Search in sources :

Example 6 with RuntimeProperties

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());
}
Also used : RuntimeProperties(com.radixdlt.properties.RuntimeProperties) Test(org.junit.Test)

Example 7 with RuntimeProperties

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);
    }
}
Also used : JSONObject(org.json.JSONObject) ParseException(org.apache.commons.cli.ParseException) RuntimeProperties(com.radixdlt.properties.RuntimeProperties)

Example 8 with RuntimeProperties

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));
        }
    });
}
Also used : Key(com.google.inject.Key) DefaultSerialization(com.radixdlt.DefaultSerialization) DatabaseCacheSize(com.radixdlt.store.DatabaseCacheSize) DispatcherModule(com.radixdlt.modules.DispatcherModule) JSONObject(org.json.JSONObject) ForkConfig(com.radixdlt.statecomputer.forks.ForkConfig) PeerOutboundBootstrap(com.radixdlt.network.p2p.transport.PeerOutboundBootstrap) SystemCounters(com.radixdlt.counters.SystemCounters) DatabaseEnvironment(com.radixdlt.store.DatabaseEnvironment) Multibinder(com.google.inject.multibindings.Multibinder) Objects(java.util.Objects) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) P2PModule(com.radixdlt.network.p2p.P2PModule) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) ParseException(org.apache.commons.cli.ParseException) NetworkId(com.radixdlt.networks.NetworkId) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) IntStream(java.util.stream.IntStream) PeerManager(com.radixdlt.network.p2p.PeerManager) Serialization(com.radixdlt.serialization.Serialization) Modules(com.google.inject.util.Modules) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) ECPublicKey(com.radixdlt.crypto.ECPublicKey) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) ImmutableList(com.google.common.collect.ImmutableList) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule) AddressBook(com.radixdlt.network.p2p.addressbook.AddressBook) Addressing(com.radixdlt.networks.Addressing) NewestForkConfig(com.radixdlt.statecomputer.forks.NewestForkConfig) Network(com.radixdlt.networks.Network) ECKeyOps(com.radixdlt.crypto.ECKeyOps) Environment(com.radixdlt.environment.Environment) RadixNodeUri(com.radixdlt.network.p2p.RadixNodeUri) IOException(java.io.IOException) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Scopes(com.google.inject.Scopes) Injector(com.google.inject.Injector) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) P2PConfig(com.radixdlt.network.p2p.P2PConfig) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Self(com.radixdlt.hotstuff.bft.Self) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) TemporaryFolder(org.junit.rules.TemporaryFolder) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ForkConfig(com.radixdlt.statecomputer.forks.ForkConfig) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) NewestForkConfig(com.radixdlt.statecomputer.forks.NewestForkConfig) P2PConfig(com.radixdlt.network.p2p.P2PConfig) ECKeyPair(com.radixdlt.crypto.ECKeyPair) IOException(java.io.IOException) AbstractModule(com.google.inject.AbstractModule) JSONObject(org.json.JSONObject) ECPublicKey(com.radixdlt.crypto.ECPublicKey) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) DispatcherModule(com.radixdlt.modules.DispatcherModule) P2PModule(com.radixdlt.network.p2p.P2PModule) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule)

Example 9 with RuntimeProperties

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());
    }
}
Also used : PeerOutboundBootstrap(com.radixdlt.network.p2p.transport.PeerOutboundBootstrap) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventDispatcher(com.radixdlt.environment.EventDispatcher) JSONObject(org.json.JSONObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) PeerChannel(com.radixdlt.network.p2p.transport.PeerChannel) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) Test(org.junit.Test)

Example 10 with RuntimeProperties

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);
}
Also used : RuntimeProperties(com.radixdlt.properties.RuntimeProperties)

Aggregations

RuntimeProperties (com.radixdlt.properties.RuntimeProperties)13 JSONObject (org.json.JSONObject)5 Test (org.junit.Test)5 ParseException (org.apache.commons.cli.ParseException)4 AbstractModule (com.google.inject.AbstractModule)3 RadixNodeUri (com.radixdlt.network.p2p.RadixNodeUri)3 BerkeleyRecoverableProcessedTxnStore (com.radixdlt.api.core.reconstruction.BerkeleyRecoverableProcessedTxnStore)2 EventDispatcher (com.radixdlt.environment.EventDispatcher)2 ScheduledEventDispatcher (com.radixdlt.environment.ScheduledEventDispatcher)2 SingleNodeAndPeersDeterministicNetworkModule (com.radixdlt.modules.SingleNodeAndPeersDeterministicNetworkModule)2 PeerOutboundBootstrap (com.radixdlt.network.p2p.transport.PeerOutboundBootstrap)2 Before (org.junit.Before)2 ImmutableList (com.google.common.collect.ImmutableList)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Provides (com.google.inject.Provides)1 Scopes (com.google.inject.Scopes)1 Multibinder (com.google.inject.multibindings.Multibinder)1 Modules (com.google.inject.util.Modules)1