Search in sources :

Example 31 with HostnamePort

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

the class PingerTest method crashPingSequenceShouldBeMinusOneThenTwoThenThreeEtc.

@Test
public void crashPingSequenceShouldBeMinusOneThenTwoThenThreeEtc() throws Exception {
    int[] expectedSequence = { -1, 2, 3, 4 };
    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).withCrash());
    for (int i = 0; i < expectedSequence.length; i++) {
        p.ping();
        int count = Integer.parseInt(handler.getQueryMap().get(UdcConstants.PING));
        assertEquals(expectedSequence[i], count);
    }
}
Also used : HashMap(java.util.HashMap) HostnamePort(org.neo4j.helpers.HostnamePort) Test(org.junit.Test)

Example 32 with HostnamePort

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

the class BackupToolIT method oldIncompatibleBackupsThrows.

@Test
public void oldIncompatibleBackupsThrows() throws Exception {
    // Prepare an "old" backup
    prepareNeoStoreFile(StandardV2_3.STORE_VERSION);
    // Start database to backup
    dbRule.getGraphDatabaseAPI();
    expected.expect(BackupTool.ToolFailureException.class);
    expected.expectMessage("Failed to perform backup because existing backup is from a different version.");
    // Perform backup
    backupTool.executeBackup(new HostnamePort("localhost", 6362), backupDir.toFile(), ConsistencyCheck.NONE, Config.defaults(), 20L * 60L * 1000L, false);
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) Test(org.junit.Test)

Example 33 with HostnamePort

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

the class BackupToolTest method shouldIgnoreIncrementalFlag.

@Test
public void shouldIgnoreIncrementalFlag() throws Exception {
    String[] args = new String[] { "-incremental", "-host", "localhost", "-to", "my_backup" };
    BackupService service = mock(BackupService.class);
    PrintStream systemOut = mock(PrintStream.class);
    // when
    new BackupTool(service, systemOut).run(args);
    // then
    verify(service).doIncrementalBackupOrFallbackToFull(eq("localhost"), eq(BackupServer.DEFAULT_PORT), eq(new File("my_backup")), eq(ConsistencyCheck.FULL), any(Config.class), eq(BackupClient.BIG_READ_TIMEOUT), eq(false));
    verify(systemOut).println("Performing backup from '" + new HostnamePort("localhost", BackupServer.DEFAULT_PORT) + "'");
    verify(systemOut).println("Done");
}
Also used : PrintStream(java.io.PrintStream) Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 34 with HostnamePort

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

the class PortRangeSocketBinderTest method shouldReturnChannelAndSocketIfAnyPortsAreFree.

@Test
public void shouldReturnChannelAndSocketIfAnyPortsAreFree() {
    // given
    HostnamePort localhost = new HostnamePort("localhost", 9000, 9001);
    ServerBootstrap bootstrap = mock(ServerBootstrap.class);
    Channel channel = mock(Channel.class);
    when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenThrow(new ChannelException());
    when(bootstrap.bind(new InetSocketAddress("localhost", 9001))).thenReturn(channel);
    // when
    Connection connection = new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
    //then
    assertEquals(channel, connection.getChannel());
    assertEquals(new InetSocketAddress(localhost.getHost(), 9001), 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) ChannelException(org.jboss.netty.channel.ChannelException) Test(org.junit.Test)

Example 35 with HostnamePort

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

the class PortRangeSocketBinderTest method shouldReThrowExceptionIfCannotBindToAnyOfThePortsInTheRange.

@Test
public void shouldReThrowExceptionIfCannotBindToAnyOfThePortsInTheRange() {
    // given
    HostnamePort localhost = new HostnamePort("localhost", 9000, 9002);
    ServerBootstrap bootstrap = mock(ServerBootstrap.class);
    when(bootstrap.bind(new InetSocketAddress("localhost", 9000))).thenThrow(new ChannelException("Failed to bind to: 9000"));
    when(bootstrap.bind(new InetSocketAddress("localhost", 9001))).thenThrow(new ChannelException("Failed to bind to: 9001"));
    when(bootstrap.bind(new InetSocketAddress("localhost", 9002))).thenThrow(new ChannelException("Failed to bind to: 9002"));
    try {
        // when
        new PortRangeSocketBinder(bootstrap).bindToFirstAvailablePortInRange(localhost);
        fail("should have thrown ChannelException");
    } catch (ChannelException ex) {
        // expected
        assertEquals(2, suppressedExceptions(ex));
    }
}
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)

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