Search in sources :

Example 86 with CacheFactory

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);
}
Also used : AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) MyGatewayEventFilter(org.apache.geode.internal.cache.wan.MyGatewayEventFilter) MyGatewayEventFilter(org.apache.geode.internal.cache.wan.MyGatewayEventFilter) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter) Parameters(junitparams.Parameters) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 87 with CacheFactory

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"));
    }
}
Also used : AsyncEventQueueConfigurationException(org.apache.geode.internal.cache.wan.AsyncEventQueueConfigurationException) AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) CacheFactory(org.apache.geode.cache.CacheFactory) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 88 with CacheFactory

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();
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) IOException(java.io.IOException) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 89 with CacheFactory

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);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 90 with CacheFactory

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CacheFactory (org.apache.geode.cache.CacheFactory)125 Properties (java.util.Properties)51 Test (org.junit.Test)51 Cache (org.apache.geode.cache.Cache)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)38 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)28 Region (org.apache.geode.cache.Region)21 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)18 CacheServer (org.apache.geode.cache.server.CacheServer)17 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)17 File (java.io.File)15 Before (org.junit.Before)14 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 ClientCache (org.apache.geode.cache.client.ClientCache)11 Host (org.apache.geode.test.dunit.Host)11 IOException (java.io.IOException)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)10 PdxType (org.apache.geode.pdx.internal.PdxType)9 MyPdxSerializer (com.examples.snapshot.MyPdxSerializer)8