Search in sources :

Example 21 with HostnamePort

use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.

the class BoltConfigIT method shouldSupportMultipleConnectors.

@Test
public void shouldSupportMultipleConnectors() throws Throwable {
    // Given
    // When
    // Then
    HostnamePort address0 = new HostnamePort("localhost:7888");
    assertConnectionAccepted(address0, new WebSocketConnection());
    assertConnectionAccepted(address0, new SecureWebSocketConnection());
    assertConnectionAccepted(address0, new SocketConnection());
    assertConnectionAccepted(address0, new SecureSocketConnection());
    HostnamePort address1 = new HostnamePort("localhost:7687");
    assertConnectionRejected(address1, new WebSocketConnection());
    assertConnectionAccepted(address1, new SecureWebSocketConnection());
    assertConnectionRejected(address1, new SocketConnection());
    assertConnectionAccepted(address1, new SecureSocketConnection());
}
Also used : SecureSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection) SecureWebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection) SecureWebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection) WebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection) SocketConnection(org.neo4j.bolt.v1.transport.socket.client.SocketConnection) SecureWebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection) SecureSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection) WebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection) HostnamePort(org.neo4j.helpers.HostnamePort) Test(org.junit.Test)

Example 22 with HostnamePort

use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.

the class NetworkedServerFactory method newNetworkedServer.

public ProtocolServer newNetworkedServer(final Config config, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider) {
    final NetworkReceiver receiver = new NetworkReceiver(networkReceiverMonitor, new NetworkReceiver.Configuration() {

        @Override
        public HostnamePort clusterServer() {
            return config.get(ClusterSettings.cluster_server);
        }

        @Override
        public int defaultPort() {
            return 5001;
        }

        @Override
        public String name() {
            return null;
        }
    }, logProvider);
    final NetworkSender sender = new NetworkSender(networkSenderMonitor, new NetworkSender.Configuration() {

        @Override
        public int defaultPort() {
            return 5001;
        }

        @Override
        public int port() {
            return config.get(ClusterSettings.cluster_server).getPort();
        }
    }, receiver, logProvider);
    ExecutorLifecycleAdapter stateMachineExecutor = new ExecutorLifecycleAdapter(() -> Executors.newSingleThreadExecutor(new NamedThreadFactory("State machine", namedThreadFactoryMonitor)));
    final ProtocolServer protocolServer = protocolServerFactory.newProtocolServer(config.get(ClusterSettings.server_id), timeoutStrategy, receiver, sender, acceptorInstanceStore, electionCredentialsProvider, stateMachineExecutor, objectInputStreamFactory, objectOutputStreamFactory, config);
    receiver.addNetworkChannelsListener(new NetworkReceiver.NetworkChannelsListener() {

        private StateTransitionLogger logger;

        @Override
        public void listeningAt(URI me) {
            protocolServer.listeningAt(me);
            if (logger == null) {
                logger = new StateTransitionLogger(logProvider, new AtomicBroadcastSerializer(objectInputStreamFactory, objectOutputStreamFactory));
                protocolServer.addStateTransitionListener(logger);
            }
        }

        @Override
        public void channelOpened(URI to) {
        }

        @Override
        public void channelClosed(URI to) {
        }
    });
    life.add(stateMachineExecutor);
    // Timeout timer - triggers every 10 ms
    life.add(new Lifecycle() {

        private ScheduledExecutorService scheduler;

        @Override
        public void init() throws Throwable {
            protocolServer.getTimeouts().tick(System.currentTimeMillis());
        }

        @Override
        public void start() throws Throwable {
            scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("timeout"));
            scheduler.scheduleWithFixedDelay(new Runnable() {

                @Override
                public void run() {
                    long now = System.currentTimeMillis();
                    protocolServer.getTimeouts().tick(now);
                }
            }, 0, 10, TimeUnit.MILLISECONDS);
        }

        @Override
        public void stop() throws Throwable {
            scheduler.shutdownNow();
        }

        @Override
        public void shutdown() throws Throwable {
        }
    });
    // Add this last to ensure that timeout service is setup first
    life.add(sender);
    life.add(receiver);
    return protocolServer;
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory) HostnamePort(org.neo4j.helpers.HostnamePort) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) URI(java.net.URI) NetworkReceiver(org.neo4j.cluster.com.NetworkReceiver) StateTransitionLogger(org.neo4j.cluster.statemachine.StateTransitionLogger) NetworkSender(org.neo4j.cluster.com.NetworkSender)

Example 23 with HostnamePort

use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldRegisterItselfOnMonitors.

@Test
public void shouldRegisterItselfOnMonitors() {
    // given
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    Cluster cluster = mock(Cluster.class);
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    // when
    new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0)).init();
    // then
    verify(cluster).addClusterListener(any(ClusterListener.class));
}
Also used : ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 24 with HostnamePort

use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldReturnAvailableAndAliveSlaves.

@Test
public void shouldReturnAvailableAndAliveSlaves() {
    // given
    Cluster cluster = mock(Cluster.class);
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID).availableAs(SLAVE, HA_URI, StoreId.DEFAULT)));
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    when(slaveFactory.newSlave(any(LifeSupport.class), any(ClusterMember.class), any(String.class), any(Integer.class))).thenReturn(mock(Slave.class));
    HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
    slaves.init();
    // when
    Iterable<Slave> memberSlaves = slaves.getSlaves();
    // then
    assertThat(count(memberSlaves), equalTo(1L));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 25 with HostnamePort

use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldClearSlavesWhenNewMasterElected.

@Test
public void shouldClearSlavesWhenNewMasterElected() {
    // given
    Cluster cluster = mock(Cluster.class);
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID).availableAs(SLAVE, HA_URI, StoreId.DEFAULT)));
    SlaveFactory slaveFactory = mock(SlaveFactory.class);
    when(slaveFactory.newSlave(any(LifeSupport.class), any(ClusterMember.class), any(String.class), any(Integer.class))).thenReturn(mock(Slave.class), mock(Slave.class));
    HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
    slaves.init();
    ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
    verify(cluster).addClusterListener(listener.capture());
    // when
    Slave slave1 = slaves.getSlaves().iterator().next();
    listener.getValue().elected(ClusterConfiguration.COORDINATOR, INSTANCE_ID, CLUSTER_URI);
    Slave slave2 = slaves.getSlaves().iterator().next();
    // then
    assertThat(slave2, not(sameInstance(slave1)));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Aggregations

HostnamePort (org.neo4j.helpers.HostnamePort)41 Test (org.junit.Test)29 File (java.io.File)9 Config (org.neo4j.kernel.configuration.Config)9 URI (java.net.URI)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)6 PrintStream (java.io.PrintStream)5 InetSocketAddress (java.net.InetSocketAddress)5 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DefaultSlaveFactory (org.neo4j.kernel.ha.com.master.DefaultSlaveFactory)5 HashMap (java.util.HashMap)4 SocketConnection (org.neo4j.bolt.v1.transport.socket.client.SocketConnection)4 SlaveFactory (org.neo4j.kernel.ha.com.master.SlaveFactory)4 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)4 InputStream (java.io.InputStream)3 Socket (java.net.Socket)3 Channel (org.jboss.netty.channel.Channel)3 ChannelException (org.jboss.netty.channel.ChannelException)3