Search in sources :

Example 1 with BatchResendManager

use of com.quorum.tessera.recovery.workflow.BatchResendManager in project tessera by ConsenSys.

the class BatchResendManagerImplTest method createBatchResendManager.

@Test
public void createBatchResendManager() {
    BatchResendManager expected = mock(BatchResendManager.class);
    BatchResendManager result;
    try (var staticServiceLoader = mockStatic(ServiceLoader.class)) {
        ServiceLoader<BatchResendManager> serviceLoader = mock(ServiceLoader.class);
        when(serviceLoader.findFirst()).thenReturn(Optional.of(expected));
        staticServiceLoader.when(() -> ServiceLoader.load(BatchResendManager.class)).thenReturn(serviceLoader);
        result = BatchResendManager.create();
        staticServiceLoader.verify(() -> ServiceLoader.load(BatchResendManager.class));
        staticServiceLoader.verifyNoMoreInteractions();
        verify(serviceLoader).findFirst();
        verifyNoMoreInteractions(serviceLoader);
    }
    assertThat(result).isNotNull().isSameAs(expected);
}
Also used : BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Test(org.junit.Test)

Example 2 with BatchResendManager

use of com.quorum.tessera.recovery.workflow.BatchResendManager 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);
    }
}
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) Test(org.junit.Test)

Example 3 with BatchResendManager

use of com.quorum.tessera.recovery.workflow.BatchResendManager 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)

Example 4 with BatchResendManager

use of com.quorum.tessera.recovery.workflow.BatchResendManager in project tessera by ConsenSys.

the class P2PRestApp method getSingletons.

@Override
public Set<Object> getSingletons() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();
    List<URI> peers = runtimeContext.getPeers();
    LOGGER.debug("Found configured peers {}", peers);
    peers.stream().map(NodeUri::create).map(NodeUri::asURI).peek(u -> LOGGER.debug("Adding {} to party store", u)).forEach(partyStore::store);
    final PartyInfoResource partyInfoResource = new PartyInfoResource(discovery, partyInfoParser, runtimeContext.getP2pClient(), enclave, runtimeContext.isRemoteKeyValidation());
    final IPWhitelistFilter iPWhitelistFilter = new IPWhitelistFilter();
    final TransactionResource transactionResource = new TransactionResource(transactionManager, batchResendManager, legacyResendManager);
    final UpCheckResource upCheckResource = new UpCheckResource();
    final PrivacyGroupResource privacyGroupResource = new PrivacyGroupResource(privacyGroupManager);
    if (runtimeContext.isRecoveryMode()) {
        final RecoveryResource recoveryResource = new RecoveryResource(transactionManager, batchResendManager);
        return Set.of(partyInfoResource, iPWhitelistFilter, recoveryResource, upCheckResource);
    }
    return Set.of(partyInfoResource, iPWhitelistFilter, transactionResource, privacyGroupResource, upCheckResource);
}
Also used : PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) AppType(com.quorum.tessera.config.AppType) Logger(org.slf4j.Logger) TransactionManager(com.quorum.tessera.transaction.TransactionManager) LoggerFactory(org.slf4j.LoggerFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Set(java.util.Set) PrivacyGroupManager(com.quorum.tessera.privacygroup.PrivacyGroupManager) NodeUri(com.quorum.tessera.discovery.NodeUri) PartyStore(com.quorum.tessera.p2p.partyinfo.PartyStore) Objects(java.util.Objects) Discovery(com.quorum.tessera.discovery.Discovery) ApplicationPath(jakarta.ws.rs.ApplicationPath) List(java.util.List) Stream(java.util.stream.Stream) UpCheckResource(com.quorum.tessera.api.common.UpCheckResource) GlobalFilter(com.quorum.tessera.api.filter.GlobalFilter) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) Collectors.toSet(java.util.stream.Collectors.toSet) IPWhitelistFilter(com.quorum.tessera.api.filter.IPWhitelistFilter) TesseraRestApplication(com.quorum.tessera.app.TesseraRestApplication) UpCheckResource(com.quorum.tessera.api.common.UpCheckResource) IPWhitelistFilter(com.quorum.tessera.api.filter.IPWhitelistFilter) NodeUri(com.quorum.tessera.discovery.NodeUri) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI)

Example 5 with BatchResendManager

use of com.quorum.tessera.recovery.workflow.BatchResendManager in project tessera by ConsenSys.

the class P2PRestAppTest method setUp.

@Before
public void setUp() {
    runtimeContext = mock(RuntimeContext.class);
    enclave = mock(Enclave.class);
    discovery = mock(Discovery.class);
    partyStore = mock(PartyStore.class);
    transactionManager = mock(TransactionManager.class);
    batchResendManager = mock(BatchResendManager.class);
    legacyResendManager = mock(LegacyResendManager.class);
    privacyGroupManager = mock(PrivacyGroupManager.class);
    p2PRestApp = new P2PRestApp(discovery, enclave, partyStore, transactionManager, batchResendManager, legacyResendManager, privacyGroupManager);
    Client client = mock(Client.class);
    when(runtimeContext.getP2pClient()).thenReturn(client);
    when(runtimeContext.isRemoteKeyValidation()).thenReturn(true);
    when(runtimeContext.getPeers()).thenReturn(List.of(peerUri));
}
Also used : BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) PrivacyGroupManager(com.quorum.tessera.privacygroup.PrivacyGroupManager) Enclave(com.quorum.tessera.enclave.Enclave) TransactionManager(com.quorum.tessera.transaction.TransactionManager) PartyStore(com.quorum.tessera.p2p.partyinfo.PartyStore) Discovery(com.quorum.tessera.discovery.Discovery) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Client(jakarta.ws.rs.client.Client) Before(org.junit.Before)

Aggregations

BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)5 RuntimeContext (com.quorum.tessera.context.RuntimeContext)2 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)2 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)2 Discovery (com.quorum.tessera.discovery.Discovery)2 Enclave (com.quorum.tessera.enclave.Enclave)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)2 BatchWorkflowFactory (com.quorum.tessera.recovery.workflow.BatchWorkflowFactory)2 LegacyResendManager (com.quorum.tessera.recovery.workflow.LegacyResendManager)2 TransactionManager (com.quorum.tessera.transaction.TransactionManager)2 Test (org.junit.Test)2 UpCheckResource (com.quorum.tessera.api.common.UpCheckResource)1 GlobalFilter (com.quorum.tessera.api.filter.GlobalFilter)1 IPWhitelistFilter (com.quorum.tessera.api.filter.IPWhitelistFilter)1 TesseraRestApplication (com.quorum.tessera.app.TesseraRestApplication)1 AppType (com.quorum.tessera.config.AppType)1 NodeUri (com.quorum.tessera.discovery.NodeUri)1 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)1 ApplicationPath (jakarta.ws.rs.ApplicationPath)1