use of com.quorum.tessera.recovery.workflow.BatchWorkflowContext in project tessera by ConsenSys.
the class BatchResendManagerImpl method resendBatch.
@Override
public ResendBatchResponse resendBatch(ResendBatchRequest request) {
final int batchSize = validateRequestBatchSize(request.getBatchSize());
final byte[] publicKeyData = Base64.getDecoder().decode(request.getPublicKey());
final PublicKey recipientPublicKey = PublicKey.from(publicKeyData);
final long transactionCount = encryptedTransactionDAO.transactionCount();
final long batchCount = calculateBatchCount(maxResults, transactionCount);
final BatchWorkflow batchWorkflow = batchWorkflowFactory.create(transactionCount);
IntStream.range(0, (int) batchCount).map(i -> i * maxResults).mapToObj(offset -> encryptedTransactionDAO.retrieveTransactions(offset, maxResults)).flatMap(List::stream).forEach(encryptedTransaction -> {
final BatchWorkflowContext context = new BatchWorkflowContext();
context.setEncryptedTransaction(encryptedTransaction);
context.setEncodedPayload(encryptedTransaction.getPayload());
context.setRecipientKey(recipientPublicKey);
context.setBatchSize(batchSize);
batchWorkflow.execute(context);
});
return ResendBatchResponse.from(batchWorkflow.getPublishedMessageCount());
}
use of com.quorum.tessera.recovery.workflow.BatchWorkflowContext in project tessera by ConsenSys.
the class BatchWorkflowFactoryImplTest method workflowExecutedReturnFalse.
@Test
public void workflowExecutedReturnFalse() {
BatchWorkflowFactoryImpl batchWorkflowFactory = new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
BatchWorkflow batchWorkflow = batchWorkflowFactory.create(999L);
assertThat(batchWorkflow).isNotNull();
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
PublicKey publicKey = mock(PublicKey.class);
batchWorkflowContext.setRecipientKey(publicKey);
EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
batchWorkflowContext.setEncryptedTransaction(encryptedTransaction);
batchWorkflowContext.setEncodedPayload(mock(EncodedPayload.class));
when(enclave.status()).thenReturn(Service.Status.STARTED);
assertThat(batchWorkflow.execute(batchWorkflowContext)).isFalse();
assertThat(batchWorkflow.getPublishedMessageCount()).isZero();
verify(enclave).status();
}
use of com.quorum.tessera.recovery.workflow.BatchWorkflowContext in project tessera by ConsenSys.
the class BatchWorkflowFactoryImplTest method createBatchWorkflowFactoryImplAndExecuteWorkflow.
@Test
public void createBatchWorkflowFactoryImplAndExecuteWorkflow() {
BatchWorkflowFactoryImpl batchWorkflowFactory = new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
BatchWorkflow batchWorkflow = batchWorkflowFactory.create(1L);
assertThat(batchWorkflow).isNotNull();
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
PublicKey recipientKey = mock(PublicKey.class);
batchWorkflowContext.setRecipientKey(recipientKey);
PublicKey ownedKey = mock(PublicKey.class);
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getSenderKey()).thenReturn(ownedKey);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey));
EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
batchWorkflowContext.setEncryptedTransaction(encryptedTransaction);
batchWorkflowContext.setEncodedPayload(encodedPayload);
batchWorkflowContext.setBatchSize(100);
when(mockPayloadBuilder.build()).thenReturn(encodedPayload);
when(enclave.status()).thenReturn(Service.Status.STARTED);
when(enclave.getPublicKeys()).thenReturn(Set.of(ownedKey));
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(recipientKey, "url")));
when(discovery.getCurrent()).thenReturn(nodeInfo);
assertThat(batchWorkflow.execute(batchWorkflowContext)).isTrue();
assertThat(batchWorkflow.getPublishedMessageCount()).isOne();
verify(enclave).status();
verify(enclave, times(2)).getPublicKeys();
mockStaticPayloadBuilder.verify(() -> EncodedPayload.Builder.forRecipient(any(), any()));
verify(mockPayloadBuilder).build();
verify(discovery).getCurrent();
verify(resendBatchPublisher).publishBatch(any(), any());
}
Aggregations