mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
Pass on command ID as correlation ID for transaction submissions (#6051)
CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
d56b5adc1a
commit
32625da92f
@ -31,8 +31,7 @@ class KeyValueParticipantStateWriter(writer: LedgerWriter, metrics: Metrics) ext
|
||||
transactionMeta,
|
||||
transaction.assertNoRelCid(cid => s"Unexpected relative contract id: $cid"),
|
||||
)
|
||||
val correlationId = nextSubmissionId()
|
||||
commit(correlationId, submission)
|
||||
commit(correlationId = submitterInfo.commandId, submission = submission)
|
||||
}
|
||||
|
||||
override def uploadPackages(
|
||||
@ -77,8 +76,6 @@ class KeyValueParticipantStateWriter(writer: LedgerWriter, metrics: Metrics) ext
|
||||
private def generateRandomParty(): Ref.Party =
|
||||
Ref.Party.assertFromString(s"party-${UUID.randomUUID().toString.take(8)}")
|
||||
|
||||
private def nextSubmissionId(): String = UUID.randomUUID().toString
|
||||
|
||||
private def commit(
|
||||
correlationId: String,
|
||||
submission: DamlSubmission): CompletionStage[SubmissionResult] =
|
||||
|
@ -22,28 +22,32 @@ import org.mockito.ArgumentCaptor
|
||||
import org.mockito.ArgumentMatchers._
|
||||
import org.mockito.Mockito.{times, verify, when}
|
||||
import org.scalatest.mockito.MockitoSugar._
|
||||
import org.scalatest.{Assertion, WordSpec}
|
||||
import org.scalatest.{Assertion, Matchers, WordSpec}
|
||||
|
||||
import scala.collection.immutable.HashMap
|
||||
import scala.concurrent.Future
|
||||
|
||||
class KeyValueParticipantStateWriterSpec extends WordSpec {
|
||||
class KeyValueParticipantStateWriterSpec extends WordSpec with Matchers {
|
||||
|
||||
private def newMetrics = new Metrics(new MetricRegistry)
|
||||
|
||||
"participant state writer" should {
|
||||
"submit a transaction" in {
|
||||
val transactionCaptor = captor[Bytes]
|
||||
val writer = createWriter(transactionCaptor)
|
||||
val correlationIdCaptor = captor[String]
|
||||
val writer = createWriter(transactionCaptor, correlationIdCaptor)
|
||||
val instance = new KeyValueParticipantStateWriter(writer, newMetrics)
|
||||
val recordTime = newRecordTime()
|
||||
val expectedCorrelationId = "correlation ID"
|
||||
|
||||
instance.submitTransaction(
|
||||
submitterInfo(recordTime, aParty),
|
||||
submitterInfo(recordTime, aParty, expectedCorrelationId),
|
||||
transactionMeta(recordTime),
|
||||
anEmptyTransaction)
|
||||
|
||||
verify(writer, times(1)).commit(anyString(), any[Bytes]())
|
||||
verifyEnvelope(transactionCaptor.getValue)(_.hasTransactionEntry)
|
||||
correlationIdCaptor.getValue should be(expectedCorrelationId)
|
||||
}
|
||||
|
||||
"upload a package" in {
|
||||
@ -52,6 +56,7 @@ class KeyValueParticipantStateWriterSpec extends WordSpec {
|
||||
val instance = new KeyValueParticipantStateWriter(writer, newMetrics)
|
||||
|
||||
instance.uploadPackages(aSubmissionId, List.empty, sourceDescription = None)
|
||||
|
||||
verify(writer, times(1)).commit(anyString(), any[Bytes]())
|
||||
verifyEnvelope(packageUploadCaptor.getValue)(_.hasPackageUploadEntry)
|
||||
}
|
||||
@ -62,6 +67,7 @@ class KeyValueParticipantStateWriterSpec extends WordSpec {
|
||||
val instance = new KeyValueParticipantStateWriter(writer, newMetrics)
|
||||
|
||||
instance.submitConfiguration(newRecordTime().addMicros(10000), aSubmissionId, aConfiguration)
|
||||
|
||||
verify(writer, times(1)).commit(anyString(), any[Bytes]())
|
||||
verifyEnvelope(configurationCaptor.getValue)(_.hasConfigurationSubmission)
|
||||
}
|
||||
@ -72,6 +78,7 @@ class KeyValueParticipantStateWriterSpec extends WordSpec {
|
||||
val instance = new KeyValueParticipantStateWriter(writer, newMetrics)
|
||||
|
||||
instance.allocateParty(hint = None, displayName = None, aSubmissionId)
|
||||
|
||||
verify(writer, times(1)).commit(anyString(), any[Bytes]())
|
||||
verifyEnvelope(partyAllocationCaptor.getValue)(_.hasPartyAllocationEntry)
|
||||
}
|
||||
@ -100,20 +107,23 @@ object KeyValueParticipantStateWriterSpec {
|
||||
maxDeduplicationTime = Duration.ofDays(1),
|
||||
)
|
||||
|
||||
private def createWriter(captor: ArgumentCaptor[Bytes]): LedgerWriter = {
|
||||
private def createWriter(
|
||||
envelopeCaptor: ArgumentCaptor[Bytes],
|
||||
correlationIdCaptor: ArgumentCaptor[String] = captor[String]): LedgerWriter = {
|
||||
val writer = mock[LedgerWriter]
|
||||
when(writer.commit(anyString(), captor.capture()))
|
||||
when(writer.commit(correlationIdCaptor.capture(), envelopeCaptor.capture()))
|
||||
.thenReturn(Future.successful(SubmissionResult.Acknowledged))
|
||||
when(writer.participantId).thenReturn(v1.ParticipantId.assertFromString("test-participant"))
|
||||
writer
|
||||
}
|
||||
|
||||
private def submitterInfo(rt: Timestamp, party: Ref.Party) = SubmitterInfo(
|
||||
submitter = party,
|
||||
applicationId = Ref.LedgerString.assertFromString("tests"),
|
||||
commandId = Ref.LedgerString.assertFromString("X"),
|
||||
deduplicateUntil = rt.addMicros(Duration.ofDays(1).toNanos / 1000).toInstant,
|
||||
)
|
||||
private def submitterInfo(recordTime: Timestamp, party: Ref.Party, commandId: String = "X") =
|
||||
SubmitterInfo(
|
||||
submitter = party,
|
||||
applicationId = Ref.LedgerString.assertFromString("tests"),
|
||||
commandId = Ref.LedgerString.assertFromString(commandId),
|
||||
deduplicateUntil = recordTime.addMicros(Duration.ofDays(1).toNanos / 1000).toInstant,
|
||||
)
|
||||
|
||||
private def transactionMeta(let: Timestamp) = TransactionMeta(
|
||||
ledgerEffectiveTime = let,
|
||||
|
Loading…
Reference in New Issue
Block a user