use of com.radixdlt.properties.RuntimeProperties in project radixdlt by radixdlt.
the class NetworkQueryHostIpTest method testPropertyEmpty.
@Test
public void testPropertyEmpty() {
RuntimeProperties properties = mock(RuntimeProperties.class);
when(properties.get(eq(NetworkQueryHostIp.QUERY_URLS_PROPERTY), any())).thenReturn("");
NetworkQueryHostIp nqhip = (NetworkQueryHostIp) NetworkQueryHostIp.create(properties);
assertEquals(NetworkQueryHostIp.DEFAULT_QUERY_URLS.size(), nqhip.count());
}
use of com.radixdlt.properties.RuntimeProperties in project radixdlt by radixdlt.
the class DeterministicP2PNetworkTest method defaultProperties.
protected RuntimeProperties defaultProperties() {
try {
final var props = new RuntimeProperties(new JSONObject(), new String[] {});
props.set("network.p2p.max_inbound_channels", 10);
props.set("network.p2p.max_outbound_channels", 10);
return props;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
use of com.radixdlt.properties.RuntimeProperties in project radixdlt by radixdlt.
the class P2PTestNetworkRunner method createInjector.
private static Injector createInjector(MockP2PNetwork p2pNetwork, DeterministicNetwork network, P2PConfig p2pConfig, ECKeyPair nodeKey, RadixNodeUri selfUri, int selfNodeIndex) throws ParseException {
final var properties = new RuntimeProperties(new JSONObject(), new String[] {});
return Guice.createInjector(Modules.override(new P2PModule(properties)).with(new AbstractModule() {
@Override
protected void configure() {
bind(TestCounters.class).toInstance(new TestCounters());
bind(P2PConfig.class).toInstance(p2pConfig);
bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
bind(SystemCounters.class).to(SystemCountersImpl.class).in(Scopes.SINGLETON);
}
@Provides
public PeerOutboundBootstrap peerOutboundBootstrap(TestCounters testCounters) {
return uri -> {
testCounters.outboundChannelsBootstrapped += 1;
p2pNetwork.createChannel(selfNodeIndex, uri);
};
}
}), new PeerDiscoveryModule(), new PeerLivenessMonitorModule(), new DispatcherModule(), new AbstractModule() {
@Override
protected void configure() {
final var dbDir = new TemporaryFolder();
try {
dbDir.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
bindConstant().annotatedWith(NetworkId.class).to(Network.LOCALNET.getId());
bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
bindConstant().annotatedWith(DatabaseLocation.class).to(dbDir.getRoot().getAbsolutePath());
bindConstant().annotatedWith(DatabaseCacheSize.class).to(100_000L);
bind(ECKeyPair.class).annotatedWith(Self.class).toInstance(nodeKey);
bind(ECPublicKey.class).annotatedWith(Self.class).toInstance(nodeKey.getPublicKey());
bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.create(nodeKey.getPublicKey()));
bind(String.class).annotatedWith(Self.class).toInstance(Addressing.ofNetwork(Network.LOCALNET).forValidators().of(nodeKey.getPublicKey()).substring(0, 10));
bind(ECKeyOps.class).toInstance(ECKeyOps.fromKeyPair(nodeKey));
bind(Environment.class).toInstance(network.createSender(BFTNode.create(nodeKey.getPublicKey())));
bind(RuntimeProperties.class).toInstance(properties);
bind(Serialization.class).toInstance(DefaultSerialization.getInstance());
bind(DeterministicProcessor.class);
Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
bind(ForkConfig.class).annotatedWith(NewestForkConfig.class).toInstance(new FixedEpochForkConfig("genesis", null, 0L));
}
});
}
use of com.radixdlt.properties.RuntimeProperties in project radixdlt by radixdlt.
the class PendingOutboundChannelsManagerTest method pending_outbound_channels_manager_should_return_the_same_future_when_called_from_diff_threads.
/*
* Tests whether the PendingOutboundChannelsManager can be safely accessed from multiple threads by
* calling `connectTo` from two threads and ensuring that only a single outbound connection
* request was triggered, and a single CompletableFuture object was returned to both callers.
*/
@Test
public void pending_outbound_channels_manager_should_return_the_same_future_when_called_from_diff_threads() throws Exception {
final var executorService = Executors.newFixedThreadPool(2);
final var sut = new PendingOutboundChannelsManager(P2PConfig.fromRuntimeProperties(new RuntimeProperties(new JSONObject(), new String[] {})), mock(PeerOutboundBootstrap.class), rmock(ScheduledEventDispatcher.class), rmock(EventDispatcher.class));
final var remoteNodeId = NodeId.fromPublicKey(ECKeyPair.generateNew().getPublicKey());
final var remoteNodeUri = RadixNodeUri.fromPubKeyAndAddress(1, remoteNodeId.getPublicKey(), "127.0.0.1", 30000);
// in case of invalid concurrent access, but doesn't take too long in a happy scenario.
for (int i = 0; i < 200; i++) {
final var futureRef1 = new AtomicReference<CompletableFuture<PeerChannel>>();
final var futureRef2 = new AtomicReference<CompletableFuture<PeerChannel>>();
executorService.invokeAll(List.of(Executors.callable(() -> futureRef1.set(sut.connectTo(remoteNodeUri))), Executors.callable(() -> futureRef2.set(sut.connectTo(remoteNodeUri)))));
assertNotNull(futureRef1.get());
assertNotNull(futureRef2.get());
// Assert the exact same future object is returned
assertSame(futureRef1.get(), futureRef2.get());
// Callback to PendingOutboundChannelsManager with successful connection so that it clears
// pendingChannels
final var peerChannel = mock(PeerChannel.class);
when(peerChannel.getRemoteNodeId()).thenReturn(remoteNodeId);
sut.peerEventProcessor().process(new PeerEvent.PeerConnected(peerChannel));
// Just to make sure the Futures were completed
assertTrue(futureRef1.get().isDone());
assertTrue(futureRef2.get().isDone());
}
}
use of com.radixdlt.properties.RuntimeProperties in project radixdlt by radixdlt.
the class RuntimePropertiesHostIpTest method make.
private static RuntimePropertiesHostIp make(String value) {
RuntimeProperties properties = mock(RuntimeProperties.class);
when(properties.get(eq(RuntimePropertiesHostIp.HOST_IP_PROPERTY), any())).thenReturn(value);
return (RuntimePropertiesHostIp) RuntimePropertiesHostIp.create(properties);
}
Aggregations