@Test public void testShutdownWithNoTasks() throws InterruptedException { _engine.shutdown(); assertTrue(_engine.isShutdown()); assertTrue(_engine.awaitTermination(50, TimeUnit.MILLISECONDS)); assertTrue(_engine.isTerminated()); assertTrue(_engine.isShutdown()); }
@Test public void canGet() { MaryConfig m = MaryConfig.getLanguageConfig(LUXEMBOURGISH); assertNotNull(m); assertTrue(((LanguageConfig) m).getLocales().contains(LUXEMBOURGISH)); }
@Test public void testTimeBoundedTryRunWithinCapacity() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(0); Task<?>[] tasks = new Task<?>[10]; for (int i = 0; i < 10; i++) { tasks[i] = Task.action(counter::incrementAndGet); } for (int i = 0; i < 10; i++) { assertTrue(_engine.tryRun(tasks[i], 10, TimeUnit.MILLISECONDS)); } assertTrue(awaitAll(tasks)); assertEquals(10, counter.get()); }
@Test public void testValue() { final String value = "value"; final Promise<String> promise = Promises.value(value); assertTrue(promise.isDone()); assertFalse(promise.isFailed()); assertEquals(value, promise.get()); }
public void testObjAllMatch() { Cache<Integer, String> cache = getCache(0); int range = 10; // First populate the cache with a bunch of values IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value")); assertEquals(range, cache.size()); CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet(); assertTrue(createStream(entrySet).allMatch(e -> e.getValue().endsWith("-value"))); assertFalse(createStream(entrySet).allMatch(e -> e.getKey() % 2 == 0)); assertTrue(createStream(entrySet).allMatch(e -> e.getKey() < 10 && e.getKey() >= 0)); assertTrue(createStream(entrySet).allMatch(e -> e.getKey().toString().equals(e.getValue().substring(0, 1)))); }
@Test public void notWellFormed() throws Exception { System.out.println("\n===[ notWellFormed ]====="); OperationResult result = new OperationResult(this.getClass().getName()+".notWellFormed"); validateFile("not-well-formed.xml",result); System.out.println(result.debugDump()); AssertJUnit.assertFalse(result.isSuccess()); AssertJUnit.assertTrue(result.getMessage().contains("Unexpected close tag")); // Check if line number is in the error AssertJUnit.assertTrue("Line number not found in error message", result.getMessage().contains("35")); }
private void checkClusterRestartedCorrectly(Map<JGroupsAddress, PersistentUUID> addressMappings) throws Exception { Iterator<Map.Entry<JGroupsAddress, PersistentUUID>> addressIterator = addressMappings.entrySet().iterator(); for (int i = 0; i < cacheManagers.size(); i++) { LocalTopologyManager ltm = TestingUtil.extractGlobalComponent(manager(i), LocalTopologyManager.class); // Ensure that nodes have the old UUID assertEquals(addressIterator.next().getValue(), ltm.getPersistentUUID()); // Ensure that rebalancing is enabled for the cache assertTrue(ltm.isCacheRebalancingEnabled(cache(0).getName())); } }
@Test public void testSearchFocus() throws SchemaException { OperationResult result = new OperationResult("search"); List<PrismObject<FocusType>> objects = repositoryService.searchObjects(FocusType.class, null, null, result); result.recomputeStatus(); assertSuccess(result); System.out.println("Objects found: " + objects); for (PrismObject<?> object : objects) { assertTrue("returned object is not a FocusType: " + object, object.asObjectable() instanceof FocusType); } }
@Test public void testCancelAfterCancel() { final Task<?> task = TestUtil.noop(); final Exception reason1 = new Exception(); final Exception reason2 = new Exception(); assertTrue(task.cancel(reason1)); assertFalse(task.cancel(reason2)); assertCancelled(task, reason1); }
@Test(dependsOnMethods="testJmxOperations") public void testCacheMBeanUnregisterOnRemove() throws Exception { cacheManager.defineConfiguration("test", new ConfigurationBuilder().build()); assertNotNull(cacheManager.getCache("test")); ObjectName cacheMBean = getCacheObjectName(JMX_DOMAIN, "test(local)"); assertTrue(existsObject(cacheMBean)); cacheManager.administration().removeCache("test"); assertFalse(existsObject(cacheMBean)); }
@SuppressWarnings("unchecked") @Override protected void initializeKeyAndCheckData(Object key, Object value) { assertTrue("A cache store should be configured!", cache.getCacheConfiguration().persistence().usingStores()); cache.put(key, value); DataContainer container = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry entry = container.get(key); CacheLoader<Object, Object> loader = TestingUtil.getFirstLoader(cache); assertNotNull("Key " + key + " does not exist in data container.", entry); assertEquals("Wrong value for key " + key + " in data container.", value, entry.getValue()); MarshalledEntry<Object, Object> entryLoaded = loader.load(key); assertNull("Key " + key + " exists in cache loader.", entryLoaded); }
private <T> void assertDone(final Task<T> task, final T expectedValue) { assertTrue(task.isDone()); assertFalse(task.isFailed()); assertEquals(expectedValue, task.get()); assertNull(task.getError()); assertTrue(task.getShallowTrace().getStartNanos() > 0); assertTrue(task.getShallowTrace().getStartNanos() <= task.getShallowTrace().getEndNanos()); }
public void testPutAsyncWithVersion() throws Exception { final Integer key = 4; NumericVersion version = new NumericVersion(1); Future<String> f = advCache.putAsync(key, "v1", withVersion(version)); assertNotNull(f); assertFalse(f.isCancelled()); assertNull(f.get()); assertTrue(f.isDone()); CacheEntry entry = advCache.getCacheEntry(key); assertEquals("v1", entry.getValue()); assertEquals(EQUAL, version.compareTo(entry.getMetadata().version())); }
private void verifyShallowTrace(final Task<?> task) { final ShallowTrace trace = findPossiblyFusedTrace(task); assertEquals(task.getName(), trace.getName()); assertEquals(ResultType.fromTask(task), trace.getResultType()); } else { assertTrue(trace.getEndNanos() <= System.nanoTime()); assertTrue(trace.getEndNanos() > trace.getStartNanos()); assertNotNull(trace.getValue()); } else { assertNull(trace.getValue());
private void assertRunOrPending(final Task<?> task) { assertFalse(task.isDone()); assertFalse(task.isFailed()); assertTrue(task.getShallowTrace().getStartNanos() > 0); assertNotNull(task.getShallowTrace().getEndNanos()); try { task.get(); fail("Should have thrown PromiseUnresolvedException"); } catch (PromiseUnresolvedException e) { // Expected case } try { task.getError(); fail("Should have thrown PromiseUnresolvedException"); } catch (PromiseUnresolvedException e) { // Expected case } }
private void checkRelease(ConnectionSemaphore semaphore) throws IOException { semaphore.acquireChannelLock(PK); boolean tooManyCaught = false; try { semaphore.acquireChannelLock(PK); } catch (TooManyConnectionsException | TooManyConnectionsPerHostException e) { tooManyCaught = true; } assertTrue(tooManyCaught); tooManyCaught = false; semaphore.releaseChannelLock(PK); try { semaphore.acquireChannelLock(PK); } catch (TooManyConnectionsException | TooManyConnectionsPerHostException e) { tooManyCaught = true; } assertFalse(tooManyCaught); }
@Test public void testShutdownWithRunningTask() throws InterruptedException { final CountDownLatch finishLatch = new CountDownLatch(1); final String taskValue = "task executed"; final Task<String> task = new BaseTask<String>() { @Override protected Promise<? extends String> run(final Context context) throws Exception { finishLatch.await(); return Promises.value(taskValue); } }; _engine.run(task); _engine.shutdown(); // shutdown should not complete until after our task is done assertFalse(_engine.awaitTermination(50, TimeUnit.MILLISECONDS)); assertTrue(_engine.isShutdown()); assertFalse(_engine.isTerminated()); finishLatch.countDown(); assertTrue(_engine.awaitTermination(50, TimeUnit.MILLISECONDS)); assertTrue(_engine.isShutdown()); assertTrue(_engine.isTerminated()); // Task should finish shortly assertTrue(task.await(50, TimeUnit.MILLISECONDS)); assertEquals(taskValue, task.get()); }
public void testObjAnyMatch() { Cache<Integer, String> cache = getCache(0); int range = 10; // First populate the cache with a bunch of values IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value")); assertEquals(range, cache.size()); CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet(); assertTrue(createStream(entrySet).anyMatch(e -> e.getValue().endsWith("-value"))); assertTrue(createStream(entrySet).anyMatch(e -> e.getKey() % 2 == 0)); assertTrue(createStream(entrySet).anyMatch(e -> e.getKey() < 10 && e.getKey() >= 0)); assertTrue(createStream(entrySet).anyMatch(e -> e.getValue().equals("4-value"))); assertFalse(createStream(entrySet).anyMatch(e -> e.getKey() > 12)); }
@Test public void undeclaredPrefix() throws Exception { System.out.println("\n===[ undeclaredPrefix ]====="); OperationResult result = new OperationResult(this.getClass().getName()+".undeclaredPrefix"); validateFile("undeclared-prefix.xml",result); System.out.println(result.debugDump()); AssertJUnit.assertFalse(result.isSuccess()); AssertJUnit.assertTrue(result.getMessage().contains("Undeclared namespace prefix")); // Check if line number is in the error AssertJUnit.assertTrue("Line number not found in error message", result.getMessage().contains("37")); }
@Test public void testSearchAssignmentHolder() throws SchemaException { OperationResult result = new OperationResult("search"); List<PrismObject<AssignmentHolderType>> objects = repositoryService.searchObjects(AssignmentHolderType.class, null, null, result); result.recomputeStatus(); assertSuccess(result); System.out.println("Objects found: " + objects); for (PrismObject<?> object : objects) { assertTrue("returned object is not a AssignmentHolderType: " + object, object.asObjectable() instanceof AssignmentHolderType); } } }