Search in sources :

Example 1 with HostnamePort

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());
}
Also used : SecureSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection) SecureWebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection) SecureWebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection) WebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection) SocketConnection(org.neo4j.bolt.v1.transport.socket.client.SocketConnection) SecureWebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection) SecureSocketConnection(org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection) WebSocketConnection(org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection) HostnamePort(org.neo4j.helpers.HostnamePort) Test(org.junit.Test)

Example 2 with HostnamePort

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

the class SocketConnectionTest method shouldOnlyReadOnceIfAllBytesAreRead.

@Test
public void shouldOnlyReadOnceIfAllBytesAreRead() 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);
    SocketConnection connection = new SocketConnection(socket);
    connection.connect(new HostnamePort("my.domain", 1234));
    // WHEN
    connection.recv(4);
    // THEN
    verify(stream, times(1)).read(any(byte[].class), anyInt(), anyInt());
}
Also used : InputStream(java.io.InputStream) HostnamePort(org.neo4j.helpers.HostnamePort) Socket(java.net.Socket) Test(org.junit.Test)

Example 3 with HostnamePort

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

the class SocketConnectionTest method shouldOnlyReadUntilAllBytesAreRead.

@Test
public void shouldOnlyReadUntilAllBytesAreRead() 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(4).thenReturn(2).thenReturn(-1);
    SocketConnection connection = new SocketConnection(socket);
    connection.connect(new HostnamePort("my.domain", 1234));
    // WHEN
    connection.recv(10);
    // THEN
    verify(stream, times(3)).read(any(byte[].class), anyInt(), anyInt());
}
Also used : InputStream(java.io.InputStream) HostnamePort(org.neo4j.helpers.HostnamePort) Socket(java.net.Socket) Test(org.junit.Test)

Example 4 with HostnamePort

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

the class HighAvailabilitySlavesTest method shouldSupportConcurrentConsumptionOfSlaves.

@Test
public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception {
    // Given
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(clusterMembersOfSize(1000), mock(Cluster.class), new DefaultSlaveFactory(NullLogProvider.getInstance(), new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0));
    // When
    ExecutorService executor = Executors.newFixedThreadPool(5);
    for (int i = 0; i < 5; i++) {
        executor.submit(slavesConsumingRunnable(haSlaves));
    }
    executor.shutdown();
    executor.awaitTermination(30, SECONDS);
    // Then
    int slavesCount = 0;
    LifeSupport life = ReflectionUtil.getPrivateField(haSlaves, "life", LifeSupport.class);
    for (Lifecycle lifecycle : life.getLifecycleInstances()) {
        if (lifecycle instanceof Slave) {
            slavesCount++;
        }
    }
    // One instance is master
    assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount);
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Slave(org.neo4j.kernel.ha.com.master.Slave) Monitors(org.neo4j.kernel.monitoring.Monitors) ExecutorService(java.util.concurrent.ExecutorService) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 5 with HostnamePort

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

the class BackupProtocolTest method shouldGatherForensicsInFullBackupRequest.

private void shouldGatherForensicsInFullBackupRequest(boolean forensics) throws Exception {
    // GIVEN
    Response<Void> response = Response.EMPTY;
    StoreId storeId = response.getStoreId();
    String host = "localhost";
    int port = BackupServer.DEFAULT_PORT;
    LifeSupport life = new LifeSupport();
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
    BackupClient client = life.add(new BackupClient(host, port, null, NullLogProvider.getInstance(), storeId, 10_000, mock(ResponseUnpacker.class), mock(ByteCounterMonitor.class), mock(RequestMonitor.class), reader));
    ControlledBackupInterface backup = new ControlledBackupInterface();
    life.add(new BackupServer(backup, new HostnamePort(host, port), NullLogProvider.getInstance(), mock(ByteCounterMonitor.class), mock(RequestMonitor.class)));
    life.start();
    try {
        // WHEN
        StoreWriter writer = mock(StoreWriter.class);
        client.fullBackup(writer, forensics);
        // THEN
        assertEquals(forensics, backup.receivedForensics);
    } finally {
        life.shutdown();
    }
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) StoreId(org.neo4j.kernel.impl.store.StoreId) StoreWriter(org.neo4j.com.storecopy.StoreWriter) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)

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