Search in sources :

Example 6 with TestThread

use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.

the class CountDownLatchAdvancedTest method testLatchDestroyed.

@Test(expected = DistributedObjectDestroyedException.class)
public void testLatchDestroyed() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    final ICountDownLatch latch = hz1.getCountDownLatch("test");
    latch.trySetCount(2);
    new TestThread() {

        public void doRun() throws Exception {
            sleep(1000);
            latch.destroy();
        }
    }.start();
    hz2.getCountDownLatch("test").await(5, TimeUnit.SECONDS);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestThread(com.hazelcast.test.TestThread) ICountDownLatch(com.hazelcast.core.ICountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with TestThread

use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.

the class ConditionAbstractTest method startThreadWaitingOnCondition.

private TestThread startThreadWaitingOnCondition(final ILock lock, final ICondition condition, final CountDownLatch awaited, final CountDownLatch signalled) {
    TestThread t = new TestThread() {

        public void doRun() throws Exception {
            try {
                lock.lock();
                awaited.countDown();
                condition.await();
                signalled.countDown();
            } finally {
                lock.unlock();
            }
        }
    };
    t.start();
    return t;
}
Also used : TestThread(com.hazelcast.test.TestThread)

Aggregations

TestThread (com.hazelcast.test.TestThread)7 Test (org.junit.Test)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 ICountDownLatch (com.hazelcast.core.ICountDownLatch)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Config (com.hazelcast.config.Config)2 ListenerConfig (com.hazelcast.config.ListenerConfig)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 DistributedObjectDestroyedException (com.hazelcast.spi.exception.DistributedObjectDestroyedException)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1