Search in sources :

Example 26 with HostnamePort

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

the class HighAvailabilitySlavesTest method shouldNotReturnUnavailableSlaves.

@Test
public void shouldNotReturnUnavailableSlaves() {
    // given
    Cluster cluster = mock(Cluster.class);
    ClusterMembers clusterMembers = mock(ClusterMembers.class);
    when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID)));
    SlaveFactory slaveFactory = mock(SlaveFactory.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(0L));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) 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 27 with HostnamePort

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

the class SocketConnectionTest method shouldThrowIfNotEnoughBytesAreRead.

@Test
public void shouldThrowIfNotEnoughBytesAreRead() throws Exception {
    // GIVEN
    Socket socket = mock(Socket.class);
    InputStream stream = mock(InputStream.class);
    when(socket.getInputStream()).thenReturn(stream);
    when(stream.read(any(byte[].class), anyInt(), anyInt())).thenReturn(4).thenReturn(-1);
    SocketConnection connection = new SocketConnection(socket);
    connection.connect(new HostnamePort("my.domain", 1234));
    // EXPECT
    expectedException.expect(IOException.class);
    // WHEN
    connection.recv(10);
}
Also used : InputStream(java.io.InputStream) HostnamePort(org.neo4j.helpers.HostnamePort) Socket(java.net.Socket) Test(org.junit.Test)

Example 28 with HostnamePort

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

the class UdcKernelExtension method start.

@Override
public void start() throws Throwable {
    if (!config.get(UdcSettings.udc_enabled)) {
        return;
    }
    int firstDelay = config.get(UdcSettings.first_delay);
    int interval = config.get(UdcSettings.interval);
    HostnamePort hostAddress = config.get(UdcSettings.udc_host);
    UdcInformationCollector collector = new DefaultUdcInformationCollector(config, xadsm, idGeneratorFactory, startupStats, usageData);
    UdcTimerTask task = new UdcTimerTask(hostAddress, collector);
    timer.scheduleAtFixedRate(task, firstDelay, interval);
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort)

Example 29 with HostnamePort

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

the class PingerTest method shouldPingServer.

@Test
public void shouldPingServer() {
    final HostnamePort hostURL = new HostnamePort(hostname, server.getLocalPort());
    final Map<String, String> udcFields = new HashMap<String, String>();
    udcFields.put(ID, EXPECTED_STORE_ID);
    udcFields.put(UdcConstants.VERSION, EXPECTED_KERNEL_VERSION);
    Pinger p = new Pinger(hostURL, new TestUdcCollector(udcFields));
    Exception thrownException = null;
    try {
        p.ping();
    } catch (IOException e) {
        thrownException = e;
        e.printStackTrace();
    }
    assertThat(thrownException, nullValue());
    Map<String, String> actualQueryMap = handler.getQueryMap();
    assertThat(actualQueryMap, notNullValue());
    assertThat(actualQueryMap.get(ID), is(EXPECTED_STORE_ID));
}
Also used : HashMap(java.util.HashMap) HostnamePort(org.neo4j.helpers.HostnamePort) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with HostnamePort

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

the class PingerTest method shouldIncludePingCountInURI.

@Test
public void shouldIncludePingCountInURI() throws IOException {
    final int EXPECTED_PING_COUNT = 16;
    final HostnamePort hostURL = new HostnamePort(hostname, server.getLocalPort());
    final Map<String, String> udcFields = new HashMap<String, String>();
    Pinger p = new Pinger(hostURL, new TestUdcCollector(udcFields));
    for (int i = 0; i < EXPECTED_PING_COUNT; i++) {
        p.ping();
    }
    assertThat(p.getPingCount(), is(equalTo(EXPECTED_PING_COUNT)));
    Map<String, String> actualQueryMap = handler.getQueryMap();
    assertThat(actualQueryMap.get(UdcConstants.PING), is(Integer.toString(EXPECTED_PING_COUNT)));
}
Also used : HashMap(java.util.HashMap) HostnamePort(org.neo4j.helpers.HostnamePort) 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