Search in sources :

Example 1 with BeaconChainControllerFactory

use of tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory in project teku by ConsenSys.

the class TekuConfigurationTest method beaconChainControllerFactory_useCustomFactories.

@Test
void beaconChainControllerFactory_useCustomFactories() {
    AtomicBoolean customDiscoveryBuilderMethodCalled = new AtomicBoolean();
    AtomicBoolean customLibP2PBuilderMethodCalled = new AtomicBoolean();
    AtomicBoolean customGossipNetworkBuilderCalled = new AtomicBoolean();
    DiscoveryNetworkBuilder customDiscoveryNetworkBuilder = new DiscoveryNetworkBuilder() {

        @Override
        public DiscoveryNetwork<?> build() {
            customDiscoveryBuilderMethodCalled.set(true);
            return super.build();
        }
    };
    LibP2PGossipNetworkBuilder customGossipNetworkBuilder = new LibP2PGossipNetworkBuilder() {

        @Override
        public LibP2PGossipNetwork build() {
            customGossipNetworkBuilderCalled.set(true);
            return super.build();
        }
    };
    LibP2PNetworkBuilder customLibP2PNetworkBuilder = new LibP2PNetworkBuilder() {

        @Override
        public P2PNetwork<Peer> build() {
            customLibP2PBuilderMethodCalled.set(true);
            return super.build();
        }

        @Override
        protected LibP2PGossipNetworkBuilder createLibP2PGossipNetworkBuilder() {
            return customGossipNetworkBuilder;
        }
    };
    Eth2P2PNetworkBuilder customEth2P2PNetworkBuilder = new Eth2P2PNetworkBuilder() {

        @Override
        protected DiscoveryNetworkBuilder createDiscoveryNetworkBuilder() {
            return customDiscoveryNetworkBuilder;
        }

        @Override
        protected LibP2PNetworkBuilder createLibP2PNetworkBuilder() {
            return customLibP2PNetworkBuilder;
        }
    };
    BeaconChainControllerFactory customControllerFactory = (serviceConfig, beaconConfig) -> new BeaconChainController(serviceConfig, beaconConfig) {

        @Override
        protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() {
            return customEth2P2PNetworkBuilder;
        }
    };
    TekuConfiguration tekuConfiguration = TekuConfiguration.builder().data(b -> b.dataBasePath(tempDir)).beaconChainControllerFactory(customControllerFactory).build();
    try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) {
        assertThat(beaconNode).isNotNull();
        assertThat(customDiscoveryBuilderMethodCalled).isTrue();
        assertThat(customLibP2PBuilderMethodCalled).isTrue();
        assertThat(customGossipNetworkBuilderCalled).isTrue();
    }
}
Also used : TempDirUtils(tech.pegasys.teku.cli.TempDirUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoveryNetwork(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetwork) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryNetworkBuilder(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetworkBuilder) LibP2PNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNetworkBuilder) BeaconChainController(tech.pegasys.teku.services.beaconchain.BeaconChainController) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) BeaconChainControllerFactory(tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory) LibP2PGossipNetwork(tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetwork) P2PNetwork(tech.pegasys.teku.networking.p2p.network.P2PNetwork) LibP2PGossipNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder) BeaconNodeFacade(tech.pegasys.teku.BeaconNodeFacade) TekuFacade(tech.pegasys.teku.TekuFacade) Path(java.nio.file.Path) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryNetworkBuilder(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetworkBuilder) BeaconChainControllerFactory(tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder) LibP2PGossipNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder) Peer(tech.pegasys.teku.networking.p2p.peer.Peer) BeaconChainController(tech.pegasys.teku.services.beaconchain.BeaconChainController) BeaconNodeFacade(tech.pegasys.teku.BeaconNodeFacade) LibP2PNetworkBuilder(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNetworkBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Test (org.junit.jupiter.api.Test)1 BeaconNodeFacade (tech.pegasys.teku.BeaconNodeFacade)1 TekuFacade (tech.pegasys.teku.TekuFacade)1 TempDirUtils (tech.pegasys.teku.cli.TempDirUtils)1 Eth2P2PNetworkBuilder (tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder)1 DiscoveryNetwork (tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetwork)1 DiscoveryNetworkBuilder (tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetworkBuilder)1 LibP2PNetworkBuilder (tech.pegasys.teku.networking.p2p.libp2p.LibP2PNetworkBuilder)1 LibP2PGossipNetwork (tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetwork)1 LibP2PGossipNetworkBuilder (tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder)1 P2PNetwork (tech.pegasys.teku.networking.p2p.network.P2PNetwork)1 Peer (tech.pegasys.teku.networking.p2p.peer.Peer)1 BeaconChainController (tech.pegasys.teku.services.beaconchain.BeaconChainController)1 BeaconChainControllerFactory (tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory)1