Skip to content

Commit

Permalink
R3SOL-372 Extract Uniqueness code to a library (#6370)
Browse files Browse the repository at this point in the history
Main changes in this PR:
- `BackingStore` and `UniquenessChecker` interfaces are now part of the `ledger-lib-uniqueness` library
- The `BackingStore` logic is basically common for C5 and DLT except for how we establish the DB connection.
   That's the reason we have a base abstract class now called `JPABackingStoreBase`.
   Both C5 and DLT will inherit from this. In C5 it's called `JPABackingStoreOsgiImpl` and the entity manager
   is acquired through `DbConnectionManager`.
- Thankfully the core uniqueness checker logic is the same for C5/DLT so only C5 will extend
  `BatchedUniquenessCheckerImpl` with the necessary OSGi things.
- `BatchedUniquenessCheckerImplTest` tests the main UniquenessChecker logic
- `JPABackingStoreOsgiImplIntegrationTests`, `JPABackingStoreEntitiesIntegrationTest` tests BackingStore in C5.
    We will have testcontainers integration tests in DLT.
- `JPABackingStoreOsgiImplBenchmark` still exists and still works.
- `UniquenessCheckerImplDBIntegrationTests` is the integration test for C5, will have testcontainers version in DLT.

Co-authored-by: nkovacsx <[email protected]>
  • Loading branch information
lankydan and nkovacsx authored Oct 23, 2024
1 parent 2298213 commit c570ab5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ import net.corda.v5.crypto.SecureHash
import net.corda.virtualnode.HoldingIdentity
import net.corda.virtualnode.VirtualNodeInfo
import net.corda.virtualnode.read.VirtualNodeInfoReadService
import org.apache.avro.AvroRuntimeException
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.assertAll
import org.junit.jupiter.api.Assertions.assertIterableEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
Expand Down Expand Up @@ -342,16 +339,6 @@ class UniquenessCheckerImplDBIntegrationTests {

@Nested
inner class MalformedRequests {
@Test
@Disabled("Setting null is not possible anymore")
fun `Request is missing time window upper bound`() {
assertThrows(AvroRuntimeException::class.java, {
newRequestBuilder()
//.setTimeWindowUpperBound(null)
.build()
}, "Field timeWindowUpperBound type:LONG pos:5 does not accept null values")
}

@Test
fun `Request contains a negative number of output states`() {
processRequests(
Expand Down
8 changes: 8 additions & 0 deletions libs/ledger-lib-uniqueness/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ dependencies {
testImplementation project(":testing:uniqueness:backing-store-fake")
testImplementation project(":testing:uniqueness:uniqueness-utilities")
}

tasks.named('jar', Jar) {
bundle {
bnd '''\
DynamicImport-Package: org.hibernate.proxy
'''
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ open class BatchedUniquenessCheckerImpl(
Pair<UniquenessCheckRequestInternal, UniquenessCheckRequest>
>(requests.size)

log.debug("Processing ${requests.size} requests")
log.debug { "Processing ${requests.size} requests" }

// Convert the supplied batch of external requests to internal requests. Doing this can
// throw an exception if the request is malformed. These are filtered out immediately with
Expand Down Expand Up @@ -382,11 +382,11 @@ open class BatchedUniquenessCheckerImpl(
it.second.result is UniquenessCheckResultSuccess
}.size

log.debug(
log.debug {
"Finished processing write batch for $holdingIdentity. " +
"$numSuccessful successful, " +
"${resultsToRespondWith.size - numSuccessful} rejected"
)
}
}

return resultsToRespondWith
Expand All @@ -400,7 +400,7 @@ open class BatchedUniquenessCheckerImpl(
val resultsToRespondWith =
mutableListOf<Pair<UniquenessCheckRequestInternal, InternalUniquenessCheckResultWithContext>>()

log.debug("Processing uniqueness check read batch of ${batch.size} requests for $holdingIdentity")
log.debug { "Processing uniqueness check read batch of ${batch.size} requests for $holdingIdentity" }

// DB operations are retried, removing conflicts from the batch on each attempt.
backingStore.transactionSession(holdingIdentity) { session, _ ->
Expand Down Expand Up @@ -461,10 +461,10 @@ open class BatchedUniquenessCheckerImpl(

val notFound = resultsToRespondWith.size - (numSuccessful + numRejected)

log.debug(
log.debug {
"Finished processing read batch for $holdingIdentity. " +
"$numSuccessful successful, $notFound not found, $numRejected rejected"
)
}
}

return resultsToRespondWith
Expand Down

0 comments on commit c570ab5

Please sign in to comment.