Search in sources :

Example 56 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class RecoveryImplTest method testSyncFailed.

@Test
public void testSyncFailed() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    EncodedPayload encodedPayload2 = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(encodedPayload);
    when(version2.getEncodedPayload()).thenReturn(encodedPayload2);
    List<StagingTransaction> stagingTransactions = List.of(version1, version2);
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(stagingTransactions);
    when(stagingEntityDAO.countAll()).thenReturn((long) stagingTransactions.size());
    when(transactionManager.storePayload(any())).thenThrow(PrivacyViolationException.class);
    RecoveryResult result = recovery.sync();
    assertThat(result).isEqualTo(RecoveryResult.FAILURE);
    verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
    verify(stagingEntityDAO, times(2)).countAll();
    verify(transactionManager, times(2)).storePayload(any());
}
Also used : StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 57 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class RecoveryImplTest method testSyncSuccess.

@Test
public void testSyncSuccess() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    EncodedPayload firstPayload = mock(EncodedPayload.class);
    EncodedPayload secondPayload = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(firstPayload);
    when(version2.getEncodedPayload()).thenReturn(secondPayload);
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2));
    when(stagingEntityDAO.countAll()).thenReturn(2L);
    when(transactionManager.storePayload(any())).thenReturn(new MessageHash("hash".getBytes()));
    RecoveryResult result = recovery.sync();
    assertThat(result).isEqualTo(RecoveryResult.SUCCESS);
    verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
    verify(stagingEntityDAO, times(2)).countAll();
    verify(transactionManager).storePayload(firstPayload);
    verify(transactionManager).storePayload(secondPayload);
}
Also used : StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 58 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class EncodedPayloadPublisherTest method noOutstandingPayload.

@Test
public void noOutstandingPayload() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(100);
    batchWorkflowContext.setExpectedTotal(4L);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    batchWorkflowContext.setEncodedPayload(encodedPayload);
    PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getUrl()).thenReturn("http://junit.com");
    batchWorkflowContext.setRecipientKey(recipientKey);
    batchWorkflowContext.setRecipient(recipient);
    encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(0);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 59 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class EncodedPayloadPublisherTest method flattenedPayloadsOverBatchSizeSplitsToSublists.

@Test
public void flattenedPayloadsOverBatchSizeSplitsToSublists() {
    final int numberOfMessagesToSend = 10;
    PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = Recipient.of(recipientKey, "http://junit.com");
    EncodedPayload encodedPayloadFirst = mock(EncodedPayload.class);
    EncodedPayload encodedPayloadSecond = mock(EncodedPayload.class);
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(3);
    batchWorkflowContext.setExpectedTotal(10L);
    batchWorkflowContext.setPayloadsToPublish(new LinkedHashSet<>(List.of(encodedPayloadFirst, encodedPayloadSecond)));
    batchWorkflowContext.setRecipientKey(recipientKey);
    batchWorkflowContext.setRecipient(recipient);
    boolean result = IntStream.range(0, numberOfMessagesToSend).allMatch(i -> encodedPayloadPublisher.execute(batchWorkflowContext));
    assertThat(result).isTrue();
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(10);
    List<EncodedPayload> batchOne = List.of(encodedPayloadFirst, encodedPayloadSecond, encodedPayloadFirst);
    List<EncodedPayload> batchTwo = List.of(encodedPayloadSecond, encodedPayloadFirst, encodedPayloadSecond);
    List<EncodedPayload> leftovers = List.of(encodedPayloadFirst, encodedPayloadSecond);
    verify(resendBatchPublisher, times(3)).publishBatch(batchOne, "http://junit.com");
    verify(resendBatchPublisher, times(3)).publishBatch(batchTwo, "http://junit.com");
    verify(resendBatchPublisher).publishBatch(leftovers, "http://junit.com");
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.node.Recipient) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 60 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class FilterPayloadTest method testIrrelevantPayload.

@Test
public void testIrrelevantPayload() {
    BatchWorkflowContext context = new BatchWorkflowContext();
    final PublicKey requester = mock(PublicKey.class);
    final PublicKey recipient = mock(PublicKey.class);
    final PublicKey thisNode = mock(PublicKey.class);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getSenderKey()).thenReturn(thisNode);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(thisNode, recipient));
    context.setEncodedPayload(encodedPayload);
    context.setRecipientKey(requester);
    when(enclave.getPublicKeys()).thenReturn(Set.of(thisNode));
    boolean result = filterPayload.filter(context);
    assertThat(result).isFalse();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Aggregations

EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)91 Test (org.junit.Test)60 PublicKey (com.quorum.tessera.encryption.PublicKey)50 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)23 Response (jakarta.ws.rs.core.Response)20 MessageHash (com.quorum.tessera.data.MessageHash)13 Collectors (java.util.stream.Collectors)12 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)11 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)11 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)9 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)8 Recipient (com.quorum.tessera.partyinfo.node.Recipient)8 java.util (java.util)8 Invocation (jakarta.ws.rs.client.Invocation)6 WebTarget (jakarta.ws.rs.client.WebTarget)6 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)5 PrivacyMetadata (com.quorum.tessera.enclave.PrivacyMetadata)5 RecipientBox (com.quorum.tessera.enclave.RecipientBox)5 TxHash (com.quorum.tessera.enclave.TxHash)5 ResendRequest (com.quorum.tessera.p2p.resend.ResendRequest)5