From: Kai Moritz Date: Mon, 9 Jan 2023 20:14:35 +0000 (+0100) Subject: fix: `ChatBackendApplicationTest` cannot corrupt the real data anymore X-Git-Tag: TEST~23 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=06dc744bf6f251ae82b2a2af6815866665e949cf;p=demos%2Fkafka%2Fchat fix: `ChatBackendApplicationTest` cannot corrupt the real data anymore - The test used the default storage-direcory. - Because the app is sometimes aborted during the shutdown, this sometimes lead to corrupted data in the default storage-directory. - The test now uses a predefined set of data underneath the build-directory. - Also changed the name of the according property to `storage-directory`. --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java index 68ccc4fe..65708628 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -43,7 +43,7 @@ public class ChatBackendConfiguration ObjectMapper mapper) { return new LocalJsonFilesStorageStrategy( - Paths.get(properties.getDatadir()), + Paths.get(properties.getStorageDirectory()), clock, properties.getChatroomBufferSize(), mapper); diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java index 26149de0..48e58165 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java @@ -12,7 +12,7 @@ import java.nio.file.Paths; @Setter public class ChatBackendProperties { - private String datadir = Paths.get(System.getProperty("java.io.tmpdir"),"chat", "backend").toString(); + private String storageDirectory = Paths.get(System.getProperty("java.io.tmpdir"),"chat", "backend").toString(); private String allowedOrigins = "http://localhost:4200"; private int chatroomBufferSize = 8; } diff --git a/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java b/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java index fde473c6..9accd8af 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java +++ b/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java @@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest +@SpringBootTest(properties = "chat.backend.storage-directory=target/test-classes/data/") class ChatBackendApplicationTests { @Test diff --git a/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json b/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json new file mode 100644 index 00000000..0c8abcbe --- /dev/null +++ b/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json @@ -0,0 +1,19 @@ +[ { + "id" : 1477, + "serial" : 0, + "time" : "2023-01-08T00:10:08.817267716", + "user" : "ute", + "text" : "Nachricht Nr. 1477" +}, { + "id" : 1478, + "serial" : 1, + "time" : "2023-01-08T00:10:10.03333094", + "user" : "ute", + "text" : "Nachricht Nr. 1478" +}, { + "id" : 1479, + "serial" : 2, + "time" : "2023-01-08T00:10:11.22582036", + "user" : "ute", + "text" : "Nachricht Nr. 1479" +} ] diff --git a/src/test/resources/data/chatrooms.json b/src/test/resources/data/chatrooms.json new file mode 100644 index 00000000..5b6c22b5 --- /dev/null +++ b/src/test/resources/data/chatrooms.json @@ -0,0 +1,4 @@ +[ { + "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f", + "name" : "Peter's Chat-Room" +} ] \ No newline at end of file