Search in sources :

Example 71 with AssertTask

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

the class Invocation_TimeoutTest method async_whenLongRunningOperation.

@Test
public void async_whenLongRunningOperation() throws InterruptedException, ExecutionException, TimeoutException {
    long callTimeout = 5000;
    Config config = new Config().setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    OperationService opService = getOperationService(local);
    ICompletableFuture<Object> future = opService.invokeOnPartition(null, new SlowOperation(6 * callTimeout, RESPONSE), getPartitionId(remote));
    final ExecutionCallback<Object> callback = getExecutionCallbackMock();
    future.andThen(callback);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onResponse(RESPONSE);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with AssertTask

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

the class SecondsBasedEntryTaskSchedulerStressTest method test_postpone.

@Test
public void test_postpone() {
    final EntryStoringProcessor processor = new EntryStoringProcessor();
    final SecondsBasedEntryTaskScheduler<Integer, Integer> scheduler = new SecondsBasedEntryTaskScheduler<Integer, Integer>(executorService, processor, ScheduleType.POSTPONE);
    final int numberOfKeys = NUMBER_OF_THREADS;
    final Object[] locks = new Object[numberOfKeys];
    Arrays.fill(locks, new Object());
    final Map<Integer, Integer> latestValues = new ConcurrentHashMap<Integer, Integer>();
    for (int i = 0; i < NUMBER_OF_THREADS; i++) {
        final Thread thread = new Thread() {

            final Random random = new Random();

            @Override
            public void run() {
                for (int j = 0; j < NUMBER_OF_EVENTS_PER_THREAD; j++) {
                    int key = random.nextInt(numberOfKeys);
                    synchronized (locks[key]) {
                        if (scheduler.schedule(getDelayMillis(), key, j)) {
                            latestValues.put(key, j);
                        }
                    }
                }
            }

            private int getDelayMillis() {
                return random.nextInt(5000) + 1;
            }
        };
        thread.start();
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(latestValues.size(), processor.values.size());
            for (int key = 0; key < numberOfKeys; key++) {
                Integer expected = latestValues.get(key);
                Integer actual = processor.get(key);
                if (expected == null) {
                    assertNull(actual);
                } else {
                    assertEquals(expected, actual);
                }
            }
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Random(java.util.Random) AssertTask(com.hazelcast.test.AssertTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 73 with AssertTask

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

the class OverloadedConnectionsPluginTest method test.

@Test
public void test() {
    spawn(new Runnable() {

        @Override
        public void run() {
            IMap map = local.getMap("foo");
            while (!stop) {
                map.getAsync(remoteKey);
            }
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            plugin.run(logWriter);
            assertContains(GetOperation.class.getSimpleName() + " sampleCount=");
        }
    });
}
Also used : IMap(com.hazelcast.core.IMap) GetOperation(com.hazelcast.map.impl.operation.GetOperation) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 74 with AssertTask

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

the class PendingInvocationsPluginTest method testRun.

@Test
public void testRun() {
    spawn(new Runnable() {

        @Override
        public void run() {
            hz.getMap("foo").executeOnKey("bar", new SlowEntryProcessor());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            plugin.run(logWriter);
            assertContains("PendingInvocations[");
            assertContains("count=1");
            assertContains(EntryOperation.class.getName() + "=1");
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) EntryOperation(com.hazelcast.map.impl.operation.EntryOperation) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with AssertTask

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

the class SystemLogPluginTest method testLifecycle.

@Test
public void testLifecycle() {
    hz.shutdown();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            plugin.run(logWriter);
            assertContains("Lifecycle[" + LINE_SEPARATOR + "                          SHUTTING_DOWN]");
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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