Search in sources :

Example 41 with AssertTask

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");
}
Also used : SocketReader(com.hazelcast.internal.networking.SocketReader) AssertTask(com.hazelcast.test.AssertTask) SocketWriter(com.hazelcast.internal.networking.SocketWriter)

Example 42 with AssertTask

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);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test)

Example 43 with AssertTask

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);
        }
    });
}
Also used : Connection(com.hazelcast.nio.Connection) AssertTask(com.hazelcast.test.AssertTask) ConnectionListener(com.hazelcast.nio.ConnectionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with AssertTask

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);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) UnknownHostException(java.net.UnknownHostException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with AssertTask

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();
}
Also used : Connection(com.hazelcast.nio.Connection) AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20