Search in sources :

Example 16 with HostnamePort

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));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) Test(org.junit.Test)

Example 17 with HostnamePort

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;
}
Also used : TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) SocketConnection(org.neo4j.bolt.v1.transport.socket.client.SocketConnection) HostnamePort(org.neo4j.helpers.HostnamePort) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 18 with HostnamePort

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;
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) HostnamePort(org.neo4j.helpers.HostnamePort) RequestMonitor(org.neo4j.com.monitor.RequestMonitor)

Example 19 with HostnamePort

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
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostnamePort(org.neo4j.helpers.HostnamePort) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelException(org.jboss.netty.channel.ChannelException) Test(org.junit.Test)

Example 20 with HostnamePort

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());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostnamePort(org.neo4j.helpers.HostnamePort) Channel(org.jboss.netty.channel.Channel) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) 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