@Test(dependsOnMethods = "sequantialOvewritingInBatches") public void indexWasStored() { cache = cacheManager.getCache(); Assert.assertEquals(0, cache.getAdvancedCache().getDataContainer().size()); boolean failed = false; for (Object key : cacheCopy.keySet()) { Object expected = cacheCopy.get(key); Object actual = cache.get(key); if (!expected.equals(actual)) { log.errorf("Failure on key '%s' expected value: '%s' actual value: '%s'", key.toString(), expected, actual); failed = true; } } Assert.assertFalse(failed); Assert.assertEquals(cacheCopy.keySet().size(), cache.keySet().size(), "have a different number of keys"); }
public void testEntrySetAfterExpiryWithStore() throws Exception { ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false); createCacheStoreConfig(cb.persistence(), true); cacheManager.defineConfiguration("testEntrySetAfterExpiryWithStore", cb.build()); Cache<String, String> cache = cacheManager.getCache("testEntrySetAfterExpiryWithStore"); cache.start(); cache.clear(); assertEquals(cache.entrySet().size(), 0); Map dataIn = new HashMap(); dataIn.put(1, 1); dataIn.put(2, 2); cache.putAll(dataIn, EXPIRATION_TIMEOUT, TimeUnit.MILLISECONDS); Thread.sleep(EXPIRATION_TIMEOUT + 1000); assertEquals(cache.entrySet().size(), 0); }
@Override public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable { // First execute the operation itself Object ret = super.visitPutKeyValueCommand(ctx, command); assertKeySet = (cache.keySet().size() == 1); // After entry has been committed to the container log.info("Cache entry created, now check in different thread"); latch.countDown(); // Force a bit of delay in the listener TestingUtil.sleepThread(3000); return ret; }
private void checkResponse(String result, int entryCount) { assert isSuccess(result) : "Received: " + result; assertEquals(cache(0, "test").keySet().size(), entryCount); assertEquals(cache(1, "test").keySet().size(), entryCount); eventually(new Condition() { @Override public boolean isSatisfied() throws Exception { return showInDoubtTransactions(0).isEmpty() && showInDoubtTransactions(1).isEmpty(); } }); //just make sure everything is cleaned up properly now checkProperlyCleanup(0); checkProperlyCleanup(1); }
public void testKeySetAfterExpiryInPut(Method m) throws Exception { Cache<Integer, String> cache = cm.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.keySet().size()); }
public void testForceCommitOnOtherNode() throws Exception { String inDoubt = showInDoubtTransactions(0); assertInDoubtTxCount(inDoubt, 1); assertInDoubtTxCount(showInDoubtTransactions(1), 1); List<Long> ids = getInternalIds(inDoubt); assertEquals(1, ids.size()); assertEquals(0, cache(0, "test").keySet().size()); assertEquals(0, cache(1, "test").keySet().size()); if (log.isTraceEnabled()) log.trace("Before forcing commit!"); String result = invokeForceWithId("forceCommit", 0, ids.get(0)); checkResponse(result, 1); }
public void testTxCleanupWithEntrySet() throws Exception { tm().begin(); assertEquals(0, cache.entrySet().size()); TransactionTable txTable = getTransactionTable(cache); assertEquals(1, txTable.getLocalTransactions().size()); tm().commit(); assertEquals(0, txTable.getLocalTransactions().size()); }
private void doTestEntrySetAfterExpiryInPut(Method m, CacheContainer cc) throws Exception { Cache<Integer, String> cache = cc.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.entrySet().size()); }
public void testTxCleanupWithKeySet() throws Exception { tm().begin(); assertEquals(0, cache.keySet().size()); TransactionTable txTable = getTransactionTable(cache); assertEquals(1, txTable.getLocalTransactions().size()); tm().commit(); assertEquals(0, txTable.getLocalTransactions().size()); }
private void doKeySetAfterExpiryInTransaction(Method m, CacheContainer cc) throws Exception { Cache<Integer, String> cache = cc.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); cache.getAdvancedCache().getTransactionManager().begin(); try { Map txDataIn = new HashMap(); txDataIn.put(3, v(m, 3)); Map allEntriesIn = new HashMap(dataIn); // Update expectations allEntriesIn.putAll(txDataIn); // Add an entry within tx cache.putAll(txDataIn); timeService.advance(lifespan + 100); } finally { cache.getAdvancedCache().getTransactionManager().commit(); } assertEquals(1, cache.keySet().size()); }
public void testKeySetSizeAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertEquals(0, cache.keySet().size()); } finally { tm().commit(); } }
private void doEntrySetAfterExpiryInTransaction(Method m, CacheContainer cc) throws Exception { Cache<Integer, String> cache = cc.getCache(); Set<Map.Entry<Integer, String>> entries; Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); cache.getAdvancedCache().getTransactionManager().begin(); try { Map txDataIn = new HashMap(); txDataIn.put(3, v(m, 3)); Map allEntriesIn = new HashMap(dataIn); // Update expectations allEntriesIn.putAll(txDataIn); // Add an entry within tx cache.putAll(txDataIn); timeService.advance(lifespan + 100); } finally { cache.getAdvancedCache().getTransactionManager().commit(); } assertEquals(1, cache.entrySet().size()); }
public void testEntrySetSizeAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertEquals(0, cache.entrySet().size()); } finally { tm().commit(); } }
public void testLoadEntrySet() { int numberOfEntries = 10; ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false); createCacheStoreConfig(cb.persistence(), true); cacheManager.defineConfiguration("testLoadKeySet", cb.build()); Cache<String, Object> cache = cacheManager.getCache("testLoadKeySet"); Map<String, Object> entriesMap = IntStream.range(0, numberOfEntries).boxed() .collect(Collectors.toMap(Object::toString, i -> wrap(i.toString(), "Val"+i))); cache.putAll(entriesMap); cache.stop(); cache.start(); CacheSet<Map.Entry<String, Object>> set = cache.entrySet(); assertEquals(numberOfEntries, cache.size()); assertEquals(numberOfEntries, set.size()); set.forEach(e -> assertEquals(entriesMap.get(e.getKey()), e.getValue())); }
public void testKeySet2() throws Exception { cache.put("k1", "v1"); cache.put("k2", "v2"); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); tm().begin(); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); cache.remove("k1"); assertEquals(1, cache.keySet().size()); assertEquals(1, cache.values().size()); tm().rollback(); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); }
public void testKeySetAlterValue() throws Exception { cache.put("k1", "v1"); cache.put("k2", "v2"); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); tm().begin(); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); cache.put("k1", "v3"); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); assert cache.values().contains("v3"); tm().rollback(); assertEquals(2, cache.keySet().size()); assertEquals(2, cache.values().size()); }
private void assertCacheSize(int expectedSize) { assertEquals(expectedSize, cache.size()); assertEquals(expectedSize, cache.keySet().size()); assertEquals(expectedSize, cache.values().size()); assertEquals(expectedSize, cache.entrySet().size()); boolean isEmpty = expectedSize == 0; assertEquals(isEmpty, cache.isEmpty()); assertEquals(isEmpty, cache.keySet().isEmpty()); assertEquals(isEmpty, cache.values().isEmpty()); assertEquals(isEmpty, cache.entrySet().isEmpty()); }
private void assertCacheSize(int expectedSize) { assertEquals(expectedSize, cache.size()); assertEquals(expectedSize, cache.keySet().size()); assertEquals(expectedSize, cache.values().size()); assertEquals(expectedSize, cache.entrySet().size()); boolean isEmpty = expectedSize == 0; assertEquals(isEmpty, cache.isEmpty()); assertEquals(isEmpty, cache.keySet().isEmpty()); assertEquals(isEmpty, cache.values().isEmpty()); assertEquals(isEmpty, cache.entrySet().isEmpty()); }
public void testPreloadStoredAsBinary() { ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false); createCacheStoreConfig(cb.persistence(), true).memory().storageType(StorageType.BINARY); cacheManager.defineConfiguration("testPreloadStoredAsBinary", cb.build()); Cache<String, Pojo> cache = cacheManager.getCache("testPreloadStoredAsBinary"); cache.start(); assert cache.getCacheConfiguration().persistence().preload(); assertEquals(StorageType.BINARY, cache.getCacheConfiguration().memory().storageType()); cache.put("k1", new Pojo(1)); cache.put("k2", new Pojo(2), 111111, TimeUnit.MILLISECONDS); cache.put("k3", new Pojo(3), -1, TimeUnit.MILLISECONDS, 222222, TimeUnit.MILLISECONDS); cache.put("k4", new Pojo(4), 333333, TimeUnit.MILLISECONDS, 444444, TimeUnit.MILLISECONDS); cache.stop(); cache.start(); assertEquals(4, cache.entrySet().size()); assertEquals(new Pojo(1), cache.get("k1")); assertEquals(new Pojo(2), cache.get("k2")); assertEquals(new Pojo(3), cache.get("k3")); assertEquals(new Pojo(4), cache.get("k4")); }