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();
}
};
}
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);
}
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);
}
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();
}
}
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();
}
}
Aggregations