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());
}
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());
}
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());
}
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);
}
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();
}
}
Aggregations