Skip to content

Commit

Permalink
m7l2 concurrency finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
svok authored and phaeton03 committed Jun 23, 2024
1 parent 9b883b7 commit f9bc318
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ internal abstract class AdRepoBaseV2Test {
id = MkplAdId(uuidNew)
ownerId = MkplUserId.NONE
lock = MkplAdLock(uuidNew)
// lock = MkplAdLock.NONE
})
.toTransportCreate()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -22,8 +22,9 @@ abstract class RepoAdCreateTest {
@Test
fun createSuccess() = runRepoTest {
val result = repo.createAd(DbAdRequest(createObj))
val expected = createObj
assertIs<DbAdResponseOk>(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)
Expand Down

0 comments on commit f9bc318

Please sign in to comment.