use of com.quorum.tessera.recovery.workflow.BatchWorkflowFactory in project tessera by ConsenSys.
the class BatchResendManagerImplTest method useMaxResultsAlsoWhenBatchSizeTooLarge.
@Test
public void useMaxResultsAlsoWhenBatchSizeTooLarge() {
final ResendBatchRequest request = ResendBatchRequest.Builder.create().withBatchSize(10000000).withPublicKey(KEY_STRING).build();
List<EncryptedTransaction> transactions = IntStream.range(0, 5).mapToObj(i -> mock(EncryptedTransaction.class)).collect(Collectors.toUnmodifiableList());
when(encryptedTransactionDAO.transactionCount()).thenReturn(101L);
when(encryptedTransactionDAO.retrieveTransactions(lt(100), anyInt())).thenReturn(transactions);
when(encryptedTransactionDAO.retrieveTransactions(gt(99), anyInt())).thenReturn(singletonList(mock(EncryptedTransaction.class)));
final BatchWorkflow batchWorkflow = mock(BatchWorkflow.class);
when(batchWorkflow.getPublishedMessageCount()).thenReturn(999L);
when(batchWorkflowFactory.create(101L)).thenReturn(batchWorkflow);
final ResendBatchResponse result = manager.resendBatch(request);
assertThat(result.getTotal()).isEqualTo(999L);
verify(batchWorkflow, times(101)).execute(any(BatchWorkflowContext.class));
verify(encryptedTransactionDAO, times(21)).retrieveTransactions(anyInt(), anyInt());
verify(encryptedTransactionDAO).transactionCount();
verify(batchWorkflowFactory).create(101L);
}
use of com.quorum.tessera.recovery.workflow.BatchWorkflowFactory in project tessera by ConsenSys.
the class BatchResendManagerImplTest method resendBatch.
@Test
public void resendBatch() {
ResendBatchRequest request = ResendBatchRequest.Builder.create().withBatchSize(3).withPublicKey(KEY_STRING).build();
List<EncryptedTransaction> transactions = IntStream.range(0, 5).mapToObj(i -> mock(EncryptedTransaction.class)).collect(Collectors.toUnmodifiableList());
when(encryptedTransactionDAO.transactionCount()).thenReturn(101L);
when(encryptedTransactionDAO.retrieveTransactions(lt(100), anyInt())).thenReturn(transactions);
when(encryptedTransactionDAO.retrieveTransactions(gt(99), anyInt())).thenReturn(singletonList(mock(EncryptedTransaction.class)));
BatchWorkflow batchWorkflow = mock(BatchWorkflow.class);
when(batchWorkflow.getPublishedMessageCount()).thenReturn(999L);
when(batchWorkflowFactory.create(101L)).thenReturn(batchWorkflow);
final ResendBatchResponse result = manager.resendBatch(request);
assertThat(result.getTotal()).isEqualTo(999L);
verify(batchWorkflow).getPublishedMessageCount();
verify(batchWorkflow, times(101)).execute(any(BatchWorkflowContext.class));
verify(encryptedTransactionDAO, times(21)).retrieveTransactions(anyInt(), anyInt());
verify(encryptedTransactionDAO).transactionCount();
verify(batchWorkflowFactory).create(101L);
}
use of com.quorum.tessera.recovery.workflow.BatchWorkflowFactory in project tessera by ConsenSys.
the class BatchResendManagerProviderTest method provider.
@Test
public void provider() {
try (var staticEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
var staticStagingEntityDAO = mockStatic(StagingEntityDAO.class);
var staticBatchWorkflowFactory = mockStatic(BatchWorkflowFactory.class)) {
staticEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
staticStagingEntityDAO.when(StagingEntityDAO::create).thenReturn(mock(StagingEntityDAO.class));
staticBatchWorkflowFactory.when(BatchWorkflowFactory::create).thenReturn(mock(BatchWorkflowFactory.class));
BatchResendManager batchResendManager = BatchResendManagerProvider.provider();
assertThat(batchResendManager).isNotNull().isExactlyInstanceOf(BatchResendManagerImpl.class);
staticEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
staticStagingEntityDAO.verify(StagingEntityDAO::create);
staticBatchWorkflowFactory.verify(BatchWorkflowFactory::create);
staticEncryptedTransactionDAO.verifyNoMoreInteractions();
staticStagingEntityDAO.verifyNoMoreInteractions();
staticBatchWorkflowFactory.verifyNoMoreInteractions();
assertThat(BatchResendManagerHolder.INSTANCE.getBatchResendManager()).isPresent().containsSame(batchResendManager);
assertThat(BatchResendManagerProvider.provider()).isSameAs(batchResendManager);
}
}
use of com.quorum.tessera.recovery.workflow.BatchWorkflowFactory in project tessera by ConsenSys.
the class BatchWorkflowFactoryImplTest method loadMockBatchWorkflowFactory.
@Test
public void loadMockBatchWorkflowFactory() {
BatchWorkflowFactory batchWorkflowFactory = new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
assertThat(batchWorkflowFactory).isExactlyInstanceOf(BatchWorkflowFactoryImpl.class);
}
use of com.quorum.tessera.recovery.workflow.BatchWorkflowFactory 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();
}
}
Aggregations