From 49410579d5c295ba802e94b9aec3ade0b2fd8fcd Mon Sep 17 00:00:00 2001 From: iakunin Date: Wed, 13 May 2020 16:10:10 +0300 Subject: [PATCH 1/3] #62 - GapsFillerIntegrationTest --- .../cron/GapsFillerIntegrationTest.java | 83 ++++++++++++++++++- .../gaps-filler/expected/emptyDatabase.yml | 1 + .../cron/gaps-filler/expected/oneMissing.yml | 25 ++++++ .../cron/gaps-filler/expected/twoMissing.yml | 41 +++++++++ .../gaps-filler/initial/emptyDatabase.yml | 1 + .../cron/gaps-filler/initial/oneMissing.yml | 17 ++++ .../cron/gaps-filler/initial/twoMissing.yml | 25 ++++++ .../hackernews/cron/gaps-filler/2.json | 11 +++ .../hackernews/cron/gaps-filler/4.json | 11 +++ 9 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/emptyDatabase.yml create mode 100644 src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/oneMissing.yml create mode 100644 src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/twoMissing.yml create mode 100644 src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/emptyDatabase.yml create mode 100644 src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/oneMissing.yml create mode 100644 src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/twoMissing.yml create mode 100644 src/test/resources/wiremock/hackernews/cron/gaps-filler/2.json create mode 100644 src/test/resources/wiremock/hackernews/cron/gaps-filler/4.json diff --git a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java index 7189c6bd..c9c35c13 100644 --- a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java @@ -1,13 +1,94 @@ package dev.iakunin.codexiabot.hackernews.cron; +import com.github.database.rider.core.api.dataset.DataSet; +import com.github.database.rider.core.api.dataset.ExpectedDataSet; import dev.iakunin.codexiabot.AbstractIntegrationTest; +import dev.iakunin.codexiabot.util.WireMockServer; +import dev.iakunin.codexiabot.util.wiremock.Request; +import dev.iakunin.codexiabot.util.wiremock.Response; +import dev.iakunin.codexiabot.util.wiremock.Stub; +import org.cactoos.io.ResourceOf; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ContextConfiguration; +@ContextConfiguration(initializers = GapsFillerIntegrationTest.Initializer.class) public class GapsFillerIntegrationTest extends AbstractIntegrationTest { @Autowired private GapsFiller gapsFiller; - // @todo #10 Implement GapsFillerIntegrationTest + @Test + @DataSet( + value = "db-rider/hackernews/cron/gaps-filler/initial/emptyDatabase.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/hackernews/cron/gaps-filler/expected/emptyDatabase.yml") + public void emptyDatabase() { + gapsFiller.run(); + } + @Test + @DataSet( + value = "db-rider/hackernews/cron/gaps-filler/initial/oneMissing.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/hackernews/cron/gaps-filler/expected/oneMissing.yml") + public void oneMissing() { + WireMockServer.stub( + new Stub( + new Request("/item/2.json"), + new Response( + new ResourceOf("wiremock/hackernews/cron/gaps-filler/2.json") + ) + ) + ); + + gapsFiller.run(); + } + + @Test + @DataSet( + value = "db-rider/hackernews/cron/gaps-filler/initial/twoMissing.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/hackernews/cron/gaps-filler/expected/twoMissing.yml") + public void twoMissing() { + WireMockServer.stub( + new Stub( + new Request("/item/2.json"), + new Response( + new ResourceOf("wiremock/hackernews/cron/gaps-filler/2.json") + ) + ) + ); + WireMockServer.stub( + new Stub( + new Request("/item/4.json"), + new Response( + new ResourceOf("wiremock/hackernews/cron/gaps-filler/4.json") + ) + ) + ); + + gapsFiller.run(); + } + + @AfterEach + void after() { + WireMockServer.getInstance().resetAll(); + } + + static class Initializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + TestPropertyValues.of( + "app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() + ).applyTo(applicationContext.getEnvironment()); + } + } } diff --git a/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/emptyDatabase.yml b/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/emptyDatabase.yml new file mode 100644 index 00000000..598ffa20 --- /dev/null +++ b/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/emptyDatabase.yml @@ -0,0 +1 @@ +hackernews_item: [] diff --git a/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/oneMissing.yml b/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/oneMissing.yml new file mode 100644 index 00000000..0f0dcf81 --- /dev/null +++ b/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/oneMissing.yml @@ -0,0 +1,25 @@ +hackernews_item: + - + external_id: 1 + type: story + by: test1author + title: Title for test1 + url: test 1 url + time: 2009-01-15 05:56:17 + deleted: false + - + external_id: 3 + type: story + by: test3author + title: Title for test3 + url: test 3 url + time: 2009-01-15 05:58:12 + deleted: false + - + external_id: 2 + type: story + by: test2author + title: Title for test2 + url: test 2 url + time: 2009-01-15 06:12:49 + deleted: false diff --git a/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/twoMissing.yml b/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/twoMissing.yml new file mode 100644 index 00000000..c886bc80 --- /dev/null +++ b/src/test/resources/db-rider/hackernews/cron/gaps-filler/expected/twoMissing.yml @@ -0,0 +1,41 @@ +hackernews_item: + - + external_id: 1 + type: story + by: test1author + title: Title for test1 + url: test 1 url + time: 2009-01-15 05:56:17 + deleted: false + - + external_id: 3 + type: story + by: test3author + title: Title for test3 + url: test 3 url + time: 2009-01-15 05:58:12 + deleted: false + - + external_id: 5 + type: story + by: test5author + title: Title for test5 + url: test 5 url + time: 2009-01-15 06:32:52 + deleted: false + - + external_id: 2 + type: story + by: test2author + title: Title for test2 + url: test 2 url + time: 2009-01-15 06:12:49 + deleted: false + - + external_id: 4 + type: story + by: test4author + title: Title for test4 + url: test 4 url + time: 2009-01-15 06:12:53 + deleted: false diff --git a/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/emptyDatabase.yml b/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/emptyDatabase.yml new file mode 100644 index 00000000..598ffa20 --- /dev/null +++ b/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/emptyDatabase.yml @@ -0,0 +1 @@ +hackernews_item: [] diff --git a/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/oneMissing.yml b/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/oneMissing.yml new file mode 100644 index 00000000..71e5df0c --- /dev/null +++ b/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/oneMissing.yml @@ -0,0 +1,17 @@ +hackernews_item: + - + external_id: 1 + type: story + by: test1author + title: Title for test1 + url: test 1 url + time: 2009-01-15 05:56:17 + deleted: false + - + external_id: 3 + type: story + by: test3author + title: Title for test3 + url: test 3 url + time: 2009-01-15 05:58:12 + deleted: false diff --git a/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/twoMissing.yml b/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/twoMissing.yml new file mode 100644 index 00000000..37288ac6 --- /dev/null +++ b/src/test/resources/db-rider/hackernews/cron/gaps-filler/initial/twoMissing.yml @@ -0,0 +1,25 @@ +hackernews_item: + - + external_id: 1 + type: story + by: test1author + title: Title for test1 + url: test 1 url + time: 2009-01-15 05:56:17 + deleted: false + - + external_id: 3 + type: story + by: test3author + title: Title for test3 + url: test 3 url + time: 2009-01-15 05:58:12 + deleted: false + - + external_id: 5 + type: story + by: test5author + title: Title for test5 + url: test 5 url + time: 2009-01-15 06:32:52 + deleted: false diff --git a/src/test/resources/wiremock/hackernews/cron/gaps-filler/2.json b/src/test/resources/wiremock/hackernews/cron/gaps-filler/2.json new file mode 100644 index 00000000..f36420c0 --- /dev/null +++ b/src/test/resources/wiremock/hackernews/cron/gaps-filler/2.json @@ -0,0 +1,11 @@ +{ + "by": "test2author", + "id": 2, + "text": "Some awesome text for test 2.", + "title": "Title for test2", + "url": "test 2 url", + "time": 1231999969, + "type": "story", + "descendants": 0, + "score": 2 +} diff --git a/src/test/resources/wiremock/hackernews/cron/gaps-filler/4.json b/src/test/resources/wiremock/hackernews/cron/gaps-filler/4.json new file mode 100644 index 00000000..7581b84c --- /dev/null +++ b/src/test/resources/wiremock/hackernews/cron/gaps-filler/4.json @@ -0,0 +1,11 @@ +{ + "by": "test4author", + "id": 4, + "text": "Some awesome text for test 4.", + "title": "Title for test4", + "url": "test 4 url", + "time": 1231999973, + "type": "story", + "descendants": 30, + "score": 55 +} From 6b0fdd7c7522d900a08022e9ab2eaa16ba92d788 Mon Sep 17 00:00:00 2001 From: iakunin Date: Wed, 13 May 2020 16:46:20 +0300 Subject: [PATCH 2/3] #62 - Increasing maxParallelForks in build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 306be505..f2fa8989 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,7 @@ springBoot { test { useJUnitPlatform() failFast = true - maxParallelForks = 2 + maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 } lombok { From 0992f6ea556fe682da522f756b1a510c85609b7e Mon Sep 17 00:00:00 2001 From: iakunin Date: Wed, 13 May 2020 16:54:54 +0300 Subject: [PATCH 3/3] Revert "#62 - Increasing maxParallelForks in build.gradle" This reverts commit 6b0fdd7c --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f2fa8989..306be505 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,7 @@ springBoot { test { useJUnitPlatform() failFast = true - maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 + maxParallelForks = 2 } lombok {