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);
}
});
}
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);
}
}
}
});
}
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=");
}
});
}
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");
}
});
}
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]");
}
});
}
Aggregations