Search in sources :

Example 26 with CacheFactory

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

Example 27 with CacheFactory

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();
}
Also used : HashMap(java.util.HashMap) Host(org.apache.geode.test.dunit.Host) VM(org.apache.geode.test.dunit.VM) CacheFactory(org.apache.geode.cache.CacheFactory) DelayedAction(org.apache.geode.internal.util.DelayedAction) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with CacheFactory

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);
    }
}
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 29 with CacheFactory

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);
    }
}
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 30 with CacheFactory

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