use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.
the class HaConfigurationValidatorTest method validateSuccess.
@Test
public void validateSuccess() throws Exception {
// when
Config config = Config.embeddedDefaults(stringMap(ClusterSettings.mode.name(), mode.name(), ClusterSettings.server_id.name(), "1", ClusterSettings.initial_hosts.name(), "localhost,remotehost"), Collections.singleton(new HaConfigurationValidator()));
// then
assertEquals(asList(new HostnamePort("localhost"), new HostnamePort("remotehost")), config.get(ClusterSettings.initial_hosts));
assertEquals(new InstanceId(1), config.get(ClusterSettings.server_id));
}
use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.
the class ProcedureInteractionTestBase method startBoltSession.
@SuppressWarnings("unchecked")
TransportConnection startBoltSession(String username, String password) throws Exception {
TransportConnection connection = new SocketConnection();
HostnamePort address = new HostnamePort("localhost:7687");
Map<String, Object> authToken = map("principal", username, "credentials", password, "scheme", "basic");
connection.connect(address).send(TransportTestUtil.acceptedVersions(1, 0, 0, 0)).send(TransportTestUtil.chunk(init("TestClient/1.1", authToken)));
assertThat(connection, eventuallyReceives(new byte[] { 0, 0, 0, 1 }));
assertThat(connection, eventuallyReceives(msgSuccess()));
return connection;
}
use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.
the class ServerTest method newServer.
private Server<Object, Object> newServer(final TxChecksumVerifier checksumVerifier) throws Throwable {
Server.Configuration conf = mock(Server.Configuration.class);
when(conf.getServerAddress()).thenReturn(new HostnamePort("aa", -1667));
Server<Object, Object> server = new Server<Object, Object>(null, conf, getInstance(), DEFAULT_FRAME_LENGTH, new ProtocolVersion((byte) 0, ProtocolVersion.INTERNAL_PROTOCOL_VERSION), checksumVerifier, Clocks.systemClock(), mock(ByteCounterMonitor.class), mock(RequestMonitor.class)) {
@Override
protected RequestType<Object> getRequestContext(byte id) {
return mock(RequestType.class);
}
@Override
protected void stopConversation(RequestContext context) {
}
};
server.init();
return server;
}
use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.
the class PortRangeSocketBinderTest method shouldReThrowExceptionIfCannotBindToPort.
@Test
public void shouldReThrowExceptionIfCannotBindToPort() {
// given
HostnamePort localhost = new HostnamePort("localhost", 9000);
ServerBootstrap bootstrap = mock(ServerBootstrap.class);
when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenThrow(new ChannelException());
try {
// when
new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
fail("should have thrown ChannelException");
} catch (ChannelException ignored) {
// expected
}
}
use of org.neo4j.helpers.HostnamePort in project neo4j by neo4j.
the class PortRangeSocketBinderTest method shouldReturnChannelAndSocketIfPortIsFree.
@Test
public void shouldReturnChannelAndSocketIfPortIsFree() {
// given
HostnamePort localhost = new HostnamePort("localhost", 9000);
ServerBootstrap bootstrap = mock(ServerBootstrap.class);
Channel channel = mock(Channel.class);
when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenReturn(channel);
// when
Connection connection = new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
//then
assertEquals(channel, connection.getChannel());
assertEquals(new InetSocketAddress("localhost", 9000), connection.getSocketAddress());
}
Aggregations