Search in sources :

Example 1 with ResendBatchPublisher

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();
        }
    };
}
Also used : Objects(java.util.Objects) AtomicLong(java.util.concurrent.atomic.AtomicLong) Discovery(com.quorum.tessera.discovery.Discovery) List(java.util.List) Predicate(java.util.function.Predicate) Enclave(com.quorum.tessera.enclave.Enclave) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher) com.quorum.tessera.recovery.workflow(com.quorum.tessera.recovery.workflow) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 2 with ResendBatchPublisher

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);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher)

Example 3 with 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();
    }
}
Also used : BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher) Test(org.junit.Test)

Example 4 with ResendBatchPublisher

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();
    }
}
Also used : PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher) Test(org.junit.Test)

Aggregations

ResendBatchPublisher (com.quorum.tessera.recovery.resend.ResendBatchPublisher)4 Discovery (com.quorum.tessera.discovery.Discovery)3 Enclave (com.quorum.tessera.enclave.Enclave)3 Test (org.junit.Test)2 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)1 com.quorum.tessera.recovery.workflow (com.quorum.tessera.recovery.workflow)1 BatchWorkflowFactory (com.quorum.tessera.recovery.workflow.BatchWorkflowFactory)1 List (java.util.List)1 Objects (java.util.Objects)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Predicate (java.util.function.Predicate)1