Search in sources :

Example 11 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class ResendManagerProvider method provider.

public static ResendManager provider() {
    LOGGER.debug("Creating EncryptedTransactionDAO");
    final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    LOGGER.debug("Created EncryptedTransactionDAO {}", encryptedTransactionDAO);
    LOGGER.debug("Creating Enclave");
    final Enclave enclave = Enclave.create();
    LOGGER.debug("Created Enclave {}", enclave);
    PayloadDigest payloadDigest = PayloadDigest.create();
    return new ResendManagerImpl(encryptedTransactionDAO, enclave, payloadDigest);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO)

Example 12 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO 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)

Example 13 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class BatchResendManagerImplTest method useMaxResultsWhenBatchSizeNotProvided.

@Test
public void useMaxResultsWhenBatchSizeNotProvided() {
    final ResendBatchRequest request = ResendBatchRequest.Builder.create().withPublicKey(KEY_STRING).build();
    List<EncryptedTransaction> transactions = IntStream.range(0, 5).mapToObj(i -> mock(EncryptedTransaction.class)).collect(Collectors.toUnmodifiableList());
    when(encryptedTransactionDAO.transactionCount()).thenReturn(101L);
    BatchWorkflow batchWorkflow = mock(BatchWorkflow.class);
    when(batchWorkflow.getPublishedMessageCount()).thenReturn(// arbitary total that's returned as result.getTotal()
    999L);
    when(batchWorkflowFactory.create(101L)).thenReturn(batchWorkflow);
    when(encryptedTransactionDAO.retrieveTransactions(lt(100), anyInt())).thenReturn(transactions);
    when(encryptedTransactionDAO.retrieveTransactions(gt(99), anyInt())).thenReturn(List.of(mock(EncryptedTransaction.class)));
    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);
}
Also used : AdditionalMatchers.lt(org.mockito.AdditionalMatchers.lt) ResendBatchRequest(com.quorum.tessera.recovery.resend.ResendBatchRequest) IntStream(java.util.stream.IntStream) PublicKey(com.quorum.tessera.encryption.PublicKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Base64Codec(com.quorum.tessera.base64.Base64Codec) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) Collections.singletonList(java.util.Collections.singletonList) PushBatchRequest(com.quorum.tessera.recovery.resend.PushBatchRequest) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) StagingEntityDAO(com.quorum.tessera.data.staging.StagingEntityDAO) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) After(org.junit.After) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) AdditionalMatchers.gt(org.mockito.AdditionalMatchers.gt) com.quorum.tessera.enclave(com.quorum.tessera.enclave) Nonce(com.quorum.tessera.encryption.Nonce) ServiceLoader(java.util.ServiceLoader) Test(org.junit.Test) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) Optional(java.util.Optional) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) ResendBatchRequest(com.quorum.tessera.recovery.resend.ResendBatchRequest) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 14 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class BatchResendManagerProvider method provider.

public static BatchResendManager provider() {
    if (BatchResendManagerHolder.INSTANCE.getBatchResendManager().isPresent()) {
        return BatchResendManagerHolder.INSTANCE.getBatchResendManager().get();
    }
    LOGGER.debug("Creating EncryptedTransactionDAO");
    final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    LOGGER.debug("Created EncryptedTransactionDAO {}", encryptedTransactionDAO);
    LOGGER.debug("Creating StagingEntityDAO");
    final StagingEntityDAO stagingEntityDAO = StagingEntityDAO.create();
    LOGGER.debug("Created StagingEntityDAO");
    final int defaultMaxResults = 10000;
    BatchWorkflowFactory batchWorkflowFactory = BatchWorkflowFactory.create();
    BatchResendManager batchResendManager = new BatchResendManagerImpl(stagingEntityDAO, encryptedTransactionDAO, defaultMaxResults, batchWorkflowFactory);
    return BatchResendManagerHolder.INSTANCE.setBatchResendManager(batchResendManager);
}
Also used : BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) StagingEntityDAO(com.quorum.tessera.data.staging.StagingEntityDAO) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO)

Aggregations

EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)14 Test (org.junit.Test)9 Enclave (com.quorum.tessera.enclave.Enclave)6 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)5 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)5 BatchWorkflowFactory (com.quorum.tessera.recovery.workflow.BatchWorkflowFactory)5 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)4 PrivacyHelper (com.quorum.tessera.transaction.PrivacyHelper)4 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)4 Base64Codec (com.quorum.tessera.base64.Base64Codec)3 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)3 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)3 com.quorum.tessera.enclave (com.quorum.tessera.enclave)3 Nonce (com.quorum.tessera.encryption.Nonce)3 PublicKey (com.quorum.tessera.encryption.PublicKey)3 PushBatchRequest (com.quorum.tessera.recovery.resend.PushBatchRequest)3 ResendBatchRequest (com.quorum.tessera.recovery.resend.ResendBatchRequest)3 ResendBatchResponse (com.quorum.tessera.recovery.resend.ResendBatchResponse)3 BatchWorkflow (com.quorum.tessera.recovery.workflow.BatchWorkflow)3 BatchWorkflowContext (com.quorum.tessera.recovery.workflow.BatchWorkflowContext)3