@Test public void testPollOnEmpty() { final FIFOPriorityQueue<?> queue = new FIFOPriorityQueue<>(); assertNull(queue.poll()); }
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()); }
@Test public void testPollOnUnprioritizedSequence() { final FIFOPriorityQueue<PrioritizableInt> queue = new FIFOPriorityQueue<>(); queue.add(new PrioritizableInt(1)); queue.add(new PrioritizableInt(2)); queue.add(new PrioritizableInt(3)); assertEquals(1, queue.poll().getValue()); assertEquals(2, queue.poll().getValue()); assertEquals(3, queue.poll().getValue()); assertNull(queue.poll()); }
public void testIdleExpiryInPutIfAbsent() throws InterruptedException { Cache<String, String> cache = getCache(); long idleTime = EXPIRATION_TIMEOUT; assertNull(cache.putIfAbsent("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS)); assertEquals("v", cache.get("k")); timeService.advance(idleTime + 100); assertNull(cache.get("k")); cache.put("k", "v"); assertNotNull(cache.putIfAbsent("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS)); }
private void verifyShallowTrace(final Task<?> task) { final ShallowTrace trace = findPossiblyFusedTrace(task); assertEquals(task.getName(), trace.getName()); assertEquals(ResultType.fromTask(task), trace.getResultType()); assertNull(trace.getEndNanos()); } else { assertTrue(trace.getEndNanos() <= System.nanoTime()); assertTrue(trace.getEndNanos() > trace.getStartNanos()); assertNotNull(trace.getValue()); } else { assertNull(trace.getValue()); assertNull(trace.getValue());
@Test public void testFilter() { final boolean isClustered = cache(0).getCacheConfiguration().clustering().cacheMode().isClustered(); for (int i = 0; i < 10; ++i) { Person value = new Person(); value.setName("John"); value.setAge(i + 30); Cache<Object, Person> cache = cache(i % numNodes); Object key = isClustered ? new MagicKey(cache) : i; cache.put(key, value); } IckleFilterAndConverter filterAndConverter = new IckleFilterAndConverter<Object, Person>("from org.infinispan.query.test.Person where blurb is null and age <= 31", null, ReflectionMatcher.class); Stream<CacheEntry<Object, Object>> stream = cache(0).getAdvancedCache().cacheEntrySet().stream(); CloseableIterator<Map.Entry<Object, ObjectFilter.FilterResult>> iterator = Closeables.iterator(CacheFilters.filterAndConvert(stream, filterAndConverter).iterator()); Map<Object, ObjectFilter.FilterResult> results = mapFromIterator(iterator); assertEquals(2, results.size()); for (ObjectFilter.FilterResult p : results.values()) { assertNull(((Person) p.getInstance()).getBlurb()); assertTrue(((Person) p.getInstance()).getAge() <= 31); } }
@Test public void searchNonExistingShadowOwner() throws Exception { //searching owner for non existing shadow OperationResult result = new OperationResult("List owner"); PrismObject<FocusType> shadow = repositoryService.searchShadowOwner("12345", null, result); AssertJUnit.assertNull(shadow); result.computeStatus(); AssertJUnit.assertTrue(result.isSuccess()); }
@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); }
@SuppressWarnings("unchecked") @Override protected void assertNotInMemory(Object key, Object value) { DataContainer container = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry entry = container.get(key); CacheLoader<Object, Object> loader = TestingUtil.getFirstLoader(cache); assertNull("Key " + key + " exists in data container", entry); MarshalledEntry<Object, Object> entryLoaded = loader.load(key); assertNotNull("Key " + key + " does not exist in cache loader", entryLoaded); assertEquals("Wrong value for key " + key + " in cache loader", value, entryLoaded.getValue()); }
public void testIdleExpiryInReplace() throws InterruptedException { Cache<String, String> cache = getCache(); long idleTime = EXPIRATION_TIMEOUT; assertNull(cache.get("k")); assertNull(cache.replace("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS)); assertNull(cache.get("k")); cache.put("k", "v-old"); assertEquals("v-old", cache.get("k")); assertNotNull(cache.replace("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS)); assertEquals("v", cache.get("k")); timeService.advance(idleTime + 100); assertNull(cache.get("k")); cache.put("k", "v"); assertTrue(cache.replace("k", "v", "v2", -1, MILLISECONDS, idleTime, MILLISECONDS)); timeService.advance(idleTime + 100); assertNull(cache.get("k")); }
private void checkAndDisableStore(EmbeddedCacheManager cm, int count) { Cache<Object, Object> cache = cm.getCache(); PersistenceManager clm = TestingUtil.extractComponent(cache, PersistenceManager.class); Set<DummyInMemoryStore> stores = clm.getStores(DummyInMemoryStore.class); assertEquals(count, stores.size()); stores.forEach(store -> assertTrue(store.isRunning())); clm.disableStore(DummyInMemoryStore.class.getName()); stores.forEach(store -> assertFalse(store.isRunning())); AsyncInterceptor interceptor = cache.getAdvancedCache().getAsyncInterceptorChain() .findInterceptorExtending(CacheLoaderInterceptor.class); assertNull(interceptor); interceptor = cache.getAdvancedCache().getAsyncInterceptorChain() .findInterceptorExtending(CacheWriterInterceptor.class); assertNull(interceptor); }
public void testAtomicPutIfAbsentFromNonOwnerWithFlag(Method m) throws Exception { String key = k(m), value = "value"; String replaced = getFirstNonOwner(key).getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE).putIfAbsent(key, value); assertNull(replaced); //interesting case: fails to put as value exists, put actually missing in Store replaced = getFirstNonOwner(key).putIfAbsent(key, value); assertEquals(replaced, value); for (Cache<Object, String> c : caches) { assertEquals(replaced, c.get(key)); CacheLoader store = TestingUtil.getFirstLoader(c); assertFalse(store.contains(key)); } }
protected void assertCountConfiguredCapability(CountObjectsCapabilityType capCount) { CountObjectsSimulateType expectedCountSimulation = getCountSimulationMode(); if (expectedCountSimulation == null) { assertNull("Unexpected configured count capability", capCount); } else { assertNotNull("configured count capability not present", capCount); CountObjectsSimulateType simulate = capCount.getSimulate(); assertNotNull("simulate not present in configured count capability", simulate); assertEquals("Wrong similate in configured count capability", getCountSimulationMode(), simulate); } }
protected void byteArrayRemove( Map<byte[], byte[]> map, boolean expectRemove) { byte[] key = {1, 2, 3}; byte[] value = {4, 5, 6}; map.put(key, value); byte[] removeKey = {1, 2, 3}; // on purpose, different instance required if (expectRemove) assertTrue(String.format( "Expected key=%s to be removed", str(removeKey)), Arrays.equals(value, map.remove(removeKey))); else assertNull(map.get(removeKey)); }
private void expectCachedThenExpired(Integer key, String value) { // Check that it doesn't expire too early controlledTimeService.advance(EXPIRATION_TIMEOUT - 1); String v = this.<Integer, String>cache().get(key); assertEquals(value, v); // But not too late either controlledTimeService.advance(2); assertNull(cache.get(key)); } }
public void testExpirationLifespanInOps() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); for (int i = 0; i < SIZE; i++) { assertFalse(cache.containsKey("key-" + 1)); assertNull(cache.get("key-" + i)); assertNull(cache.remove("key-" + i)); } }
public void testSizeInExplicitTxWithModification() throws Exception { assertEquals(0, cache.size()); cache.put("k1", "v1"); TransactionManager tm = TestingUtil.getTransactionManager(cache); withTx(tm, () -> { assertNull(cache.put("k2", "v2")); assertEquals(2, cache.size()); tm.setRollbackOnly(); return null; }); }
public void testIdleExpiryInPutAll() throws InterruptedException { Cache<String, String> cache = getCache(); final long idleTime = EXPIRATION_TIMEOUT; Map<String, String> m = new HashMap<String, String>(); m.put("k1", "v"); m.put("k2", "v"); cache.putAll(m, -1, MILLISECONDS, idleTime, MILLISECONDS); assertEquals("v", cache.get("k1")); assertEquals("v", cache.get("k2")); timeService.advance(idleTime + 100); assertNull(cache.get("k1")); assertNull(cache.get("k2")); }
public void testRemoveAsync() throws Exception { c.put("k", "v"); assertEquals("v", c.get("k")); CompletableFuture<String> f = c.removeAsync("k"); assertFutureResult(f, "v"); assertNull(c.get("k")); }
@Test public void testPollOnUnprioritizedSequence() { final LIFOBiPriorityQueue<PrioritizableInt> queue = new LIFOBiPriorityQueue<>(); queue.add(new PrioritizableInt(1)); queue.add(new PrioritizableInt(2)); queue.add(new PrioritizableInt(3)); assertEquals(3, queue.poll().getValue()); assertEquals(2, queue.poll().getValue()); assertEquals(1, queue.poll().getValue()); assertNull(queue.poll()); }