use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class AsyncEventQueueValidationsJUnitTest method testAsyncEventQueueConfiguredFromXmlUsesFilter.
@Test
@Parameters(method = "getCacheXmlFileBaseNames")
public void testAsyncEventQueueConfiguredFromXmlUsesFilter(String cacheXmlFileBaseName) {
// Create cache with xml
String cacheXmlFileName = TestUtil.getResourcePath(getClass(), getClass().getSimpleName() + "." + cacheXmlFileBaseName + ".cache.xml");
cache = new CacheFactory().set(MCAST_PORT, "0").set(CACHE_XML_FILE, cacheXmlFileName).create();
// Get region and do puts
Region region = cache.getRegion(cacheXmlFileBaseName);
int numPuts = 10;
for (int i = 0; i < numPuts; i++) {
region.put(i, i);
}
// Get AsyncEventQueue and GatewayEventFilter
AsyncEventQueue aeq = cache.getAsyncEventQueue(cacheXmlFileBaseName);
List<GatewayEventFilter> filters = aeq.getGatewayEventFilters();
assertTrue(filters.size() == 1);
MyGatewayEventFilter filter = (MyGatewayEventFilter) filters.get(0);
// Validate filter callbacks were invoked
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> filter.getBeforeEnqueueInvocations() == numPuts);
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> filter.getBeforeTransmitInvocations() == numPuts);
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> filter.getAfterAcknowledgementInvocations() == numPuts);
}
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);
}
}
Aggregations