use of com.radixdlt.modules.DispatcherModule 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.modules.DispatcherModule in project radixdlt by radixdlt.
the class MempoolRunnerTest method createModule.
@SuppressWarnings(// The mock method doesn't support type-safe generics due to type erasure
"unchecked")
public Module createModule() {
return new AbstractModule() {
@Override
public void configure() {
bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.random());
bind(LedgerProof.class).annotatedWith(LastProof.class).toInstance(mock(LedgerProof.class));
bind(StateComputer.class).toInstance(stateComputer);
bind(SystemCounters.class).toInstance(new SystemCountersImpl());
bind(RxRemoteEnvironment.class).toInstance(new RxRemoteEnvironment() {
@Override
public <T> Flowable<RemoteEvent<T>> remoteEvents(Class<T> remoteEventClass) {
return Flowable.never();
}
});
bind(LedgerAccumulator.class).toInstance(mock(LedgerAccumulator.class));
bind(LedgerAccumulatorVerifier.class).toInstance(mock(LedgerAccumulatorVerifier.class));
bind(new TypeLiteral<Comparator<LedgerProof>>() {
}).toInstance(mock(Comparator.class));
bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
install(MempoolConfig.asModule(100, 10));
install(new MockedKeyModule());
install(new MockedCryptoModule());
install(new RxEnvironmentModule());
install(new DispatcherModule());
install(new MempoolReceiverModule());
install(new EventLoggerModule());
}
};
}
Aggregations