-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1884 from scireum/feature/smo/junit-migrateReplic…
…ationTest jUnit: Migrate ReplicationTest to Kotlin
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/test/kotlin/sirius/biz/storage/layer1/ReplicationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import sirius.biz.storage.layer1.replication.ReplicationBackgroundLoop | ||
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) | ||
@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() } | ||
|
||
val res = InputStreamReader(downloaded.get().getInputStream(), StandardCharsets.UTF_8) | ||
assertEquals("test", InputStreamReader(downloaded.get().getInputStream(), StandardCharsets.UTF_8).readText()) | ||
} | ||
|
||
@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()) | ||
|
||
awaitReplication() | ||
storage.getSpace("repl-primary").delete("repl-delete-test") | ||
awaitReplication() | ||
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) | ||
} | ||
|
||
} | ||
} |