Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jUnit: Migrate ReplicationTest to Kotlin #1884

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
moved groovy tests to new file
  • Loading branch information
MOOOOOSER committed Nov 20, 2023
commit 136dc8ac607e875d8a440ffc75c7373412ccff3c
64 changes: 64 additions & 0 deletions src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt
Original file line number Diff line number Diff line change
@@ -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()
}

}