-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
744 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
23 changes: 23 additions & 0 deletions
23
ok-marketplace-be/ok-marketplace-app-ktor/src/jvmMain/kotlin/configs/CassandraConfig.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,23 @@ | ||
package ru.otus.otuskotlin.marketplace.app.ktor.configs | ||
|
||
import io.ktor.server.config.* | ||
|
||
data class CassandraConfig( | ||
val host: String = "localhost", | ||
val port: Int = 9042, | ||
val user: String = "cassandra", | ||
val pass: String = "cassandra", | ||
val keyspace: String = "test_keyspace" | ||
) { | ||
constructor(config: ApplicationConfig) : this( | ||
host = config.property("$PATH.host").getString(), | ||
port = config.property("$PATH.port").getString().toInt(), | ||
user = config.property("$PATH.user").getString(), | ||
pass = config.property("$PATH.pass").getString(), | ||
keyspace = config.property("$PATH.keyspace").getString() | ||
) | ||
|
||
companion object { | ||
const val PATH = "${ConfigPaths.repository}.cassandra" | ||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
ok-marketplace-be/ok-marketplace-app-ktor/src/jvmTest/kotlin/repo/V1AdRepoCassandraTest.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,86 @@ | ||
package ru.otus.otuskotlin.marketplace.app.ktor.repo | ||
|
||
import com.benasher44.uuid.uuid4 | ||
import org.junit.AfterClass | ||
import org.junit.BeforeClass | ||
import org.testcontainers.containers.CassandraContainer | ||
import ru.otus.otuskotlin.marketplace.api.v1.models.AdRequestDebugMode | ||
import ru.otus.otuskotlin.marketplace.app.ktor.MkplAppSettings | ||
import ru.otus.otuskotlin.marketplace.backend.repo.cassandra.RepoAdCassandra | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.common.repo.IRepoAd | ||
import ru.otus.otuskotlin.marketplace.repo.common.AdRepoInitialized | ||
import java.time.Duration | ||
|
||
class V1AdRepoCassandraTest : V1AdRepoBaseTest() { | ||
override val workMode: AdRequestDebugMode = AdRequestDebugMode.TEST | ||
private fun mkAppSettings(repo: IRepoAd) = MkplAppSettings( | ||
corSettings = MkplCorSettings( | ||
repoTest = repo | ||
) | ||
) | ||
|
||
override val appSettingsCreate: MkplAppSettings = mkAppSettings( | ||
repo = AdRepoInitialized(repository("ks_create", uuidNew)) | ||
) | ||
override val appSettingsRead: MkplAppSettings = mkAppSettings( | ||
repo = AdRepoInitialized( | ||
repository("ks_read"), | ||
initObjects = listOf(initAd), | ||
) | ||
) | ||
override val appSettingsUpdate: MkplAppSettings = mkAppSettings( | ||
repo = AdRepoInitialized( | ||
repository("ks_update", uuidNew), | ||
initObjects = listOf(initAd), | ||
) | ||
) | ||
override val appSettingsDelete: MkplAppSettings = mkAppSettings( | ||
repo = AdRepoInitialized( | ||
repository("ks_delete"), | ||
initObjects = listOf(initAd), | ||
) | ||
) | ||
override val appSettingsSearch: MkplAppSettings = mkAppSettings( | ||
repo = AdRepoInitialized( | ||
repository("ks_search"), | ||
initObjects = listOf(initAd), | ||
) | ||
) | ||
override val appSettingsOffers: MkplAppSettings = mkAppSettings( | ||
repo = AdRepoInitialized( | ||
repository("ks_offers"), | ||
initObjects = listOf(initAd, initAdSupply), | ||
) | ||
) | ||
|
||
companion object { | ||
class TestCasandraContainer : CassandraContainer<TestCasandraContainer>("cassandra:3.11.2") | ||
private val container by lazy { | ||
@Suppress("Since15") | ||
TestCasandraContainer().withStartupTimeout(Duration.ofSeconds(300L)) | ||
} | ||
|
||
@JvmStatic | ||
@BeforeClass | ||
fun tearUp() { | ||
container.start() | ||
} | ||
|
||
@JvmStatic | ||
@AfterClass | ||
fun tearDown() { | ||
container.stop() | ||
} | ||
|
||
fun repository(keyspace: String, uuid: String? = null): RepoAdCassandra { | ||
return RepoAdCassandra( | ||
keyspaceName = keyspace, | ||
host = container.host, | ||
port = container.getMappedPort(CassandraContainer.CQL_PORT), | ||
testing = true, | ||
randomUuid = uuid?.let { { uuid } } ?: { uuid4().toString() }, | ||
) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
ok-marketplace-be/ok-marketplace-biz/src/commonTest/kotlin/validation/TestBase.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,13 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.validation | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.coroutines.withContext | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
fun runBizTest(block: suspend () -> Unit) = runTest { | ||
withContext(Dispatchers.Default.limitedParallelism(1)) { | ||
block() | ||
} | ||
} |
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
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
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
Oops, something went wrong.