From f9bc31811068939a64671abad89744a5eae5fe5b Mon Sep 17 00:00:00 2001 From: Sergey Okatov Date: Sun, 5 May 2024 14:47:00 +0500 Subject: [PATCH] m7l2 concurrency finalization --- .../src/test/kotlin/repo/AdRepoBaseV2Test.kt | 1 - .../commonTest/kotlin/validation/BaseBizValidationTest.kt | 2 +- .../src/commonMain/kotlin/AdRepoInMemory.kt | 4 ++-- .../src/commonTest/kotlin/AdRepoInMemoryTest.kt | 2 +- .../src/commonMain/kotlin/RepoAdCreateTest.kt | 5 +++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ok-marketplace-be/ok-marketplace-app-spring/src/test/kotlin/repo/AdRepoBaseV2Test.kt b/ok-marketplace-be/ok-marketplace-app-spring/src/test/kotlin/repo/AdRepoBaseV2Test.kt index fbec105..da7fc8a 100644 --- a/ok-marketplace-be/ok-marketplace-app-spring/src/test/kotlin/repo/AdRepoBaseV2Test.kt +++ b/ok-marketplace-be/ok-marketplace-app-spring/src/test/kotlin/repo/AdRepoBaseV2Test.kt @@ -27,7 +27,6 @@ internal abstract class AdRepoBaseV2Test { id = MkplAdId(uuidNew) ownerId = MkplUserId.NONE lock = MkplAdLock(uuidNew) -// lock = MkplAdLock.NONE }) .toTransportCreate() ) diff --git a/ok-marketplace-be/ok-marketplace-biz/src/commonTest/kotlin/validation/BaseBizValidationTest.kt b/ok-marketplace-be/ok-marketplace-biz/src/commonTest/kotlin/validation/BaseBizValidationTest.kt index 48149a2..98944d8 100644 --- a/ok-marketplace-be/ok-marketplace-biz/src/commonTest/kotlin/validation/BaseBizValidationTest.kt +++ b/ok-marketplace-be/ok-marketplace-biz/src/commonTest/kotlin/validation/BaseBizValidationTest.kt @@ -12,7 +12,7 @@ abstract class BaseBizValidationTest { private val repo = AdRepoInitialized( repo = AdRepoInMemory(), initObjects = listOf( - MkplAdStub.prepareResult { }, + MkplAdStub.get(), ), ) private val settings by lazy { MkplCorSettings(repoTest = repo) } diff --git a/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonMain/kotlin/AdRepoInMemory.kt b/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonMain/kotlin/AdRepoInMemory.kt index 1bd6cd4..a913b2b 100644 --- a/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonMain/kotlin/AdRepoInMemory.kt +++ b/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonMain/kotlin/AdRepoInMemory.kt @@ -53,7 +53,7 @@ class AdRepoInMemory( val rqAd = rq.ad val id = rqAd.id.takeIf { it != MkplAdId.NONE } ?: return@tryAdMethod errorEmptyId val key = id.asString() - val oldLock = rqAd.lock.takeIf { it != MkplAdLock.NONE } ?: return errorEmptyLock(id) + val oldLock = rqAd.lock.takeIf { it != MkplAdLock.NONE } ?: return@tryAdMethod errorEmptyLock(id) mutex.withLock { val oldAd = cache.get(key)?.toInternal() @@ -75,7 +75,7 @@ class AdRepoInMemory( override suspend fun deleteAd(rq: DbAdIdRequest): IDbAdResponse = tryAdMethod { val id = rq.id.takeIf { it != MkplAdId.NONE } ?: return@tryAdMethod errorEmptyId val key = id.asString() - val oldLock = rq.lock.takeIf { it != MkplAdLock.NONE } ?: return errorEmptyLock(id) + val oldLock = rq.lock.takeIf { it != MkplAdLock.NONE } ?: return@tryAdMethod errorEmptyLock(id) mutex.withLock { val oldAd = cache.get(key)?.toInternal() diff --git a/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonTest/kotlin/AdRepoInMemoryTest.kt b/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonTest/kotlin/AdRepoInMemoryTest.kt index 73ca674..fd01431 100644 --- a/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonTest/kotlin/AdRepoInMemoryTest.kt +++ b/ok-marketplace-be/ok-marketplace-repo-inmemory/src/commonTest/kotlin/AdRepoInMemoryTest.kt @@ -4,7 +4,7 @@ import ru.otus.otuskotlin.marketplace.repo.inmemory.AdRepoInMemory class AdRepoInMemoryCreateTest : RepoAdCreateTest() { override val repo = AdRepoInitialized( - AdRepoInMemory(randomUuid = { lockNew.asString() }), + AdRepoInMemory(randomUuid = { uuidNew.asString() }), initObjects = initObjects, ) } diff --git a/ok-marketplace-be/ok-marketplace-repo-tests/src/commonMain/kotlin/RepoAdCreateTest.kt b/ok-marketplace-be/ok-marketplace-repo-tests/src/commonMain/kotlin/RepoAdCreateTest.kt index 87f0f39..6e5747b 100644 --- a/ok-marketplace-be/ok-marketplace-repo-tests/src/commonMain/kotlin/RepoAdCreateTest.kt +++ b/ok-marketplace-be/ok-marketplace-repo-tests/src/commonMain/kotlin/RepoAdCreateTest.kt @@ -9,7 +9,7 @@ import kotlin.test.* abstract class RepoAdCreateTest { abstract val repo: IRepoAdInitializable - protected open val lockNew: MkplAdLock = MkplAdLock("20000000-0000-0000-0000-000000000002") + protected open val uuidNew = MkplAdId("10000000-0000-0000-0000-000000000001") private val createObj = MkplAd( title = "create object", @@ -22,8 +22,9 @@ abstract class RepoAdCreateTest { @Test fun createSuccess() = runRepoTest { val result = repo.createAd(DbAdRequest(createObj)) + val expected = createObj assertIs(result) - val expected = createObj.copy(id = result.data.id) + assertEquals(uuidNew, result.data.id) assertEquals(expected.title, result.data.title) assertEquals(expected.description, result.data.description) assertEquals(expected.adType, result.data.adType)