Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPP-609 Add StorageBackendTestsDeduplication #11088

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ trait StorageBackendSuite
with StorageBackendTestsReset
with StorageBackendTestsPruning
with StorageBackendTestsDBLockForSuite
with StorageBackendTestsDebug
with StorageBackendTestsIntegrity
with StorageBackendTestsDeduplication
with StorageBackendTestsTimestamps {
this: AsyncFlatSpec =>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.platform.store.backend

import org.scalatest.Inside
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers

import java.time.Instant
import scala.concurrent.Future

private[backend] trait StorageBackendTestsDeduplication
extends Matchers
with Inside
with StorageBackendSpec {
this: AsyncFlatSpec =>

behavior of "DeduplicationStorageBackend"

import StorageBackendTestValues._

it should "only allow one upsertDeduplicationEntry to insert a new entry" in {
val key = "deduplication key"
val submittedAt = Instant.EPOCH
val deduplicateUntil = submittedAt.plusSeconds(1)
val n = 8

for {
_ <- executeSql(backend.initializeParameters(someIdentityParams))
insertedRows <- Future.sequence(
Vector.fill(n)(
executeSql(backend.upsertDeduplicationEntry(key, submittedAt, deduplicateUntil))
)
)
} yield {
insertedRows.count(_ == 1) shouldBe 1 // One of the calls inserts a new row
insertedRows.count(_ == 0) shouldBe (n - 1) // All other calls don't write anything
succeed
}
}

it should "only allow one upsertDeduplicationEntry to update an existing expired entry" in {
val key = "deduplication key"
val submittedAt = Instant.EPOCH
val deduplicateUntil = submittedAt.plusSeconds(1)
val submittedAt2 = deduplicateUntil.plusSeconds(1)
val deduplicateUntil2 = submittedAt2.plusSeconds(1)
val n = 8

for {
_ <- executeSql(backend.initializeParameters(someIdentityParams))
insertedRows <- executeSql(
backend.upsertDeduplicationEntry(key, submittedAt, deduplicateUntil)
)
updatedRows <- Future.sequence(
Vector.fill(n)(
executeSql(backend.upsertDeduplicationEntry(key, submittedAt2, deduplicateUntil2))
)
)
} yield {
insertedRows shouldBe 1 // First call inserts a new row
updatedRows.count(
_ == 1
) shouldBe 1 // One of the subsequent calls updates the now expired row
updatedRows.count(_ == 0) shouldBe (n - 1) // All other calls don't write anything
succeed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add validation if we update values correctly.

}
}

it should "not update or insert anything if there is an existing active entry" in {
val key = "deduplication key"
val submittedAt = Instant.EPOCH
val deduplicateUntil = submittedAt.plusSeconds(1)

for {
_ <- executeSql(backend.initializeParameters(someIdentityParams))
insertedRows <- executeSql(
backend.upsertDeduplicationEntry(key, submittedAt, deduplicateUntil)
)
updatedRows <- executeSql(
backend.upsertDeduplicationEntry(key, submittedAt, deduplicateUntil)
)
} yield {
insertedRows shouldBe 1 // First call inserts a new row
updatedRows shouldBe 0 // Second call doesn't write anything
succeed
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package com.daml.platform.store.backend
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers

private[backend] trait StorageBackendTestsDebug extends Matchers with StorageBackendSpec {
private[backend] trait StorageBackendTestsIntegrity extends Matchers with StorageBackendSpec {
this: AsyncFlatSpec =>

import StorageBackendTestValues._

behavior of "DebugStorageBackend"
behavior of "IntegrityStorageBackend"

it should "find duplicate event ids" in {
val updates = Vector(
Expand Down