public static void assertCompletesEventually(final Future f) { assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { assertTrue("future has not completed", f.isDone()); } }); }
@Override public void run() { ExecutorTest test = (ExecutorTest) hz.getUserContext().get(getUserContextKeyFromTestId(testId)); test.executedCounter.incrementAndGet(); }
@Verify public void verify() { if (isClient) { return; } long putCount = putCounter.get(); long getCount = getCounter.get(); Map<Integer, Object> slowOperationLogs = getFieldValue(slowOperationDetector, "slowOperationLogs"); int expected = (int) (Math.min(putCount, 1) + Math.min(getCount, 1)); long operationCount = putCount + getCount; logger.info(format("Expecting %d slow operation logs after completing %d operations (%d put, %d get).", expected, operationCount, putCount, getCount)); assertNotNull("Could not retrieve slow operation logs", slowOperationLogs); assertEqualsStringFormat("Expected %d slow operation logs, but was %d", expected, slowOperationLogs.size()); assertTrue("Expected at least one completed operations, but was " + operationCount + ". Please run the test for a longer time!", operationCount > 0); }
@Setup public void setUp() { map = targetInstance.getMap(name); operationCounterList = targetInstance.getList(name + "OperationCounter"); mapOperationSelectorBuilder .addOperation(MapOperation.PUT, putProb) .addOperation(MapOperation.GET, getProb) .addOperation(MapOperation.CHECK_SIZE, checkProb); mapPutOperationSelectorBuilder .addOperation(MapPutOperation.PUT_ASYNC, putUsingAsyncProb) .addDefaultOperation(MapPutOperation.PUT_SYNC); if (isMemberNode(targetInstance)) { MaxSizeConfig maxSizeConfig = targetInstance.getConfig().getMapConfig(name).getMaxSizeConfig(); maxSizePerNode = maxSizeConfig.getSize(); assertEqualsStringFormat("Expected MaxSizePolicy %s, but was %s", PER_NODE, maxSizeConfig.getMaxSizePolicy()); assertTrue("Expected MaxSizePolicy.getSize() < Integer.MAX_VALUE", maxSizePerNode < Integer.MAX_VALUE); logger.info("MapSizeConfig of " + name + ": " + maxSizeConfig); } }
/** * Assert that a certain task is going to assert to true eventually. * * This method makes use of an exponential back-off mechanism. So initially it will ask frequently, but the * more times it fails the less frequent the task is going to be retried. * * Uses the default timeout of {@link #ASSERT_TRUE_EVENTUALLY_TIMEOUT} milliseconds. * * @param task AssertTask to execute * @throws NullPointerException if task is null. */ public static void assertTrueEventually(AssertTask task) { assertTrueEventually(task, ASSERT_TRUE_EVENTUALLY_TIMEOUT); }
@Setup public void setUp() { map = targetInstance.getMap(name); operationCounterList = targetInstance.getList(name + "OperationCounter"); mapOperationSelectorBuilder .addOperation(MapOperation.PUT, putProb) .addOperation(MapOperation.GET, getProb) .addOperation(MapOperation.CHECK_SIZE, checkProb); mapPutOperationSelectorBuilder .addOperation(MapPutOperation.PUT_ASYNC, putUsingAsyncProb) .addDefaultOperation(MapPutOperation.PUT_SYNC); if (isMemberNode(targetInstance)) { MaxSizeConfig maxSizeConfig = targetInstance.getConfig().getMapConfig(name).getMaxSizeConfig(); maxSizePerNode = maxSizeConfig.getSize(); assertEqualsStringFormat("Expected MaxSizePolicy %s, but was %s", PER_NODE, maxSizeConfig.getMaxSizePolicy()); assertTrue("Expected MaxSizePolicy.getSize() < Integer.MAX_VALUE", maxSizePerNode < Integer.MAX_VALUE); logger.info("MapSizeConfig of " + name + ": " + maxSizeConfig); } }
private void processCreateTest(CreateTestOperation operation) { LOGGER.info(operation.getTestCase().toString()); TestCase testCase = operation.getTestCase(); int testIndex = operation.getTestIndex(); WorkerConnector workerConnector = worker.getWorkerConnector(); if (workerConnector.getTest(testIndex) != null) { throw new IllegalStateException(format("Can't init TestCase: %s, another test with testIndex %d already exists", operation, testIndex)); } String testId = testCase.getId(); if (tests.containsKey(testId)) { throw new IllegalStateException(format("Can't init TestCase: %s, another test with testId [%s] already exists", operation, testId)); } LOGGER.info(format("%s Initializing test %s %s%n%s", DASHES, testId, DASHES, testCase)); TestContextImpl testContext = new TestContextImpl( hazelcastInstance, testId, worker.getPublicIpAddress(), workerConnector); TestContainer testContainer = new TestContainer(testContext, testCase); SimulatorAddress testAddress = workerAddress.getChild(testIndex); TestOperationProcessor processor = new TestOperationProcessor(worker, type, testContainer, testAddress); workerConnector.addTest(testIndex, processor); tests.put(testId, testContainer); if (type == WorkerType.MEMBER) { hazelcastInstance.getUserContext().put(getUserContextKeyFromTestId(testId), testContainer.getTestInstance()); } }
/** * Assert that a certain task is going to assert to true eventually. * <p> * This method makes use of an exponential back-off mechanism. So initially it will ask frequently, but the * more times it fails the less frequent the task is going to be retried. * <p> * Uses the default timeout of {@link #ASSERT_TRUE_EVENTUALLY_TIMEOUT} milliseconds. * * @param task AssertTask to execute * @throws NullPointerException if task is null. */ public static void assertTrueEventually(AssertTask task) { assertTrueEventually(task, ASSERT_TRUE_EVENTUALLY_TIMEOUT); }
@Verify(global = false) public void verify() { assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { long totalEntryCount = totalEntryCountOnNode(name, targetInstance); assertEquals("totalEntryCount=" + totalEntryCount, 0, totalEntryCount); } }, 600); }
@Verify(global = true) public void verify() { if (maxVerificationTimeSeconds < 0) { return; } final long expectedCount = totalExpectedCounter.get(); assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { long actualCount = 0; for (TopicListener topicListener : listeners) { actualCount += topicListener.count; } assertEquals("published messages don't match received messages", expectedCount, actualCount); } }, maxVerificationTimeSeconds); }
@Verify(global = true) public void verify() { final long expectedCount = listenersPerTopic * totalMessagesSend.get(); assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { long actualCount = 0; for (MessageListenerImpl topicListener : listeners) { actualCount += topicListener.received.get(); } assertEquals("published messages don't match received messages", expectedCount, actualCount); } }); assertEquals("Failures found", 0, failures.get()); } }
@Verify(global = true) public void globalVerify() { sleepSeconds(61); // provoke expire after TTL for (int i = 0; i < keyCount; i++) { cache.containsKey(i); } assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { int cacheSize = cache.size(); logger.info(name + " ICache size: " + cacheSize); assertEquals(name + " ICache should be empty, but TTL events are not processed", 0, cacheSize); } }); } }
@Verify public void globalVerify() { MapOperationCounter total = new MapOperationCounter(); for (MapOperationCounter counter : results) { total.add(counter); } logger.info(name + ": " + total + " total of " + results.size()); assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { assertEquals(name + ": Map should be empty, some TTL events are not processed", 0, map.size()); } }); } }
@Verify(global = false) public void localVerify() { MapOperationCounter total = new MapOperationCounter(); for (MapOperationCounter counter : results) { total.add(counter); } logger.info(name + ": " + total + " total of " + results.size()); assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { logger.info(name + ": " + "assert map Size = " + map.size()); assertEquals(name + ": Replicated Map should be empty, some TTL events are not processed", 0, map.size()); } }); } }
@Verify public void verify() { if (isClient(targetInstance)) { return; } final String serviceName = totalCounter.getServiceName(); final long expected = totalCounter.get(); // since the operations are asynchronous, we have no idea when they complete assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { // hack to prevent overloading the system with get calls, else it is done many times a second sleepSeconds(10); long actual = 0; for (DistributedObject distributedObject : targetInstance.getDistributedObjects()) { String key = distributedObject.getName(); if (serviceName.equals(distributedObject.getServiceName()) && key.startsWith(name)) { actual += targetInstance.getAtomicLong(key).get(); } } assertEquals(expected, actual); } }, assertEventuallySeconds); }
@Verify public void globalVerify() { MapOperationCounter total = new MapOperationCounter(); for (MapOperationCounter counter : results) { total.add(counter); } logger.info(name + ": " + total + " total of " + results.size()); assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { assertEquals(name + ": Map should be empty, some TTL events are not processed", 0, map.size()); } }); } }
logger.info(name + ": map store = " + mapStore); assertTrueEventually(new AssertTask() { @Override public void run() { assertTrueEventually(new AssertTask() { @Override public void run() {
logger.info(name + ": map store = " + mapStore); assertTrueEventually(new AssertTask() { @Override public void run() { assertTrueEventually(new AssertTask() { @Override public void run() {