@Test public void test1InitialState() { int count = dao.getCount(TEST_NAME); assertEquals("New TestEntity should have count=0.", 0, count); }
/** * Asserts that an object is null. If it is not * an AssertionFailedError is thrown with the given message. */ static public void assertNull(String message, Object object) { assertTrue(message, object == null); }
/** * Asserts that a condition is false. If it isn't it throws * an AssertionFailedError. */ static public void assertFalse(boolean condition) { assertFalse(null, condition); }
static public void assertEquals(final String message, final byte[] expected, final byte[] actual) { if(expected == actual) { return; } if(null == expected) { fail("expected a null array, but not null found. " + message); } if(null == actual) { fail("expected not null array, but null found. " + message); } assertEquals("arrays don't have the same size. " + message, expected.length, actual.length); for(int i= 0; i < expected.length; i++) { if(expected[i] != actual[i]) { fail("arrays differ firstly at element [" + i +"]; " + format(message, expected[i], actual[i])); } } }
@Test public void testAffinityPartitioner() throws Exception { Cache<AffinityKey, String> cache = cacheManagers.get(0).getCache(); IntStream.range(0, 10).boxed().forEach(num -> cache.put(new AffinityKey(num), "value")); addClusterEnabledCacheManager(getConfigurationBuilder()); waitForClusterToForm(); cacheManagers.stream().map(cm -> cm.getCache().getAdvancedCache()).forEach(advancedCache -> { LocalizedCacheTopology cacheTopology = advancedCache.getDistributionManager().getCacheTopology(); advancedCache.getDataContainer().keySet().forEach(key -> { int keySegmentId = ((AffinityKey) key).segmentId; assertEquals(cacheTopology.getSegment(key), keySegmentId); }); }); }
public void testIntNoneMatch() { 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(); // This isn't the best usage of this, but should be a usable example assertFalse(createStream(entrySet).mapToInt(toInt).noneMatch(i -> i % 2 == 0)); assertTrue(createStream(entrySet).mapToInt(toInt).noneMatch(i -> i > 10 && i < 0)); assertFalse(createStream(entrySet).mapToInt(toInt).noneMatch(i -> i < 12)); }
private void checkAcquireTime(ConnectionSemaphore semaphore) { List<SemaphoreRunner> runners = IntStream.range(0, CHECK_ACQUIRE_TIME__PERMITS * 2) .mapToObj(i -> new SemaphoreRunner(semaphore, PK)) .collect(Collectors.toList()); long acquireStartTime = System.currentTimeMillis(); runners.forEach(SemaphoreRunner::acquire); runners.forEach(SemaphoreRunner::await); long timeToAcquire = System.currentTimeMillis() - acquireStartTime; assertTrue("Semaphore acquired too soon: " + timeToAcquire+" ms",timeToAcquire >= (CHECK_ACQUIRE_TIME__TIMEOUT - 50)); //Lower Bound assertTrue("Semaphore acquired too late: " + timeToAcquire+" ms",timeToAcquire <= (CHECK_ACQUIRE_TIME__TIMEOUT + 300)); //Upper Bound }
private void testLongOperation(Supplier<Long> longSupplier, Cache<Long, String> cache) { int range = 10; // First populate the cache with a bunch of values LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value")); assertEquals(range, cache.size()); assertEquals((range - 1) * (range / 2), longSupplier.get().longValue()); }
public void testCancelAndGet() throws Exception { DistributedExecutorService des = createDES(getCache()); List<Address> cacheMembers = getCache().getAdvancedCache().getRpcManager().getMembers(); List<Address> members = new ArrayList<>(cacheMembers); assertEquals(caches(cacheName()).size(), members.size()); members.remove(getCache().getAdvancedCache().getRpcManager().getAddress()); DistributedTaskBuilder<Integer> tb = des.createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); final Future<Integer> future = des.submit(members.get(0),tb.build()); future.cancel(true); expectException(CancellationException.class, () -> future.get()); latchHolder.get().open(); }
@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()); }
@Test public void testSharedCacheStoreAfterInvalidation() { assertNull(cache(0, cacheName).get(key)); cache(0, cacheName).put(key, value); assertEquals(value, cache(1, cacheName).get(key)); cache(1, cacheName).put(key, changedValue); assertFalse(cache(0, cacheName).getAdvancedCache().getDataContainer().containsKey(key)); assertEquals(changedValue, cache(0, cacheName).get(key)); } }
@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 public void testPollOnEmpty() { final FIFOPriorityQueue<?> queue = new FIFOPriorityQueue<>(); assertNull(queue.poll()); }
@Test public void testL1UpdatedBeforeRemoveCommits() throws Exception { final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key); final Cache<Object, String> ownerCache = getFirstOwner(key); ownerCache.put(key, firstValue); assertIsNotInL1(nonOwnerCache, key); nonOwnerCache.getAdvancedCache().getTransactionManager().begin(); assertEquals(firstValue, nonOwnerCache.remove(key)); InternalCacheEntry ice = nonOwnerCache.getAdvancedCache().getDataContainer().get(key); assertNotNull(ice); assertEquals(firstValue, ice.getValue()); // Commit the put which should now update nonOwnerCache.getAdvancedCache().getTransactionManager().commit(); assertIsNotInL1(nonOwnerCache, key); }
@Test public void testSetErrorAndGetError() { final SettablePromise<String> promise = Promises.settable(); final Exception error = new Exception(); promise.fail(error); assertEquals(error, promise.getError()); assertTrue(promise.isDone()); assertTrue(promise.isFailed()); }
@Test public void testRestoreTransactionalAtomicMap(final Method m) throws Exception { cacheManager.defineConfiguration(m.getName(), configureCacheLoader(null, false).build()); Cache<String, Object> cache = cacheManager.getCache(m.getName()); TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); tm.begin(); final AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, m.getName()); map.put("a", "b"); tm.commit(); //evict from memory cache.evict(m.getName()); // now re-retrieve the map and make sure we see the diffs assertEquals("b", AtomicMapLookup.getAtomicMap(cache, m.getName()).get("a")); }
@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()); }
@Test(groups = {"group1"}) public void service() { assertNotNull(null); } }
@Test(dataProvider = "owningModeAndReadMethod") public void testReadsAfterMods(boolean isOwner, ReadMethod method) throws Exception { Object KEY = getKey(isOwner, DIST); cache(0, DIST).put(KEY, "a"); tm.begin(); assertEquals("a", rw.eval(KEY, append("b")).join()); assertEquals("ab", rw.evalMany(Collections.singleton(KEY), append("c")).findAny().get()); assertEquals(null, rw.eval("otherKey", append("d")).join()); assertEquals("abc", method.eval(KEY, ro, MarshallableFunctions.returnReadOnlyFindOrNull())); tm.commit(); }