Search in sources :

Example 76 with CacheFactory

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

the class LuceneIndexXmlParserIntegrationJUnitTest method createIndex.

/**
   * Test that the Index creation objects get appropriately translated into a real index.
   * 
   * @throws FileNotFoundException
   */
@Test
public void createIndex() throws FileNotFoundException {
    CacheFactory cf = new CacheFactory();
    cf.set(MCAST_PORT, "0");
    cf.set(CACHE_XML_FILE, getXmlFileForTest());
    Cache cache = cf.create();
    LuceneService service = LuceneServiceProvider.get(cache);
    assertEquals(3, service.getAllIndexes().size());
    LuceneIndex index1 = service.getIndex("index1", "/region");
    LuceneIndex index2 = service.getIndex("index2", "/region");
    LuceneIndex index3 = service.getIndex("index3", "/region");
    assertArrayEquals(index1.getFieldNames(), new String[] { "a", "b", "c", "d" });
    assertArrayEquals(index2.getFieldNames(), new String[] { "f", "g" });
    assertArrayEquals(index3.getFieldNames(), new String[] { "h", "i", "j" });
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache) LuceneService(org.apache.geode.cache.lucene.LuceneService) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 77 with CacheFactory

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

the class PdxDeleteFieldDUnitTest method testPdxDeleteFieldVersioning.

@Test
public void testPdxDeleteFieldVersioning() throws Exception {
    final String DS_NAME = "PdxDeleteFieldDUnitTestDiskStore";
    final String DS_NAME2 = "PdxDeleteFieldDUnitTestDiskStore2";
    final Properties props = new Properties();
    final int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "localhost[" + locatorPorts[0] + "],localhost[" + locatorPorts[1] + "]");
    props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    final File f = new File(DS_NAME);
    f.mkdir();
    final File f2 = new File(DS_NAME2);
    f2.mkdir();
    this.filesToBeDeleted.add(DS_NAME);
    this.filesToBeDeleted.add(DS_NAME2);
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            disconnectFromDS();
            props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[0] + "]");
            final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            dsf.setDiskDirs(new File[] { f });
            dsf.create(DS_NAME);
            RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
            rf1.setDiskStoreName(DS_NAME);
            Region<String, PdxValue> region1 = rf1.create("region1");
            region1.put("key1", new PdxValue(1, 2L));
            return null;
        }
    });
    vm2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            disconnectFromDS();
            props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[1] + "]");
            final Cache cache = (new CacheFactory(props)).setPdxReadSerialized(true).setPdxPersistent(true).setPdxDiskStore(DS_NAME2).create();
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            dsf.setDiskDirs(new File[] { f2 });
            dsf.create(DS_NAME2);
            RegionFactory rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
            rf1.setDiskStoreName(DS_NAME2);
            Region region1 = rf1.create("region1");
            Object v = region1.get("key1");
            assertNotNull(v);
            cache.close();
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Cache cache = CacheFactory.getAnyInstance();
            if (cache != null && !cache.isClosed()) {
                cache.close();
            }
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Collection<PdxType> types = DiskStoreImpl.pdxDeleteField(DS_NAME, new File[] { f }, PdxValue.class.getName(), "fieldToDelete");
            assertEquals(1, types.size());
            PdxType pt = types.iterator().next();
            assertEquals(PdxValue.class.getName(), pt.getClassName());
            assertEquals(null, pt.getPdxField("fieldToDelete"));
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[0] + "]");
            final Cache cache = (new CacheFactory(props)).setPdxPersistent(true).setPdxDiskStore(DS_NAME).create();
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            dsf.setDiskDirs(new File[] { f });
            dsf.create(DS_NAME);
            RegionFactory<String, PdxValue> rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
            rf1.setDiskStoreName(DS_NAME);
            Region<String, PdxValue> region1 = rf1.create("region1");
            return null;
        }
    });
    vm2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            props.setProperty(START_LOCATOR, "localhost[" + locatorPorts[1] + "]");
            final Cache cache = (new CacheFactory(props)).setPdxReadSerialized(true).setPdxPersistent(true).setPdxDiskStore(DS_NAME2).create();
            DiskStoreFactory dsf = cache.createDiskStoreFactory();
            dsf.setDiskDirs(new File[] { f2 });
            dsf.create(DS_NAME2);
            RegionFactory rf1 = cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
            rf1.setDiskStoreName(DS_NAME2);
            Region region1 = rf1.create("region1");
            PdxInstance v = (PdxInstance) region1.get("key1");
            assertNotNull(v);
            assertEquals(1, v.getField("value"));
            assertEquals(null, v.getField("fieldToDelete"));
            cache.close();
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Cache cache = CacheFactory.getAnyInstance();
            if (cache != null && !cache.isClosed()) {
                cache.close();
            }
            return null;
        }
    });
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) IOException(java.io.IOException) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) RegionFactory(org.apache.geode.cache.RegionFactory) PdxInstance(org.apache.geode.pdx.PdxInstance) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 78 with CacheFactory

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

the class RegionOperationsEqualityShouldUseArrayEqualsIntegrationTest method createCache.

private GemFireCacheImpl createCache() {
    Properties props = new Properties();
    props.setProperty(LOCATORS, "");
    props.setProperty(MCAST_PORT, "0");
    GemFireCacheImpl result = (GemFireCacheImpl) new CacheFactory(props).create();
    return result;
}
Also used : GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 79 with CacheFactory

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

the class OffHeapRegionBase method createCache.

private GemFireCacheImpl createCache(boolean isPersistent) {
    configureOffHeapStorage();
    Properties props = new Properties();
    props.setProperty(LOCATORS, "");
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(ConfigurationProperties.OFF_HEAP_MEMORY_SIZE, getOffHeapMemorySize());
    GemFireCacheImpl result = (GemFireCacheImpl) new CacheFactory(props).setPdxPersistent(isPersistent).create();
    unconfigureOffHeapStorage();
    return result;
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 80 with CacheFactory

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

the class InlineKeyJUnitTest method createCache.

private GemFireCacheImpl createCache() {
    Properties props = new Properties();
    props.setProperty(LOCATORS, "");
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(ConfigurationProperties.OFF_HEAP_MEMORY_SIZE, "1m");
    GemFireCacheImpl result = (GemFireCacheImpl) new CacheFactory(props).create();
    return result;
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory)

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