use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class TcpIpConnection_TransferStressBaseTest method testPackets.
private void testPackets(long verifyTimeoutInMillis) throws Exception {
TcpIpConnection c = connect(connManagerA, addressB);
WriteThread thread1 = new WriteThread(1, c);
WriteThread thread2 = new WriteThread(2, c);
logger.info("Starting");
thread1.start();
thread2.start();
sleepAndStop(stop, WRITER_THREAD_RUNNING_TIME_IN_SECONDS);
logger.info("Done");
thread1.assertSucceedsEventually();
thread2.assertSucceedsEventually();
// there is always one packet extra for the bind-request
final long expectedNormalPackets = thread1.normalPackets + thread2.normalPackets + 1;
final long expectedUrgentPackets = thread1.urgentPackets + thread2.urgentPackets;
logger.info("expected normal packets: " + expectedNormalPackets);
logger.info("expected priority packets: " + expectedUrgentPackets);
final SocketWriter writer = c.getSocketWriter();
final SocketReader reader = ((TcpIpConnection) connManagerB.getConnection(addressA)).getSocketReader();
long start = System.currentTimeMillis();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
logger.info("writer total frames pending : " + writer.totalFramesPending());
logger.info("writer last write time millis : " + writer.lastWriteTimeMillis());
logger.info("reader total frames handled : " + reader.getNormalFramesReadCounter().get() + reader.getPriorityFramesReadCounter().get());
logger.info("reader last read time millis : " + reader.lastReadTimeMillis());
assertEquals(expectedNormalPackets, reader.getNormalFramesReadCounter().get());
assertEquals(expectedUrgentPackets, reader.getPriorityFramesReadCounter().get());
}
}, verifyTimeoutInMillis);
logger.info("Waiting for pending packets to be sent and received finished in " + (System.currentTimeMillis() - start) + " milliseconds");
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class TcpIpConnectionManager_ConnectMemberBaseTest method destroyConnection_whenActive.
// ================== destroy ======================================================
@Test
public void destroyConnection_whenActive() throws Exception {
startAllConnectionManagers();
final TcpIpConnection connAB = connect(connManagerA, addressB);
final TcpIpConnection connBA = connect(connManagerB, addressA);
connAB.close(null, null);
assertIsDestroyed(connAB);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertIsDestroyed(connBA);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class TcpIpConnectionManager_ConnectionListenerTest method whenConnectionAdded.
@Test
public void whenConnectionAdded() throws Exception {
startAllConnectionManagers();
final ConnectionListener listener = mock(ConnectionListener.class);
connManagerA.addConnectionListener(listener);
final Connection c = connect(connManagerA, addressB);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
listener.connectionAdded(c);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class TcpIpConnectionManager_TransmitTest method withAddress_whenConnectionExists.
@Test
public void withAddress_whenConnectionExists() {
connManagerB.start();
final Packet packet = new Packet(serializationService.toBytes("foo"));
connect(connManagerA, addressB);
boolean result = connManagerA.transmit(packet, addressB);
assertTrue(result);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertContains(packetsB, packet);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class TcpIpConnection_AbstractTest method connect.
protected TcpIpConnection connect(final TcpIpConnectionManager connectionManager, final Address address) {
connectionManager.getOrConnect(address);
final AtomicReference<TcpIpConnection> ref = new AtomicReference<TcpIpConnection>();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Connection c = connectionManager.getConnection(address);
assertNotNull(c);
ref.set((TcpIpConnection) c);
}
});
return ref.get();
}
Aggregations