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());
}
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;
}
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));
}
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));
}
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)));
}
Aggregations