use of com.quorum.tessera.recovery.resend.ResendBatchPublisher in project tessera by ConsenSys.
the class BatchWorkflowFactoryImpl method create.
@Override
public BatchWorkflow create(long transactionCount) {
ValidateEnclaveStatus validateEnclaveStatus = new ValidateEnclaveStatus(enclave);
PreparePayloadForRecipient preparePayloadForRecipient = new PreparePayloadForRecipient();
FindRecipientFromPartyInfo findRecipientFromPartyInfo = new FindRecipientFromPartyInfo(discovery);
FilterPayload filterPayload = new FilterPayload(enclave);
SearchRecipientKeyForPayload searchRecipientKeyForPayload = new SearchRecipientKeyForPayload(enclave);
SenderIsNotRecipient senderIsNotRecipient = new SenderIsNotRecipient(enclave);
EncodedPayloadPublisher encodedPayloadPublisher = new EncodedPayloadPublisher(resendBatchPublisher);
List<BatchWorkflowAction> handlers = List.of(validateEnclaveStatus, filterPayload, preparePayloadForRecipient, searchRecipientKeyForPayload, findRecipientFromPartyInfo, senderIsNotRecipient, encodedPayloadPublisher);
return new BatchWorkflow() {
private final AtomicLong filteredMessageCount = new AtomicLong(transactionCount);
@Override
public boolean execute(BatchWorkflowContext context) {
context.setExpectedTotal(filteredMessageCount.get());
boolean outcome = handlers.stream().filter(Predicate.not(h -> h.execute(context))).findFirst().isEmpty();
if (!outcome) {
context.setExpectedTotal(filteredMessageCount.decrementAndGet());
encodedPayloadPublisher.checkOutstandingPayloads(context);
}
return outcome;
}
@Override
public long getPublishedMessageCount() {
return encodedPayloadPublisher.getPublishedCount();
}
};
}
use of com.quorum.tessera.recovery.resend.ResendBatchPublisher in project tessera by ConsenSys.
the class BatchWorkflowFactoryProvider method provider.
public static BatchWorkflowFactory provider() {
Enclave enclave = Enclave.create();
Discovery discovery = Discovery.create();
ResendBatchPublisher resendBatchPublisher = ResendBatchPublisher.create();
return new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
}
use of com.quorum.tessera.recovery.resend.ResendBatchPublisher in project tessera by ConsenSys.
the class BatchWorkflowFactoryProviderTest method provider.
@Test
public void provider() {
try (var staticEnclave = mockStatic(Enclave.class);
var staticDiscovery = mockStatic(Discovery.class);
var staticResendBatchPublisher = mockStatic(ResendBatchPublisher.class)) {
staticEnclave.when(Enclave::create).thenReturn(mock(Enclave.class));
staticDiscovery.when(Discovery::create).thenReturn(mock(Discovery.class));
staticResendBatchPublisher.when(ResendBatchPublisher::create).thenReturn(mock(ResendBatchPublisher.class));
BatchWorkflowFactory batchWorkflowFactory = BatchWorkflowFactoryProvider.provider();
assertThat(batchWorkflowFactory).isNotNull().isExactlyInstanceOf(BatchWorkflowFactoryImpl.class);
staticEnclave.verify(Enclave::create);
staticDiscovery.verify(Discovery::create);
staticResendBatchPublisher.verify(ResendBatchPublisher::create);
staticEnclave.verifyNoMoreInteractions();
staticDiscovery.verifyNoMoreInteractions();
staticResendBatchPublisher.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.recovery.resend.ResendBatchPublisher in project tessera by ConsenSys.
the class ResendBatchPublisherProviderTest method provider.
@Test
public void provider() {
try (var recoveryClientMockedStatic = mockStatic(RecoveryClient.class);
var payloadEncoderMockedStatic = mockStatic(PayloadEncoder.class)) {
recoveryClientMockedStatic.when(RecoveryClient::create).thenReturn(mock(RecoveryClient.class));
payloadEncoderMockedStatic.when(() -> PayloadEncoder.create(EncodedPayloadCodec.LEGACY)).thenReturn(mock(PayloadEncoder.class));
ResendBatchPublisher resendBatchPublisher = ResendBatchPublisherProvider.provider();
assertThat(resendBatchPublisher).isNotNull().isExactlyInstanceOf(RestResendBatchPublisher.class);
recoveryClientMockedStatic.verify(RecoveryClient::create);
recoveryClientMockedStatic.verifyNoMoreInteractions();
payloadEncoderMockedStatic.verify(() -> PayloadEncoder.create(EncodedPayloadCodec.LEGACY));
payloadEncoderMockedStatic.verifyNoMoreInteractions();
}
}
Aggregations