Search in sources :

Example 66 with PartitionAttributesFactory

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

the class Bug40632DUnitTest method testLocalDestroyTimeToLive.

@Test
public void testLocalDestroyTimeToLive() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 67 with PartitionAttributesFactory

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

the class Bug40632DUnitTest method testLocalInvalidateIdleTimeout.

@Test
public void testLocalInvalidateIdleTimeout() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 68 with PartitionAttributesFactory

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

the class Bug41091DUnitTest method test.

@Test
public void test() {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    // We need to use our own locator because we need enable network partition detection.
    startLocatorInVM(vm3, locatorPort);
    try {
        final SerializableRunnable createRegion = new SerializableRunnable("create the region") {

            public void run() {
                DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                    @Override
                    public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                        if (message instanceof RequestImageMessage) {
                            RequestImageMessage rim = (RequestImageMessage) message;
                            Region region = getCache().getRegion(rim.regionPath);
                            if (region instanceof BucketRegion) {
                                // We can no longer do any puts until the bucket is completely created,
                                // so this will hang
                                // getCache().getRegion("region").put(113, "b");
                                getCache().close();
                            }
                        }
                    }
                });
                Properties props = new Properties();
                props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
                props.setProperty(LOCATORS, NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
                getSystem(props);
                Cache cache = getCache();
                AttributesFactory af = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(1);
                af.setPartitionAttributes(paf.create());
                cache.createRegion("region", af.create());
            }
        };
        vm0.invoke(createRegion);
        vm1.invoke(createRegion);
        vm2.invoke(new SerializableRunnable("create an entry") {

            public void run() {
                Properties props = new Properties();
                props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
                props.setProperty(LOCATORS, NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
                getSystem(props);
                Cache cache = getCache();
                AttributesFactory af = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(1);
                paf.setLocalMaxMemory(0);
                af.setPartitionAttributes(paf.create());
                Region region = cache.createRegion("region", af.create());
                region.put(Integer.valueOf(0), "a");
            }
        });
    } finally {
        SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {

            public void run() {
                assertTrue(Locator.hasLocator());
                Locator.getLocator().stop();
                assertFalse(Locator.hasLocator());
            }
        };
        vm3.invoke(stopLocator);
    }
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 69 with PartitionAttributesFactory

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

the class DistrbutedRegionProfileOffHeapDUnitTest method testPartitionedRegionProfileWithAccessor.

/**
   * Asserts that creating a region on two members, with one being off-heap with local storage and
   * the other being on-heap without local storage, will not cause an exception.
   */
@Test
public void testPartitionedRegionProfileWithAccessor() throws Exception {
    final String regionName = getTestMethodName() + "Region";
    // Create a region using off-heap
    Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("createRegionNoException") {

        private static final long serialVersionUID = 1L;

        @Override
        public void run2() throws CacheException {
            disconnectFromDS();
            Properties properties = new Properties();
            properties.put(OFF_HEAP_MEMORY_SIZE, "2m");
            getSystem(properties);
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            regionFactory.setOffHeap(true);
            Region region = regionFactory.create(regionName);
            assertNotNull("Region is null", region);
            assertNotNull("Cache does not contain region", cache.getRegion(regionName));
        }
    });
    // Create an accessor (no local storage) for the same region
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("createRegionNoException") {

        private static final long serialVersionUID = 1L;

        @Override
        public void run2() throws CacheException {
            disconnectFromDS();
            Properties properties = new Properties();
            properties.put(OFF_HEAP_MEMORY_SIZE, "2m");
            getSystem(properties);
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            PartitionAttributes partitionAttributes = new PartitionAttributesFactory().setLocalMaxMemory(0).create();
            regionFactory.setPartitionAttributes(partitionAttributes);
            Region region = regionFactory.create(regionName);
            assertNotNull("Region is null", region);
            assertNotNull("Cache does not contain region", cache.getRegion(regionName));
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 70 with PartitionAttributesFactory

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

the class PartitionedRegionAPIDUnitTest method testCacherLoaderHelper.

@Test
public void testCacherLoaderHelper() throws Exception {
    final String rName = getUniqueName();
    Host host = Host.getHost(0);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    final int localMaxMemory = 10;
    final String key1 = "key1";
    final String arg = "loaderArg";
    CacheSerializableRunnable createLoaderPR = new CacheSerializableRunnable("createLoaderPR") {

        public void run2() throws CacheException {
            getCache();
            CacheLoader cl = new TestCacheLoader() {

                public Object load2(LoaderHelper helper) throws CacheLoaderException {
                    assertNotNull(helper);
                    assertEquals(key1, helper.getKey());
                    assertEquals(rName, helper.getRegion().getName());
                    assertEquals(arg, helper.getArgument());
                    return helper.getArgument();
                }
            };
            PartitionedRegion pr = (PartitionedRegion) new RegionFactory().setCacheLoader(cl).setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(1).setLocalMaxMemory(localMaxMemory).create()).create(rName);
            assertSame(cl, pr.getDataStore().getCacheLoader());
        }
    };
    vm2.invoke(createLoaderPR);
    vm3.invoke(createLoaderPR);
    // create a "pure" accessor, no data storage
    getCache();
    Region pr = new RegionFactory().setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(1).setLocalMaxMemory(0).create()).create(rName);
    assertEquals(arg, pr.get(key1, arg));
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Host(org.apache.geode.test.dunit.Host) TestCacheLoader(org.apache.geode.cache30.TestCacheLoader) CacheLoader(org.apache.geode.cache.CacheLoader) TestCacheLoader(org.apache.geode.cache30.TestCacheLoader) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)340 AttributesFactory (org.apache.geode.cache.AttributesFactory)289 Region (org.apache.geode.cache.Region)173 Test (org.junit.Test)154 Cache (org.apache.geode.cache.Cache)136 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)116 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)112 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)110 VM (org.apache.geode.test.dunit.VM)101 Host (org.apache.geode.test.dunit.Host)99 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)95 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)75 CacheException (org.apache.geode.cache.CacheException)58 LocalRegion (org.apache.geode.internal.cache.LocalRegion)48 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)47 IOException (java.io.IOException)42 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)42 DiskStore (org.apache.geode.cache.DiskStore)41 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 BucketRegion (org.apache.geode.internal.cache.BucketRegion)35