Search in sources :

Example 96 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 97 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 98 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 99 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)

Example 100 with CacheFactory

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);
    }
}
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