From 136dc8ac607e875d8a440ffc75c7373412ccff3c Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 20 Nov 2023 14:33:41 +0100 Subject: [PATCH 1/3] moved groovy tests to new file --- .../biz/storage/layer1/ReplicationTest.kt | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt diff --git a/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt b/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt new file mode 100644 index 000000000..4222ae48a --- /dev/null +++ b/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt @@ -0,0 +1,64 @@ +/* + * Made with all the love in the world + * by scireum in Remshalden, Germany + * + * Copyright by scireum GmbH + * http://www.scireum.de - info@scireum.de + */ + +package sirius.biz.storage.layer1 + +import org.junit.jupiter.api.Tag +import sirius.biz.storage.layer1.replication.ReplicationBackgroundLoop +import sirius.kernel.BaseSpecification +import sirius.kernel.Tags +import sirius.kernel.async.BackgroundLoop +import sirius.kernel.commons.Wait +import sirius.kernel.di.std.Part + +import java.nio.charset.StandardCharsets +import java.time.Duration + +@Tag(Tags.NIGHTLY) +class ReplicationSpec extends BaseSpecification { + + @Part + private static ObjectStorage storage + + def awaitReplication() { + BackgroundLoop.nextExecution(ReplicationBackgroundLoop.class).await(Duration.ofMinutes(1)) + // Give the sync some time to actually complete its tasks... + Wait.seconds(10) + } + + def "updates are replicated correctly"() { + given: + def testData = "test".getBytes(StandardCharsets.UTF_8) + when: + storage.getSpace("repl-primary").upload("repl-update-test", new ByteArrayInputStream(testData), testData.length) + and: + awaitReplication() + def downloaded = storage.getSpace("reply-secondary").download("repl-update-test") + then: + downloaded.isPresent() + and: + new InputStreamReader(downloaded.get().getInputStream(), StandardCharsets.UTF_8).readLine() == "test" + } + + def "deletes are replicated correctly"() { + given: + def testData = "test".getBytes(StandardCharsets.UTF_8) + when: + storage.getSpace("repl-primary").upload("repl-delete-test", new ByteArrayInputStream(testData), testData.length) + and: + awaitReplication() + and: + storage.getSpace("repl-primary").delete("repl-delete-test") + and: + awaitReplication() + def downloaded = storage.getSpace("reply-secondary").download("repl-delete-test") + then: + !downloaded.isPresent() + } + +} From a0f7a69ff91779cb4525f0e4e72ec03447de814e Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 20 Nov 2023 14:54:58 +0100 Subject: [PATCH 2/3] Adapted Kotlin Syntax --- .../biz/storage/layer1/ReplicationTest.kt | 80 +++++++++++-------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt b/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt index 4222ae48a..846e34a9b 100644 --- a/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt +++ b/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt @@ -9,56 +9,70 @@ package sirius.biz.storage.layer1 import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import sirius.biz.storage.layer1.replication.ReplicationBackgroundLoop +import sirius.biz.storage.s3.ObjectStores import sirius.kernel.BaseSpecification +import sirius.kernel.SiriusExtension import sirius.kernel.Tags import sirius.kernel.async.BackgroundLoop import sirius.kernel.commons.Wait import sirius.kernel.di.std.Part +import java.io.ByteArrayInputStream +import java.io.InputStreamReader import java.nio.charset.StandardCharsets import java.time.Duration - +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +/** + * Tests the [ReplicationBackgroundLoop]. + */ @Tag(Tags.NIGHTLY) -class ReplicationSpec extends BaseSpecification { - - @Part - private static ObjectStorage storage +@ExtendWith(SiriusExtension::class) +class ReplicationTest { + @Test + fun `updates are replicated correctly`() { + val testData = "test".toByteArray(StandardCharsets.UTF_8) + storage.getSpace("repl-primary") + .upload("repl-update-test", ByteArrayInputStream(testData), testData.size.toLong()) + awaitReplication() + val downloaded = storage.getSpace("reply-secondary").download("repl-update-test") + assertTrue { downloaded.isPresent() } - def awaitReplication() { - BackgroundLoop.nextExecution(ReplicationBackgroundLoop.class).await(Duration.ofMinutes(1)) - // Give the sync some time to actually complete its tasks... - Wait.seconds(10) + val res = InputStreamReader(downloaded.get().getInputStream(), StandardCharsets.UTF_8) + assertEquals("test", InputStreamReader(downloaded.get().getInputStream(), StandardCharsets.UTF_8).readText()) } - def "updates are replicated correctly"() { - given: - def testData = "test".getBytes(StandardCharsets.UTF_8) - when: - storage.getSpace("repl-primary").upload("repl-update-test", new ByteArrayInputStream(testData), testData.length) - and: - awaitReplication() - def downloaded = storage.getSpace("reply-secondary").download("repl-update-test") - then: - downloaded.isPresent() - and: - new InputStreamReader(downloaded.get().getInputStream(), StandardCharsets.UTF_8).readLine() == "test" - } + @Test + fun `deletes are replicated correctly`() { + + val testData = "test".toByteArray(StandardCharsets.UTF_8) + storage.getSpace("repl-primary") + .upload("repl-delete-test", ByteArrayInputStream(testData), testData.size.toLong()) - def "deletes are replicated correctly"() { - given: - def testData = "test".getBytes(StandardCharsets.UTF_8) - when: - storage.getSpace("repl-primary").upload("repl-delete-test", new ByteArrayInputStream(testData), testData.length) - and: awaitReplication() - and: storage.getSpace("repl-primary").delete("repl-delete-test") - and: awaitReplication() - def downloaded = storage.getSpace("reply-secondary").download("repl-delete-test") - then: - !downloaded.isPresent() + val downloaded = storage.getSpace("reply-secondary").download("repl-delete-test") + assertFalse { downloaded.isPresent() } + } + + companion object { + @Part + @JvmStatic + private lateinit var storage: ObjectStorage + + fun awaitReplication() { + BackgroundLoop.nextExecution( + ReplicationBackgroundLoop::class.java + ).await(Duration.ofMinutes(1)) + // Give the sync some time to actually complete its tasks... + Wait.seconds(10.0) + } + } } From a9a517801c8795f6f29468d3378d743c6c79db4a Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 20 Nov 2023 16:00:44 +0100 Subject: [PATCH 3/3] Formatting --- .../sirius/biz/storage/layer1/ReplicationTest.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt b/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt index 846e34a9b..051d7eb48 100644 --- a/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt +++ b/src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt @@ -12,8 +12,6 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import sirius.biz.storage.layer1.replication.ReplicationBackgroundLoop -import sirius.biz.storage.s3.ObjectStores -import sirius.kernel.BaseSpecification import sirius.kernel.SiriusExtension import sirius.kernel.Tags import sirius.kernel.async.BackgroundLoop @@ -21,12 +19,12 @@ import sirius.kernel.commons.Wait import sirius.kernel.di.std.Part import java.io.ByteArrayInputStream import java.io.InputStreamReader - import java.nio.charset.StandardCharsets import java.time.Duration import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue + /** * Tests the [ReplicationBackgroundLoop]. */ @@ -37,7 +35,7 @@ class ReplicationTest { fun `updates are replicated correctly`() { val testData = "test".toByteArray(StandardCharsets.UTF_8) storage.getSpace("repl-primary") - .upload("repl-update-test", ByteArrayInputStream(testData), testData.size.toLong()) + .upload("repl-update-test", ByteArrayInputStream(testData), testData.size.toLong()) awaitReplication() val downloaded = storage.getSpace("reply-secondary").download("repl-update-test") assertTrue { downloaded.isPresent() } @@ -51,7 +49,7 @@ class ReplicationTest { val testData = "test".toByteArray(StandardCharsets.UTF_8) storage.getSpace("repl-primary") - .upload("repl-delete-test", ByteArrayInputStream(testData), testData.size.toLong()) + .upload("repl-delete-test", ByteArrayInputStream(testData), testData.size.toLong()) awaitReplication() storage.getSpace("repl-primary").delete("repl-delete-test") @@ -67,12 +65,11 @@ class ReplicationTest { fun awaitReplication() { BackgroundLoop.nextExecution( - ReplicationBackgroundLoop::class.java + ReplicationBackgroundLoop::class.java ).await(Duration.ofMinutes(1)) // Give the sync some time to actually complete its tasks... Wait.seconds(10.0) } } - }