Search in sources :

Example 1 with P2pClient

use of com.quorum.tessera.partyinfo.P2pClient in project tessera by ConsenSys.

the class P2pClientProviderTest method provider.

@Test
public void provider() {
    ConfigFactory configFactory = mock(ConfigFactory.class);
    Config config = mock(Config.class);
    when(config.getP2PServerConfig()).thenReturn(mock(ServerConfig.class));
    when(configFactory.getConfig()).thenReturn(config);
    try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class)) {
        configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
        P2pClient result = P2pClientProvider.provider();
        assertThat(result).isNotNull().isExactlyInstanceOf(RestP2pClient.class);
        verify(configFactory).getConfig();
        verifyNoMoreInteractions(configFactory);
        configFactoryMockedStatic.verify(ConfigFactory::create);
        configFactoryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) P2pClient(com.quorum.tessera.partyinfo.P2pClient) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 2 with P2pClient

use of com.quorum.tessera.partyinfo.P2pClient in project tessera by ConsenSys.

the class ScheduledServiceFactory method build.

public void build() {
    IntervalPropertyHelper intervalPropertyHelper = new IntervalPropertyHelper(config.getP2PServerConfig().getProperties());
    LOGGER.info("Creating p2p client");
    P2pClient p2pClient = P2pClient.create();
    LOGGER.info("Created p2p client {}", p2pClient);
    if (enableSync) {
        ResendPartyStore resendPartyStore = ResendPartyStore.create();
        TransactionRequester transactionRequester = TransactionRequester.create();
        SyncPoller syncPoller = new SyncPoller(resendPartyStore, transactionRequester, p2pClient);
        ScheduledExecutorService scheduledExecutorService = java.util.concurrent.Executors.newSingleThreadScheduledExecutor();
        tesseraScheduledExecutors.add(new TesseraScheduledExecutor(scheduledExecutorService, syncPoller, intervalPropertyHelper.syncInterval(), 5000L));
    }
    LOGGER.info("Creating EnclaveKeySynchroniser");
    final EnclaveKeySynchroniser enclaveKeySynchroniser = ServiceLoader.load(EnclaveKeySynchroniser.class).stream().map(ServiceLoader.Provider::get).findFirst().get();
    LOGGER.info("Created EnclaveKeySynchroniser {}", enclaveKeySynchroniser);
    tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), () -> enclaveKeySynchroniser.syncKeys(), intervalPropertyHelper.enclaveKeySyncInterval(), 5000L));
    LOGGER.info("Creating PartyInfoBroadcaster");
    PartyInfoBroadcaster partyInfoPoller = new PartyInfoBroadcaster(p2pClient);
    LOGGER.info("Created PartyInfoBroadcaster {}", partyInfoPoller);
    tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), partyInfoPoller, intervalPropertyHelper.partyInfoInterval(), 5000L));
    tesseraScheduledExecutors.forEach(TesseraScheduledExecutor::start);
    LOGGER.info("Creating Enclave");
    Enclave enclave = Enclave.create();
    LOGGER.info("Created Enclave {}", enclave);
    serviceContainer = new ServiceContainer(enclave);
    LOGGER.info("Starting Enclave");
    serviceContainer.start();
    LOGGER.info("Started Enclave");
}
Also used : TransactionRequester(com.quorum.tessera.p2p.resend.TransactionRequester) TesseraScheduledExecutor(com.quorum.tessera.threading.TesseraScheduledExecutor) ResendPartyStore(com.quorum.tessera.p2p.resend.ResendPartyStore) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) SyncPoller(com.quorum.tessera.p2p.resend.SyncPoller) ServiceContainer(com.quorum.tessera.service.ServiceContainer) P2pClient(com.quorum.tessera.partyinfo.P2pClient) Enclave(com.quorum.tessera.enclave.Enclave) PartyInfoBroadcaster(com.quorum.tessera.p2p.partyinfo.PartyInfoBroadcaster) EnclaveKeySynchroniser(com.quorum.tessera.discovery.EnclaveKeySynchroniser)

Example 3 with P2pClient

use of com.quorum.tessera.partyinfo.P2pClient in project tessera by ConsenSys.

the class SyncPollerTest method init.

@Before
public void init() {
    this.executorService = mock(ExecutorService.class);
    this.resendPartyStore = mock(ResendPartyStore.class);
    this.transactionRequester = mock(TransactionRequester.class);
    this.partyInfoService = mock(Discovery.class);
    this.partyInfoParser = mock(PartyInfoParser.class);
    this.p2pClient = mock(P2pClient.class);
    doReturn(true).when(p2pClient).sendPartyInfo(anyString(), any());
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("myurl").build();
    when(partyInfoService.getCurrent()).thenReturn(nodeInfo);
    this.syncPoller = new SyncPoller(executorService, resendPartyStore, transactionRequester, partyInfoService, partyInfoParser, p2pClient);
}
Also used : P2pClient(com.quorum.tessera.partyinfo.P2pClient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ExecutorService(java.util.concurrent.ExecutorService) Discovery(com.quorum.tessera.discovery.Discovery) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) Before(org.junit.Before)

Example 4 with P2pClient

use of com.quorum.tessera.partyinfo.P2pClient in project tessera by ConsenSys.

the class P2pClientProvider method provider.

public static P2pClient provider() {
    Config config = ConfigFactory.create().getConfig();
    SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    return new RestP2pClient(client);
}
Also used : Config(com.quorum.tessera.config.Config) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client) P2pClient(com.quorum.tessera.partyinfo.P2pClient)

Aggregations

P2pClient (com.quorum.tessera.partyinfo.P2pClient)4 Config (com.quorum.tessera.config.Config)2 ConfigFactory (com.quorum.tessera.config.ConfigFactory)1 ServerConfig (com.quorum.tessera.config.ServerConfig)1 IntervalPropertyHelper (com.quorum.tessera.config.util.IntervalPropertyHelper)1 Discovery (com.quorum.tessera.discovery.Discovery)1 EnclaveKeySynchroniser (com.quorum.tessera.discovery.EnclaveKeySynchroniser)1 Enclave (com.quorum.tessera.enclave.Enclave)1 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)1 PartyInfoBroadcaster (com.quorum.tessera.p2p.partyinfo.PartyInfoBroadcaster)1 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)1 ResendPartyStore (com.quorum.tessera.p2p.resend.ResendPartyStore)1 SyncPoller (com.quorum.tessera.p2p.resend.SyncPoller)1 TransactionRequester (com.quorum.tessera.p2p.resend.TransactionRequester)1 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)1 ServiceContainer (com.quorum.tessera.service.ServiceContainer)1 ClientSSLContextFactory (com.quorum.tessera.ssl.context.ClientSSLContextFactory)1 SSLContextFactory (com.quorum.tessera.ssl.context.SSLContextFactory)1 TesseraScheduledExecutor (com.quorum.tessera.threading.TesseraScheduledExecutor)1 Client (jakarta.ws.rs.client.Client)1