From f6ea28a09f28a654829074c0a7e906cb454d24ba Mon Sep 17 00:00:00 2001 From: German Andosov <334875@niuitmo.ru> Date: Sat, 19 Nov 2022 21:11:27 +0300 Subject: [PATCH 1/4] refactoring --- .../ru/ct/belfort/db/IdeasRepository.java | 8 ++ .../src/test/java/ru/ct/belfort/Utils.java | 28 +++++ .../base/KafkaAndPostgresTestBase.java | 91 ++++++++++++++ .../java/ru/ct/belfort/db/PostgresTest.java | 56 +++++++++ .../java/ru/ct/belfort/kafka/KafkaTest.java | 112 ++---------------- 5 files changed, 195 insertions(+), 100 deletions(-) create mode 100644 trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java create mode 100644 trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java diff --git a/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java b/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java index 97cf27a..701c3f6 100644 --- a/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java +++ b/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java @@ -33,6 +33,14 @@ public List selectAll() { return jdbcTemplate.query("SELECT * FROM ideas", mapper); } + public Integer getRecordsAmount() { + return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM ideas", Integer.class); + } + + /*public IdeaEntity getLastRecord() { + return jdbcTemplate.query("SELECT * FROM ideas ORDER BY time DESC LIMIT 1", ); + }*/ + public void deleteAll() { jdbcTemplate.update("DELETE FROM ideas"); } diff --git a/trading-bot/src/test/java/ru/ct/belfort/Utils.java b/trading-bot/src/test/java/ru/ct/belfort/Utils.java index f91be68..aa37f71 100644 --- a/trading-bot/src/test/java/ru/ct/belfort/Utils.java +++ b/trading-bot/src/test/java/ru/ct/belfort/Utils.java @@ -39,4 +39,32 @@ public static TradingInfoDTO genRandomTradingInfoDTO(String strategy) { var candles = genRandomCandles(10, 5, 10); return new TradingInfoDTO(candles, strategy); } + + public static TradingInfoDTO badCandlesSample() { + return new TradingInfoDTO( + closePricesToCandles(new double[]{500, 493, 491, 485, 483, 482, 480, 467, 463, 461}), + "rsi" + ); + } + + public static TradingInfoDTO goodCandlesSample() { + return new TradingInfoDTO( + closePricesToCandles(new double[]{500, 505, 517, 523, 524, 525, 536, 541, 547, 555}), + "rsi" + ); + } + + public static TradingInfoDTO okCandlesSample() { + return new TradingInfoDTO( + closePricesToCandles(new double[]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500}), + "rsi" + ); + } + + public static TradingInfoDTO unknownStrategySample() { + return new TradingInfoDTO( + closePricesToCandles(new double[]{}), + "fds7f757das78f7sd" + ); + } } diff --git a/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java b/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java new file mode 100644 index 0000000..55aa0ee --- /dev/null +++ b/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java @@ -0,0 +1,91 @@ +package ru.ct.belfort.base; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.apache.kafka.common.serialization.StringSerializer; +import org.junit.jupiter.api.BeforeAll; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.kafka.support.serializer.JsonDeserializer; +import org.springframework.kafka.support.serializer.JsonSerializer; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; +import ru.ct.belfort.IdeaDTO; +import ru.ct.belfort.TradingInfoDTO; +import ru.ct.belfort.kafka.producers.ErrorProducerConfig; +import ru.ct.belfort.kafka.producers.IdeasProducerConfig; + +import java.util.Collections; +import java.util.Map; + +@SpringBootTest +@Testcontainers +public abstract class KafkaAndPostgresTestBase { + + @Container + protected static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + + @Container + protected static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres"); + + @DynamicPropertySource + static void kafkaProperties(DynamicPropertyRegistry registry) { + registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers); + registry.add("spring.datasource.drivername", postgres::getDriverClassName); + registry.add("spring.datasource.url", postgres::getJdbcUrl); + registry.add("spring.datasource.username", postgres::getUsername); + registry.add("spring.datasource.password", postgres::getPassword); + } + + protected static KafkaProducer producer = null; + protected static KafkaConsumer ideasConsumer = null; + protected static KafkaConsumer errorConsumer = null; + + @BeforeAll + public static void init() { + + JsonDeserializer jsonDeserializer = new JsonDeserializer<>(); + jsonDeserializer.addTrustedPackages("*"); + + producer = new KafkaProducer<>( + Map.of( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class, + ProducerConfig.CLIENT_ID_CONFIG, "candles_test_producer" + ), + new StringSerializer(), + new JsonSerializer<>() + ); + + ideasConsumer = new KafkaConsumer<>( + Map.of( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), + ConsumerConfig.GROUP_ID_CONFIG, "ideas_test_consumers", + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest" + ), + new StringDeserializer(), + jsonDeserializer + ); + + errorConsumer = new KafkaConsumer<>( + Map.of( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), + ConsumerConfig.GROUP_ID_CONFIG, "error_test_consumers", + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest" + ), + new StringDeserializer(), + new StringDeserializer() + ); + + ideasConsumer.subscribe(Collections.singletonList(IdeasProducerConfig.TOPIC)); + errorConsumer.subscribe(Collections.singletonList(ErrorProducerConfig.TOPIC)); + } +} diff --git a/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java b/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java new file mode 100644 index 0000000..44dee82 --- /dev/null +++ b/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java @@ -0,0 +1,56 @@ +package ru.ct.belfort.db; + +import org.apache.kafka.clients.producer.ProducerRecord; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import ru.ct.belfort.TradingInfoDTO; +import ru.ct.belfort.base.KafkaAndPostgresTestBase; +import ru.ct.belfort.kafka.consumers.CandlesConsumerConfig; + +import java.time.Duration; + +import static ru.ct.belfort.Utils.*; + +public class PostgresTest extends KafkaAndPostgresTestBase { + + @Autowired + IdeasRepository repository; + + private static final long MAX_BLOCK_TIME = 1000; + + private static void sendAndWait(TradingInfoDTO message) { + producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, message)); + ideasConsumer.poll(Duration.ofMillis(MAX_BLOCK_TIME)); + } + + @Test + public void sendBadCandles_ExpectDBInsertion() { + final var message = badCandlesSample(); + var before = repository.getRecordsAmount(); + sendAndWait(message); + Assertions.assertEquals(before + 1, repository.getRecordsAmount()); + } + + @Test + public void sendGoodCandles_ExpectDBInsertion() { + final var message = goodCandlesSample(); + var before = repository.getRecordsAmount(); + sendAndWait(message); + Assertions.assertEquals(before + 1, repository.getRecordsAmount()); + } + + @Test + public void sendOkCandles_ExpectNoDBInsertion() { + var before = repository.getRecordsAmount(); + sendAndWait(okCandlesSample()); + Assertions.assertEquals(before, repository.getRecordsAmount()); + } + + @Test + public void sendUnknownStrategy_ExpectNoDBInsertion() { + var before = repository.getRecordsAmount(); + sendAndWait(unknownStrategySample()); + Assertions.assertEquals(before, repository.getRecordsAmount()); + } +} diff --git a/trading-bot/src/test/java/ru/ct/belfort/kafka/KafkaTest.java b/trading-bot/src/test/java/ru/ct/belfort/kafka/KafkaTest.java index 2d82087..9bee00a 100644 --- a/trading-bot/src/test/java/ru/ct/belfort/kafka/KafkaTest.java +++ b/trading-bot/src/test/java/ru/ct/belfort/kafka/KafkaTest.java @@ -1,108 +1,34 @@ package ru.ct.belfort.kafka; -import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; -import org.apache.kafka.clients.producer.KafkaProducer; -import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerRecord; -import org.apache.kafka.common.serialization.StringDeserializer; -import org.apache.kafka.common.serialization.StringSerializer; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.kafka.support.serializer.JsonDeserializer; -import org.springframework.kafka.support.serializer.JsonSerializer; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.testcontainers.containers.KafkaContainer; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.DockerImageName; import ru.ct.belfort.Advice; import ru.ct.belfort.IdeaDTO; -import ru.ct.belfort.TradingInfoDTO; +import ru.ct.belfort.base.KafkaAndPostgresTestBase; import ru.ct.belfort.kafka.consumers.CandlesConsumerConfig; import ru.ct.belfort.kafka.producers.ErrorProducerConfig; import ru.ct.belfort.kafka.producers.IdeasProducerConfig; import ru.ct.belfort.strategy.RsiStrategy; import java.time.Duration; -import java.util.Collections; -import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -import static ru.ct.belfort.Utils.closePricesToCandles; +import static ru.ct.belfort.Utils.*; @Testcontainers @SpringBootTest -public class KafkaTest { +public class KafkaTest extends KafkaAndPostgresTestBase { - @Container - static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + private static final long MAX_BLOCK_TIME = 1000; - @Container - static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres"); - - @DynamicPropertySource - static void kafkaProperties(DynamicPropertyRegistry registry) { - registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers); - registry.add("spring.datasource.drivername", postgres::getDriverClassName); - registry.add("spring.datasource.url", postgres::getJdbcUrl); - registry.add("spring.datasource.username", postgres::getUsername); - registry.add("spring.datasource.password", postgres::getPassword); - } - - static KafkaProducer producer = null; - static KafkaConsumer ideasConsumer = null; - static KafkaConsumer errorConsumer = null; - - @BeforeAll - public static void init() { - - JsonDeserializer jsonDeserializer = new JsonDeserializer<>(); - jsonDeserializer.addTrustedPackages("*"); - - producer = new KafkaProducer<>( - Map.of( - ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), - ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class, - ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class, - ProducerConfig.CLIENT_ID_CONFIG, "candles_test_producer" - ), - new StringSerializer(), - new JsonSerializer<>() - ); - - ideasConsumer = new KafkaConsumer<>( - Map.of( - ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), - ConsumerConfig.GROUP_ID_CONFIG, "ideas_test_consumers", - ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest" - ), - new StringDeserializer(), - jsonDeserializer - ); - - errorConsumer = new KafkaConsumer<>( - Map.of( - ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers(), - ConsumerConfig.GROUP_ID_CONFIG, "error_test_consumers", - ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest" - ), - new StringDeserializer(), - new StringDeserializer() - ); - - ideasConsumer.subscribe(Collections.singletonList(IdeasProducerConfig.TOPIC)); - errorConsumer.subscribe(Collections.singletonList(ErrorProducerConfig.TOPIC)); - } - - public void expectMessage(KafkaConsumer consumer, String topic, V message) { - ConsumerRecords records = consumer.poll(Duration.ofMillis(1000)); + public static void expectMessage(KafkaConsumer consumer, String topic, V message) { + ConsumerRecords records = consumer.poll(Duration.ofMillis(MAX_BLOCK_TIME)); assertThat(records) .isNotEmpty() .hasSize(1) @@ -110,18 +36,15 @@ public void expectMessage(KafkaConsumer consumer, String topic, V .containsExactly(tuple(topic, message)); } - public void expectNoMessage(KafkaConsumer consumer) { - ConsumerRecords records = consumer.poll(Duration.ofMillis(1000)); + public static void expectNoMessage(KafkaConsumer consumer) { + ConsumerRecords records = consumer.poll(Duration.ofMillis(MAX_BLOCK_TIME)); assertThat(records) .isEmpty(); } @Test public void sendBadCandles_ExpectBuyIdea() { - final var message = new TradingInfoDTO( - closePricesToCandles(new double[]{500, 493, 491, 485, 483, 482, 480, 467, 463, 461}), - "rsi" - ); + final var message = badCandlesSample(); producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, message)); double score = new RsiStrategy().predict(message.candles()); expectMessage(ideasConsumer, IdeasProducerConfig.TOPIC, new IdeaDTO(score, Advice.BUY)); @@ -130,10 +53,7 @@ public void sendBadCandles_ExpectBuyIdea() { @Test public void sendGoodCandles_ExpectSellIdea() { - final var message = new TradingInfoDTO( - closePricesToCandles(new double[]{500, 505, 517, 523, 524, 525, 536, 541, 547, 555}), - "rsi" - ); + final var message = goodCandlesSample(); producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, message)); double score = new RsiStrategy().predict(message.candles()); expectMessage(ideasConsumer, IdeasProducerConfig.TOPIC, new IdeaDTO(score, Advice.SELL)); @@ -142,22 +62,14 @@ public void sendGoodCandles_ExpectSellIdea() { @Test public void sendOkCandles_ExpectNoIdea() { - final var message = new TradingInfoDTO( - closePricesToCandles(new double[]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500}), - "rsi" - ); - producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, message)); + producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, okCandlesSample())); expectNoMessage(ideasConsumer); expectNoMessage(errorConsumer); } @Test public void sendUnknownStrategy_ExpectError() { - final var message = new TradingInfoDTO( - closePricesToCandles(new double[]{}), - "fds7f757das78f7sd" - ); - producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, message)); + producer.send(new ProducerRecord<>(CandlesConsumerConfig.TOPIC, unknownStrategySample())); expectMessage(errorConsumer, ErrorProducerConfig.TOPIC, "Unknown strategy"); expectNoMessage(ideasConsumer); } From 68e3c965d16b3a1a362c06a6b5517d8d700b0e5b Mon Sep 17 00:00:00 2001 From: German Andosov <334875@niuitmo.ru> Date: Sat, 19 Nov 2022 21:28:04 +0300 Subject: [PATCH 2/4] tests described --- .../java/ru/ct/belfort/db/IdeasRepository.java | 15 +++------------ .../test/java/ru/ct/belfort/db/PostgresTest.java | 15 ++++++++++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java b/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java index 701c3f6..4a76289 100644 --- a/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java +++ b/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java @@ -26,7 +26,6 @@ public void insert(IdeaDTO idea) { jdbcTemplate.update(""" INSERT INTO ideas(score, time) VALUES(?, CURRENT_TIMESTAMP(0)) """, idea.score()); - debugOutput(); } public List selectAll() { @@ -37,22 +36,14 @@ public Integer getRecordsAmount() { return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM ideas", Integer.class); } - /*public IdeaEntity getLastRecord() { - return jdbcTemplate.query("SELECT * FROM ideas ORDER BY time DESC LIMIT 1", ); - }*/ + public IdeaEntity getLastRecord() { + return jdbcTemplate.query("SELECT * FROM ideas ORDER BY time DESC LIMIT 1", mapper).get(0); + } public void deleteAll() { jdbcTemplate.update("DELETE FROM ideas"); } - // TODO: Remove this when db tests appear - private void debugOutput() { - log.info("Inserted"); - for (IdeaEntity it : selectAll()) { - log.info(it.toString()); - } - } - private static class IdeaEntityMapper implements RowMapper { @Override diff --git a/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java b/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java index 44dee82..2e79253 100644 --- a/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java +++ b/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java @@ -1,15 +1,16 @@ package ru.ct.belfort.db; import org.apache.kafka.clients.producer.ProducerRecord; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import ru.ct.belfort.TradingInfoDTO; import ru.ct.belfort.base.KafkaAndPostgresTestBase; import ru.ct.belfort.kafka.consumers.CandlesConsumerConfig; +import ru.ct.belfort.strategy.RsiStrategy; import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertEquals; import static ru.ct.belfort.Utils.*; public class PostgresTest extends KafkaAndPostgresTestBase { @@ -29,7 +30,9 @@ public void sendBadCandles_ExpectDBInsertion() { final var message = badCandlesSample(); var before = repository.getRecordsAmount(); sendAndWait(message); - Assertions.assertEquals(before + 1, repository.getRecordsAmount()); + assertEquals(before + 1, repository.getRecordsAmount()); + double score = new RsiStrategy().predict(message.candles()); + assertEquals(repository.getLastRecord().score(), score); } @Test @@ -37,20 +40,22 @@ public void sendGoodCandles_ExpectDBInsertion() { final var message = goodCandlesSample(); var before = repository.getRecordsAmount(); sendAndWait(message); - Assertions.assertEquals(before + 1, repository.getRecordsAmount()); + assertEquals(before + 1, repository.getRecordsAmount()); + double score = new RsiStrategy().predict(message.candles()); + assertEquals(repository.getLastRecord().score(), score); } @Test public void sendOkCandles_ExpectNoDBInsertion() { var before = repository.getRecordsAmount(); sendAndWait(okCandlesSample()); - Assertions.assertEquals(before, repository.getRecordsAmount()); + assertEquals(before, repository.getRecordsAmount()); } @Test public void sendUnknownStrategy_ExpectNoDBInsertion() { var before = repository.getRecordsAmount(); sendAndWait(unknownStrategySample()); - Assertions.assertEquals(before, repository.getRecordsAmount()); + assertEquals(before, repository.getRecordsAmount()); } } From 090963b2404e5b08dddb92f7a17592375ca60ba4 Mon Sep 17 00:00:00 2001 From: German Andosov <334875@niuitmo.ru> Date: Sat, 19 Nov 2022 22:17:11 +0300 Subject: [PATCH 3/4] timestamp precision bug fixed --- .../src/main/java/ru/ct/belfort/db/IdeasRepository.java | 2 +- trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java b/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java index 4a76289..0b7fb19 100644 --- a/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java +++ b/trading-bot/src/main/java/ru/ct/belfort/db/IdeasRepository.java @@ -24,7 +24,7 @@ public IdeasRepository(DataSource dataSource) { public void insert(IdeaDTO idea) { jdbcTemplate.update(""" - INSERT INTO ideas(score, time) VALUES(?, CURRENT_TIMESTAMP(0)) + INSERT INTO ideas(score, time) VALUES(?, CURRENT_TIMESTAMP) """, idea.score()); } diff --git a/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java b/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java index 2e79253..ea6a660 100644 --- a/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java +++ b/trading-bot/src/test/java/ru/ct/belfort/db/PostgresTest.java @@ -3,6 +3,8 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.testcontainers.junit.jupiter.Testcontainers; import ru.ct.belfort.TradingInfoDTO; import ru.ct.belfort.base.KafkaAndPostgresTestBase; import ru.ct.belfort.kafka.consumers.CandlesConsumerConfig; @@ -13,6 +15,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static ru.ct.belfort.Utils.*; +@Testcontainers +@SpringBootTest public class PostgresTest extends KafkaAndPostgresTestBase { @Autowired From f22e6fa3bb746bbf82ffb08fc3d8dd9b2ee83980 Mon Sep 17 00:00:00 2001 From: German Andosov <334875@niuitmo.ru> Date: Sat, 19 Nov 2022 22:56:52 +0300 Subject: [PATCH 4/4] DirtiesContext for DynamicPropertySource in base class --- .../test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java b/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java index 55aa0ee..b294c8e 100644 --- a/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java +++ b/trading-bot/src/test/java/ru/ct/belfort/base/KafkaAndPostgresTestBase.java @@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.kafka.support.serializer.JsonDeserializer; import org.springframework.kafka.support.serializer.JsonSerializer; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.testcontainers.containers.KafkaContainer; @@ -27,6 +28,7 @@ @SpringBootTest @Testcontainers +@DirtiesContext public abstract class KafkaAndPostgresTestBase { @Container