From: Kai Moritz Date: Sat, 18 Feb 2023 10:07:21 +0000 (+0100) Subject: test: RED - Proofed existence of an NPE in `ShardedChatHome.getChatRoom()` X-Git-Tag: rebase--2023-08-18-abends~22 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=579188d824ed2718b03e7feecf6f8c6813888394;p=demos%2Fkafka%2Fchat test: RED - Proofed existence of an NPE in `ShardedChatHome.getChatRoom()` - Refined `AbstractConfigurationIT` to show, that an NPE can occure in `ShardedChatHome.getChatRoom()`. - Defined the expected behaviour, if the NPE is handled correctly in the refined integration-test. --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java index c424b294..139c5879 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java @@ -20,7 +20,7 @@ public abstract class AbstractConfigurationIT @Test @DisplayName("The app starts, the data is restored and accessible") - void test() + void testAppStartsDataIsRestoredAndAccessible() { Awaitility .await() diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationWithFixedShardingIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationWithFixedShardingIT.java new file mode 100644 index 00000000..789ef624 --- /dev/null +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationWithFixedShardingIT.java @@ -0,0 +1,38 @@ +package de.juplo.kafka.chat.backend; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; +import org.testcontainers.shaded.org.awaitility.Awaitility; + +import java.time.Duration; + + +public abstract class AbstractConfigurationWithFixedShardingIT extends AbstractConfigurationIT +{ + @Test + @DisplayName("A PUT for a not owned shard yields 404 NOT FOUND") + void testPutYields404() + { + Awaitility + .await() + .atMost(Duration.ofSeconds(15)) + .untilAsserted(() -> + { + webTestClient + .put() + .uri("http://localhost:{port}/97cca12a-af72-11ed-9b9e-f78fa16794ac/otto/66", port) + .contentType(MediaType.TEXT_PLAIN) + .accept(MediaType.APPLICATION_JSON) + .bodyValue("The devil rules route 66") + .exchange() + .expectStatus().isNotFound(); + webTestClient + .get() + .uri("http://localhost:{port}/97cca12a-af72-11ed-9b9e-f78fa16794ac/otto/66", port) + .accept(MediaType.APPLICATION_JSON) + .exchange() + .expectStatus().isNotFound(); + }); + } +} diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesAndShardingConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesAndShardingConfigurationIT.java index d792d258..77c188d5 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesAndShardingConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesAndShardingConfigurationIT.java @@ -10,6 +10,6 @@ import org.springframework.boot.test.context.SpringBootTest; "chat.backend.inmemory.sharding-strategy=kafkalike", "chat.backend.inmemory.num-shards=10", "chat.backend.inmemory.owned-shards=2" }) -class InMemoryWithFilesAndShardingConfigurationIT extends AbstractConfigurationIT +class InMemoryWithFilesAndShardingConfigurationIT extends AbstractConfigurationWithFixedShardingIT { } diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesConfigurationIT.java index 151a833a..435fc130 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesConfigurationIT.java @@ -8,6 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest; properties = { "chat.backend.inmemory.sharding-strategy=none", "chat.backend.inmemory.storage-directory=target/test-classes/data/files" }) -class InMemoryWithFilesConfigurationIT extends AbstractConfigurationIT +class InMemoryWithFilesConfigurationIT extends AbstractConfigurationWithFixedShardingIT { } diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java index 05f1de5f..9e36e512 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java @@ -21,7 +21,7 @@ import org.testcontainers.junit.jupiter.Testcontainers; "chat.backend.inmemory.storage-strategy=mongodb" }) @Testcontainers @Slf4j -class InMemoryWithMongoDbConfigurationIT extends AbstractConfigurationIT +class InMemoryWithMongoDbConfigurationIT extends AbstractConfigurationWithFixedShardingIT { private static final int MONGODB_PORT = 27017;