use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class RecoveryImpl method sync.
@Override
public RecoveryResult sync() {
final AtomicInteger payloadCount = new AtomicInteger(0);
final AtomicInteger syncFailureCount = new AtomicInteger(0);
final int maxResult = BATCH_SIZE;
for (int offset = 0; offset < stagingEntityDAO.countAll(); offset += maxResult) {
final List<StagingTransaction> transactions = stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(offset, maxResult);
final Map<String, List<StagingTransaction>> grouped = transactions.stream().collect(Collectors.groupingBy(StagingTransaction::getHash, LinkedHashMap::new, toList()));
grouped.forEach((key, value) -> value.stream().filter(t -> {
payloadCount.incrementAndGet();
EncodedPayload encodedPayload = t.getEncodedPayload();
try {
transactionManager.storePayload(encodedPayload);
} catch (PrivacyViolationException | PersistenceException ex) {
LOGGER.error("An error occurred during batch resend sync stage.", ex);
syncFailureCount.incrementAndGet();
}
return PrivacyMode.PRIVATE_STATE_VALIDATION == t.getPrivacyMode();
}).findFirst());
}
if (syncFailureCount.get() > 0) {
LOGGER.warn("There have been issues during the synchronisation process. " + "Problematic transactions have been ignored.");
if (syncFailureCount.get() == payloadCount.get()) {
return RecoveryResult.FAILURE;
}
return RecoveryResult.PARTIAL_SUCCESS;
}
return RecoveryResult.SUCCESS;
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class EncodedPayloadPublisherTest method outstandingPayloadsReachTotalExpected.
@Test
public void outstandingPayloadsReachTotalExpected() {
final PublicKey recipientKey = PublicKey.from("test-key".getBytes());
EncodedPayload encodedPayload = mock(EncodedPayload.class);
final BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
batchWorkflowContext.setBatchSize(100);
batchWorkflowContext.setExpectedTotal(4L);
batchWorkflowContext.setPayloadsToPublish(Set.of(encodedPayload));
batchWorkflowContext.setRecipientKey(recipientKey);
batchWorkflowContext.setRecipient(Recipient.of(recipientKey, "http://junit.com"));
encodedPayloadPublisher.execute(batchWorkflowContext);
batchWorkflowContext.setExpectedTotal(3L);
encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(0);
encodedPayloadPublisher.execute(batchWorkflowContext);
batchWorkflowContext.setExpectedTotal(2L);
encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(2);
List<EncodedPayload> sent = List.of(encodedPayload, encodedPayload);
verify(resendBatchPublisher).publishBatch(sent, "http://junit.com");
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class EncodedPayloadPublisherTest method outstandingPayloadsPlusPublishedReachTotalExpected.
@Test
public void outstandingPayloadsPlusPublishedReachTotalExpected() {
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
batchWorkflowContext.setBatchSize(2);
batchWorkflowContext.setExpectedTotal(6L);
EncodedPayload encodedPayload = mock(EncodedPayload.class);
batchWorkflowContext.setPayloadsToPublish(Set.of(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.execute(batchWorkflowContext);
batchWorkflowContext.setExpectedTotal(5L);
encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(0);
encodedPayloadPublisher.execute(batchWorkflowContext);
batchWorkflowContext.setExpectedTotal(4L);
encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(2);
// Not publish yet as not yet reach batch size
encodedPayloadPublisher.execute(batchWorkflowContext);
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(2);
batchWorkflowContext.setExpectedTotal(3L);
encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
// Publish here because message count + outstanding = expected total
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(3);
verify(resendBatchPublisher, times(2)).publishBatch(anyList(), eq("http://junit.com"));
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class EncodedPayloadPublisherTest method executeIfNumberOfPayloadsReachBatchSize.
@Test
public void executeIfNumberOfPayloadsReachBatchSize() {
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
batchWorkflowContext.setBatchSize(2);
batchWorkflowContext.setExpectedTotal(9L);
EncodedPayload encodedPayload = mock(EncodedPayload.class);
batchWorkflowContext.setPayloadsToPublish(Set.of(encodedPayload));
PublicKey recipientKey = mock(PublicKey.class);
Recipient recipient = mock(Recipient.class);
when(recipient.getUrl()).thenReturn("http://junit.com");
batchWorkflowContext.setRecipientKey(recipientKey);
batchWorkflowContext.setRecipient(recipient);
boolean result = IntStream.range(0, batchSize).allMatch(i -> encodedPayloadPublisher.execute(batchWorkflowContext));
assertThat(result).isTrue();
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(9);
List<EncodedPayload> sent2 = List.of(encodedPayload, encodedPayload);
List<EncodedPayload> sent1 = List.of(encodedPayload);
verify(resendBatchPublisher, times(4)).publishBatch(sent2, "http://junit.com");
verify(resendBatchPublisher).publishBatch(sent1, "http://junit.com");
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class EncodedPayloadPublisherTest method executeIfNumberOfPayloadsReachTotal.
@Test
public void executeIfNumberOfPayloadsReachTotal() {
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
batchWorkflowContext.setBatchSize(100);
batchWorkflowContext.setExpectedTotal(9L);
EncodedPayload encodedPayload = mock(EncodedPayload.class);
batchWorkflowContext.setPayloadsToPublish(Set.of(encodedPayload));
PublicKey recipientKey = mock(PublicKey.class);
Recipient recipient = mock(Recipient.class);
when(recipient.getUrl()).thenReturn("http://junit.com");
batchWorkflowContext.setRecipientKey(recipientKey);
batchWorkflowContext.setRecipient(recipient);
boolean result = IntStream.range(0, batchSize).allMatch(i -> encodedPayloadPublisher.execute(batchWorkflowContext));
assertThat(result).isTrue();
assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(9);
List<EncodedPayload> sent = Arrays.asList(new EncodedPayload[9]);
Collections.fill(sent, encodedPayload);
verify(resendBatchPublisher).publishBatch(sent, "http://junit.com");
}
Aggregations