Search in sources :

Example 6 with Discovery

use of com.quorum.tessera.discovery.Discovery 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 7 with Discovery

use of com.quorum.tessera.discovery.Discovery 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 8 with Discovery

use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.

the class LegacyResendManagerProvider method provider.

public static LegacyResendManager provider() {
    final Enclave enclave = Enclave.create();
    final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    final int resendFetchSize = 100;
    final PayloadPublisher payloadPublisher = PayloadPublisher.create();
    final Discovery discovery = Discovery.create();
    return new LegacyResendManagerImpl(enclave, encryptedTransactionDAO, resendFetchSize, payloadPublisher, discovery);
}
Also used : PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO)

Example 9 with Discovery

use of com.quorum.tessera.discovery.Discovery 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 10 with Discovery

use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.

the class LegacyResendManagerProviderTest method provider.

@Test
public void provider() {
    try (var enclaveMockedStatic = mockStatic(Enclave.class);
        var encryptedTransactionDAOMockedStatic = mockStatic(EncryptedTransactionDAO.class);
        var payloadPublisherMockedStatic = mockStatic(PayloadPublisher.class);
        var discoveryMockedStatic = mockStatic(Discovery.class)) {
        enclaveMockedStatic.when(Enclave::create).thenReturn(mock(Enclave.class));
        encryptedTransactionDAOMockedStatic.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        payloadPublisherMockedStatic.when(PayloadPublisher::create).thenReturn(mock(PayloadPublisher.class));
        discoveryMockedStatic.when(Discovery::create).thenReturn(mock(Discovery.class));
        LegacyResendManager legacyResendManager = LegacyResendManagerProvider.provider();
        assertThat(legacyResendManager).isNotNull();
        enclaveMockedStatic.verify(Enclave::create);
        enclaveMockedStatic.verifyNoMoreInteractions();
        encryptedTransactionDAOMockedStatic.verify(EncryptedTransactionDAO::create);
        encryptedTransactionDAOMockedStatic.verifyNoMoreInteractions();
        payloadPublisherMockedStatic.verify(PayloadPublisher::create);
        discoveryMockedStatic.verify(Discovery::create);
        discoveryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) Test(org.junit.Test)

Aggregations

Discovery (com.quorum.tessera.discovery.Discovery)20 Test (org.junit.Test)9 Enclave (com.quorum.tessera.enclave.Enclave)8 RuntimeContext (com.quorum.tessera.context.RuntimeContext)6 Config (com.quorum.tessera.config.Config)5 TransactionManager (com.quorum.tessera.transaction.TransactionManager)5 NodeUri (com.quorum.tessera.discovery.NodeUri)3 ResendBatchPublisher (com.quorum.tessera.recovery.resend.ResendBatchPublisher)3 LegacyResendManager (com.quorum.tessera.recovery.workflow.LegacyResendManager)3 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)3 Objects (java.util.Objects)3 ConfigFactory (com.quorum.tessera.config.ConfigFactory)2 ServerConfig (com.quorum.tessera.config.ServerConfig)2 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)2 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)2 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)2 BatchTransactionRequester (com.quorum.tessera.recovery.resend.BatchTransactionRequester)2 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)2