Skip to content

Commit

Permalink
m7l2 concurrent db
Browse files Browse the repository at this point in the history
  • Loading branch information
svok authored and phaeton03 committed Sep 23, 2024
1 parent e5375e9 commit 5e83282
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ abstract class V2AdRepoBaseTest {
assertEquals(ad.description, responseObj.ad?.description)
assertEquals(ad.adType, responseObj.ad?.adType)
assertEquals(ad.visibility, responseObj.ad?.visibility)
assertEquals(uuidNew, responseObj.ad?.lock)
}
}
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class MkplAdProcessor(
chain {
title = "Логика сохранения"
repoRead("Чтение объявления из БД")
checkLock("Проверяем консистентность по оптимистичной блокировке")
repoPrepareUpdate("Подготовка объекта для обновления")
repoUpdate("Обновление объявления в БД")
}
Expand Down Expand Up @@ -133,6 +134,7 @@ class MkplAdProcessor(
chain {
title = "Логика удаления"
repoRead("Чтение объявления из БД")
checkLock("Проверяем консистентность по оптимистичной блокировке")
repoPrepareDelete("Подготовка объекта для удаления")
repoDelete("Удаление объявления из БД")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun ICorChainDsl<MkplContext>.repoPrepareUpdate(title: String) = worker {
description = adValidated.description
adType = adValidated.adType
visibility = adValidated.visibility
lock = adValidated.lock
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.otus.otuskotlin.marketplace.biz.repo

import ru.otus.otuskotlin.marketplace.common.MkplContext
import ru.otus.otuskotlin.marketplace.common.helpers.fail
import ru.otus.otuskotlin.marketplace.common.models.MkplState
import ru.otus.otuskotlin.marketplace.common.repo.errorRepoConcurrency
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl
import ru.otus.otuskotlin.marketplace.cor.worker

fun ICorChainDsl<MkplContext>.checkLock(title: String) = worker {
this.title = title
description = """
Проверка оптимистичной блокировки. Если не равна сохраненной в БД, значит данные запроса устарели
и необходимо их обновить вручную
""".trimIndent()
on { state == MkplState.RUNNING && adValidated.lock != adRepoRead.lock }
handle {
fail(errorRepoConcurrency(adRepoRead, adValidated.lock).errors)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BizRepoUpdateTest {
ownerId = userId,
adType = MkplDealSide.DEMAND,
visibility = MkplVisibility.VISIBLE_PUBLIC,
lock = MkplAdLock("123-234-abc-ABC"),
)
private val repo = AdRepositoryMock(
invokeReadAd = {
Expand All @@ -37,6 +38,7 @@ class BizRepoUpdateTest {
description = "xyz",
adType = MkplDealSide.DEMAND,
visibility = MkplVisibility.VISIBLE_TO_GROUP,
lock = MkplAdLock("123-234-abc-ABC"),
)
)
}
Expand Down

0 comments on commit 5e83282

Please sign in to comment.