use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class AsyncEventQueueValidationsJUnitTest method testConcurrentParallelAsyncEventQueueAttributesOrderPolicyThread.
@Test
public void testConcurrentParallelAsyncEventQueueAttributesOrderPolicyThread() {
cache = new CacheFactory().set(MCAST_PORT, "0").create();
try {
AsyncEventQueueFactory fact = cache.createAsyncEventQueueFactory();
fact.setParallel(true);
fact.setDispatcherThreads(5);
fact.setOrderPolicy(OrderPolicy.THREAD);
fact.create("id", new org.apache.geode.internal.cache.wan.MyAsyncEventListener());
fail("Expected AsyncEventQueueConfigurationException.");
} catch (AsyncEventQueueConfigurationException e) {
assertTrue(e.getMessage().contains("can not be created with OrderPolicy"));
}
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class ServerStarterRule method startServer.
public void startServer() {
CacheFactory cf = new CacheFactory(this.properties);
cf.setPdxReadSerialized(pdxPersistent);
cf.setPdxPersistent(pdxPersistent);
cache = cf.create();
DistributionConfig config = ((InternalDistributedSystem) cache.getDistributedSystem()).getConfig();
server = cache.addCacheServer();
server.setPort(0);
try {
server.start();
} catch (IOException e) {
throw new RuntimeException("unable to start server", e);
}
memberPort = server.getPort();
jmxPort = config.getJmxManagerPort();
httpPort = config.getHttpServicePort();
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class Bug45164DUnitTest method postSetUp.
@Override
public final void postSetUp() throws Exception {
SerializableRunnable create = new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache(new CacheFactory());
Region<Integer, Object> region = cache.<Integer, Object>createRegionFactory(RegionShortcut.PARTITION).create("test");
if (region == null) {
LogWriterUtils.getLogWriter().error("oops!");
}
}
};
SerializableRunnable load = new SerializableRunnable() {
@Override
public void run() {
Region<Integer, Object> region = getCache().getRegion("test");
for (int i = 0; i < count; i++) {
region.put(i, i);
}
}
};
Host h = Host.getHost(0);
h.getVM(1).invoke(create);
h.getVM(2).invoke(create);
h.getVM(3).invoke(create);
h.getVM(1).invoke(load);
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class CacheLifecycleListenerJUnitTest method testCallbacks.
@Test
public void testCallbacks() 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 {
cache.close();
}
// assert one create callback
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(1, cacheCreatedCallbacks.size());
assertEquals(cache, cacheCreatedCallbacks.get(0).getCache());
// 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 testCallbacksRepeat.
@Test
public void testCallbacksRepeat() 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 cache1 = (InternalCache) new CacheFactory(props).create();
try {
// assert one create callback
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(1, cacheCreatedCallbacks.size());
assertEquals(cache1, cacheCreatedCallbacks.get(0).getCache());
// assert no close callback
assertTrue(cacheClosedCallbacks.isEmpty());
} finally {
cache1.close();
}
// assert one create callback
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(1, cacheCreatedCallbacks.size());
assertEquals(cache1, cacheCreatedCallbacks.get(0).getCache());
// assert one close callback
assertFalse(cacheClosedCallbacks.isEmpty());
assertEquals(1, cacheClosedCallbacks.size());
assertEquals(cache1, cacheClosedCallbacks.get(0).getCache());
InternalCache cache2 = (InternalCache) new CacheFactory(props).create();
try {
// assert two create callback
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(2, cacheCreatedCallbacks.size());
assertEquals(cache1, cacheCreatedCallbacks.get(0).getCache());
assertEquals(cache2, cacheCreatedCallbacks.get(1).getCache());
// assert one close callback
assertFalse(cacheClosedCallbacks.isEmpty());
assertEquals(1, cacheClosedCallbacks.size());
assertEquals(cache1, cacheClosedCallbacks.get(0).getCache());
} finally {
cache2.close();
}
// assert two create callbacks
assertFalse(cacheCreatedCallbacks.isEmpty());
assertEquals(2, cacheCreatedCallbacks.size());
assertEquals(cache1, cacheCreatedCallbacks.get(0).getCache());
assertEquals(cache2, cacheCreatedCallbacks.get(1).getCache());
// assert two close callbacks
assertFalse(cacheClosedCallbacks.isEmpty());
assertEquals(2, cacheClosedCallbacks.size());
assertEquals(cache1, cacheClosedCallbacks.get(0).getCache());
assertEquals(cache2, cacheClosedCallbacks.get(1).getCache());
} finally {
GemFireCacheImpl.removeCacheLifecycleListener(listener);
}
}
Aggregations