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