-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StorageBackendTestsDeduplication
changelog_begin changelog_end
- Loading branch information
1 parent
8290347
commit 23fa8e4
Showing
3 changed files
with
95 additions
and
3 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
91 changes: 91 additions & 0 deletions
91
...tion-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsDeduplication.scala
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,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 | ||
} | ||
} | ||
|
||
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 | ||
} | ||
} | ||
|
||
} |
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