Search in sources :

Example 46 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class PDXAsyncEventQueueDUnitTest method createSystem.

protected void createSystem(VM vm, final boolean pdxPersistent) {
    SerializableCallable createSystem = new SerializableCallable() {

        public Object call() throws Exception {
            Properties props = new Properties();
            // props.setProperty(DistributionConfig.LOCATORS_NAME, "");
            getSystem(props);
            CacheFactory cf = new CacheFactory();
            cf.setPdxPersistent(pdxPersistent);
            getCache(cf);
            return null;
        }
    };
    vm.invoke(createSystem);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 47 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class PdxAttributesJUnitTest method testNonPersistentRegistryWithOverflowRegion.

@Test
public void testNonPersistentRegistryWithOverflowRegion() throws Exception {
    {
        CacheFactory cf = new CacheFactory();
        cf.set(MCAST_PORT, "0");
        Cache cache = cf.create();
        cache.createDiskStoreFactory().setDiskDirs(new File[] { diskDir }).setMaxOplogSize(1).create("diskstore1");
        cache.createRegionFactory(RegionShortcut.LOCAL_OVERFLOW).setDiskStoreName("diskstore1").create("region");
        defineAType();
    }
    tearDown();
    setUp();
    {
        CacheFactory cf = new CacheFactory();
        cf.set(MCAST_PORT, "0");
        Cache cache = cf.create();
        defineAType();
        cache.createDiskStoreFactory().setDiskDirs(new File[] { diskDir }).setMaxOplogSize(1).create("diskstore1");
        cache.createRegionFactory(RegionShortcut.LOCAL_OVERFLOW).setDiskStoreName("diskstore1").create("region");
    }
}
Also used : CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 48 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class PdxAttributesJUnitTest method testNonPersistentRegistryWithPersistentRegion.

@Test
public void testNonPersistentRegistryWithPersistentRegion() throws Exception {
    {
        CacheFactory cf = new CacheFactory();
        cf.set(MCAST_PORT, "0");
        Cache cache = cf.create();
        cache.createDiskStoreFactory().setDiskDirs(new File[] { diskDir }).setMaxOplogSize(1).create("diskstore1");
        cache.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("diskstore1").create("region");
        try {
            defineATypeNoEnum();
            throw new RuntimeException("Should have received an exception");
        } catch (PdxInitializationException expected) {
        }
    }
    tearDown();
    setUp();
    {
        CacheFactory cf = new CacheFactory();
        cf.set(MCAST_PORT, "0");
        Cache cache = cf.create();
        defineATypeNoEnum();
        cache.createDiskStoreFactory().setDiskDirs(new File[] { diskDir }).setMaxOplogSize(1).create("diskstore1");
        try {
            cache.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT).setDiskStoreName("diskStore1").create("region");
            throw new RuntimeException("Should have received an exception");
        } catch (PdxInitializationException expected) {
        }
    }
}
Also used : CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 49 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class JSONPdxClientServerDUnitTest method createServerRegionWithPersistence.

private int createServerRegionWithPersistence(VM vm, final boolean persistentPdxRegistry) {
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory();
            if (persistentPdxRegistry) {
                cf.setPdxPersistent(true).setPdxDiskStore("store");
            }
            //
            Cache cache = getCache(cf);
            cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("store");
            AttributesFactory af = new AttributesFactory();
            af.setScope(Scope.DISTRIBUTED_ACK);
            af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
            af.setDiskStoreName("store");
            createRootRegion("testSimplePdx", af.create());
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailableTCPPort();
            server.setPort(port);
            server.start();
            return port;
        }
    };
    return (Integer) vm.invoke(createRegion);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 50 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class CacheXml66DUnitTest method testPdxAttributes.

@Test
public void testPdxAttributes() throws Exception {
    CacheCreation creation = new CacheCreation();
    creation.setPdxPersistent(true);
    creation.setPdxReadSerialized(true);
    creation.setPdxIgnoreUnreadFields(true);
    creation.setPdxDiskStore("my_disk_store");
    TestPdxSerializer serializer = new TestPdxSerializer();
    Properties props = new Properties();
    props.setProperty("hello", "there");
    serializer.init(props);
    creation.setPdxSerializer(serializer);
    testXml(creation);
    Cache c = getCache();
    assertTrue(c instanceof GemFireCacheImpl);
    c.loadCacheXml(generate(creation));
    assertEquals("my_disk_store", c.getPdxDiskStore());
    assertEquals(serializer, c.getPdxSerializer());
    assertEquals(true, c.getPdxPersistent());
    assertEquals(true, c.getPdxReadSerialized());
    assertEquals(true, c.getPdxIgnoreUnreadFields());
    // test that we can override the cache.xml attributes
    {
        closeCache();
        CacheFactory cf = new CacheFactory();
        cf.setPdxDiskStore("new disk store");
        c = getCache(cf);
        assertTrue(c instanceof GemFireCacheImpl);
        c.loadCacheXml(generate(creation));
        assertEquals("new disk store", c.getPdxDiskStore());
        assertEquals(serializer, c.getPdxSerializer());
        assertEquals(true, c.getPdxPersistent());
        assertEquals(true, c.getPdxReadSerialized());
        assertEquals(true, c.getPdxIgnoreUnreadFields());
    }
    {
        closeCache();
        CacheFactory cf = new CacheFactory();
        cf.setPdxPersistent(false);
        cf.setPdxIgnoreUnreadFields(false);
        c = getCache(cf);
        assertTrue(c instanceof GemFireCacheImpl);
        c.loadCacheXml(generate(creation));
        assertEquals("my_disk_store", c.getPdxDiskStore());
        assertEquals(serializer, c.getPdxSerializer());
        assertEquals(false, c.getPdxPersistent());
        assertEquals(true, c.getPdxReadSerialized());
        assertEquals(false, c.getPdxIgnoreUnreadFields());
    }
    {
        closeCache();
        CacheFactory cf = new CacheFactory();
        cf.setPdxSerializer(null);
        c = getCache(cf);
        assertTrue(c instanceof GemFireCacheImpl);
        c.loadCacheXml(generate(creation));
        assertEquals("my_disk_store", c.getPdxDiskStore());
        assertEquals(null, c.getPdxSerializer());
        assertEquals(true, c.getPdxPersistent());
        assertEquals(true, c.getPdxReadSerialized());
        assertEquals(true, c.getPdxIgnoreUnreadFields());
    }
    {
        closeCache();
        CacheFactory cf = new CacheFactory();
        cf.setPdxReadSerialized(false);
        c = getCache(cf);
        assertTrue(c instanceof GemFireCacheImpl);
        c.loadCacheXml(generate(creation));
        assertEquals("my_disk_store", c.getPdxDiskStore());
        assertEquals(serializer, c.getPdxSerializer());
        assertEquals(true, c.getPdxPersistent());
        assertEquals(false, c.getPdxReadSerialized());
        assertEquals(true, c.getPdxIgnoreUnreadFields());
    }
}
Also used : GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

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