Search in sources :

Example 51 with RegionFactory

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

the class BackupJUnitTest method createRegion.

protected Region createRegion() {
    RegionFactory rf = new RegionFactory();
    rf.setDiskStoreName("diskStore");
    rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    return rf.create("region");
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory)

Example 52 with RegionFactory

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

the class PdxRenameDUnitTest method testPdxRenameVersioning.

@Test
public void testPdxRenameVersioning() throws Exception {
    final String DS_NAME = "PdxRenameDUnitTestDiskStore";
    final String DS_NAME2 = "PdxRenameDUnitTestDiskStore2";
    final int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    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);
    final Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "localhost[" + locatorPorts[0] + "],localhost[" + locatorPorts[1] + "]");
    props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    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));
            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<Object> renameResults = DiskStoreImpl.pdxRename(DS_NAME, new File[] { f }, "apache", "pivotal");
            assertEquals(2, renameResults.size());
            for (Object o : renameResults) {
                if (o instanceof PdxType) {
                    PdxType t = (PdxType) o;
                    assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$PdxValue", t.getClassName());
                } else {
                    EnumInfo ei = (EnumInfo) o;
                    assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$Day", ei.getClassName());
                }
            }
            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 {
            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");
            PdxInstance v = (PdxInstance) region1.get("key1");
            assertNotNull(v);
            assertEquals("org.pivotal.geode.internal.PdxRenameDUnitTest$PdxValue", ((PdxInstanceImpl) v).getClassName());
            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) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) 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) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) 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 53 with RegionFactory

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

the class BackupJUnitTest method createOverflowRegion.

private Region createOverflowRegion() {
    RegionFactory rf = new RegionFactory();
    rf.setDiskStoreName("diskStore");
    rf.setEvictionAttributes(EvictionAttributes.createLIFOEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
    rf.setDataPolicy(DataPolicy.NORMAL);
    return rf.create("region");
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory)

Example 54 with RegionFactory

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

the class GIIFlowControlDUnitTest method getCreateRegionRunnable.

private SerializableRunnable getCreateRegionRunnable() {
    SerializableRunnable createRegion = new SerializableRunnable("Create non persistent region") {

        public void run() {
            getCache();
            RegionFactory rf = new RegionFactory();
            rf.setDataPolicy(DataPolicy.REPLICATE);
            rf.setScope(Scope.DISTRIBUTED_ACK);
            rf.create(REGION_NAME);
        }
    };
    return createRegion;
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable)

Example 55 with RegionFactory

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

the class MemoryMonitorJUnitTest method testPutsPartitionedRegion.

@Test
public void testPutsPartitionedRegion() throws Exception {
    PartitionAttributes pa = new PartitionAttributesFactory().setRedundantCopies(0).setTotalNumBuckets(3).create();
    Region region = new RegionFactory().setPartitionAttributes(pa).create("parReg");
    checkOpRejection(region, false, true);
    region.close();
    assertEquals(0 + SYSTEM_LISTENERS, cache.getInternalResourceManager(false).getResourceListeners(ResourceType.HEAP_MEMORY).size());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

RegionFactory (org.apache.geode.cache.RegionFactory)124 Region (org.apache.geode.cache.Region)63 Cache (org.apache.geode.cache.Cache)57 Test (org.junit.Test)54 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)51 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)44 VM (org.apache.geode.test.dunit.VM)44 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)31 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 CacheException (org.apache.geode.cache.CacheException)30 Host (org.apache.geode.test.dunit.Host)28 Properties (java.util.Properties)25 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)22 File (java.io.File)21 DiskStore (org.apache.geode.cache.DiskStore)20 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)20 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)18 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)17 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)17