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());
}
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);
}
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);
}
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");
}
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();
}
Aggregations