use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class Bug45934DUnitTest method createRemoteRegion.
private void createRemoteRegion(final VM remote, final String name) {
SerializableCallable create = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "45934");
cf.set(CONSERVE_SOCKETS, "false");
getCache(cf).<Integer, Integer>createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT).create(name);
AbstractUpdateOperation.test_InvalidVersion = true;
return null;
}
};
remote.invoke(create);
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class Bug45934DUnitTest method testNormal.
@Test
public void testNormal() throws Exception {
int count = 1000;
Host host = Host.getHost(0);
final VM remote = host.getVM(1);
final String name = getName();
// 0. create the remote region, set error flag
createRemoteRegion(remote, name);
// 1. create the local cache
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "45934");
cf.set(CONSERVE_SOCKETS, "false");
Cache cache = getCache(cf);
// 2. create normal region locally
RegionFactory<Integer, Integer> rf = cache.<Integer, Integer>createRegionFactory();
rf.setDataPolicy(DataPolicy.NORMAL);
rf.setScope(Scope.DISTRIBUTED_ACK);
Region<Integer, Integer> region = rf.create(name);
// 3. reset the error flag after initial failure
DistributedCacheOperation.test_InvalidVersionAction = new DelayedAction(new Runnable() {
@Override
public void run() {
unsetRemoteFlag(remote);
}
});
DistributedCacheOperation.test_InvalidVersionAction.allowToProceed();
// 3. put data
Map<Integer, Integer> values = new HashMap<Integer, Integer>();
for (int i = 0; i < count; i++) {
values.put(i, i);
}
region.putAll(values);
// 5. double check
verifyLocal(region, count);
verify(remote, name, count);
cache.close();
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class CacheLifecycleListenerJUnitTest method testRemoveBeforeCreate.
@Test
public void testRemoveBeforeCreate() throws Exception {
List<CacheLifecycleCallback> cacheCreatedCallbacks = new ArrayList<>();
List<CacheLifecycleCallback> cacheClosedCallbacks = new ArrayList<>();
TestCacheLifecycleListener listener = new TestCacheLifecycleListener(cacheCreatedCallbacks, cacheClosedCallbacks);
try {
GemFireCacheImpl.addCacheLifecycleListener(listener);
GemFireCacheImpl.removeCacheLifecycleListener(listener);
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
InternalCache cache = (InternalCache) new CacheFactory(props).create();
try {
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
} finally {
cache.close();
}
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
} finally {
GemFireCacheImpl.removeCacheLifecycleListener(listener);
}
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class CacheLifecycleListenerJUnitTest method testAddAfterCreate.
@Test
public void testAddAfterCreate() throws Exception {
List<CacheLifecycleCallback> cacheCreatedCallbacks = new ArrayList<>();
List<CacheLifecycleCallback> cacheClosedCallbacks = new ArrayList<>();
TestCacheLifecycleListener listener = new TestCacheLifecycleListener(cacheCreatedCallbacks, cacheClosedCallbacks);
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
InternalCache cache = (InternalCache) new CacheFactory(props).create();
try {
try {
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
GemFireCacheImpl.addCacheLifecycleListener(listener);
} finally {
cache.close();
}
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert one close callback
assertFalse(cacheClosedCallbacks.isEmpty());
assertEquals(1, cacheClosedCallbacks.size());
assertEquals(cache, cacheClosedCallbacks.get(0).getCache());
} finally {
GemFireCacheImpl.removeCacheLifecycleListener(listener);
}
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class CacheLifecycleListenerJUnitTest method testRemoveBeforeClose.
@Test
public void testRemoveBeforeClose() throws Exception {
List<CacheLifecycleCallback> cacheCreatedCallbacks = new ArrayList<>();
List<CacheLifecycleCallback> cacheClosedCallbacks = new ArrayList<>();
TestCacheLifecycleListener listener = new TestCacheLifecycleListener(cacheCreatedCallbacks, cacheClosedCallbacks);
try {
GemFireCacheImpl.addCacheLifecycleListener(listener);
// assert no create callback
assertTrue(cacheCreatedCallbacks.isEmpty());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
InternalCache cache = (InternalCache) new CacheFactory(props).create();
try {
// assert one create callback
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(1, cacheCreatedCallbacks.size());
assertEquals(cache, cacheCreatedCallbacks.get(0).getCache());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
} finally {
GemFireCacheImpl.removeCacheLifecycleListener(listener);
cache.close();
}
// assert one create callback
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(1, cacheCreatedCallbacks.size());
assertEquals(cache, cacheCreatedCallbacks.get(0).getCache());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
} finally {
GemFireCacheImpl.removeCacheLifecycleListener(listener);
}
}
Aggregations