Search in sources :

Example 1 with TestThread

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

the class CountDownLatchAbstractTest method testAwait.

@Test(timeout = 15000)
public void testAwait() throws InterruptedException {
    latch.trySetCount(1);
    TestThread thread = new TestThread() {

        public void doRun() {
            latch.countDown();
        }
    };
    thread.start();
    assertOpenEventually(latch);
}
Also used : TestThread(com.hazelcast.test.TestThread) Test(org.junit.Test)

Example 2 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)

Example 3 with TestThread

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

the class QueueAdvancedTest method testPutInterruption.

@Test
public void testPutInterruption() {
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "10000");
    config.getQueueConfig("default").setMaxSize(1);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IQueue<String> queue = instance.getQueue(randomName());
    assertTrue("Expected queue.offer() to succeed", queue.offer("item"));
    final CountDownLatch putLatch = new CountDownLatch(1);
    TestThread thread = new TestThread() {

        @Override
        public void doRun() throws Throwable {
            putLatch.countDown();
            queue.put("item");
        }
    };
    thread.start();
    assertOpenEventually(putLatch);
    thread.interrupt();
    thread.assertFailsEventually(InterruptedException.class);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestThread(com.hazelcast.test.TestThread) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with TestThread

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

the class QueueAdvancedTest method testTakeInterruption.

@Test
public void testTakeInterruption() {
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "10000");
    HazelcastInstance instance = createHazelcastInstance(config);
    final IQueue<Thread> queue = instance.getQueue(randomName());
    final CountDownLatch takeLatch = new CountDownLatch(1);
    TestThread thread = new TestThread() {

        @Override
        public void doRun() throws Throwable {
            takeLatch.countDown();
            queue.take();
        }
    };
    thread.start();
    assertOpenEventually(takeLatch);
    thread.interrupt();
    thread.assertFailsEventually(InterruptedException.class);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestThread(com.hazelcast.test.TestThread) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) TestThread(com.hazelcast.test.TestThread) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with TestThread

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

the class CountDownLatchAbstractTest method testAwait_withManyThreads.

@Test(timeout = 15000)
public void testAwait_withManyThreads() {
    final CountDownLatch completedLatch = new CountDownLatch(10);
    latch.trySetCount(1);
    for (int i = 0; i < 10; i++) {
        new TestThread() {

            public void doRun() throws Exception {
                if (latch.await(1, TimeUnit.MINUTES)) {
                    completedLatch.countDown();
                }
            }
        }.start();
    }
    latch.countDown();
    assertOpenEventually(completedLatch);
}
Also used : TestThread(com.hazelcast.test.TestThread) CountDownLatch(java.util.concurrent.CountDownLatch) ICountDownLatch(com.hazelcast.core.ICountDownLatch) Test(org.junit.Test)

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