Search in sources :

Example 1 with Scope

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

the class PartitionedRegionCreationJUnitTest method test000PartitionedRegionCreate.

/*
   * 1)Create 10 thread each. Each thread will try to create PartionedRegion total of 5 partitioned
   * region will be created. 5 threads should throw RegionExistException. 2) Tests for PR scope =
   * GLOBAL and PR scope = LOCAL </p> 3) Test for redundancy < 0 </p> 4) Test for redundancy > 3
   * </p> 5) Test for localMaxMemory < 0 </p>
   */
@Test
public void test000PartitionedRegionCreate() {
    createMultiplePartitionedRegions();
    verifyCreateResults();
    if (logger.fineEnabled()) {
        logger.fine(" PartitionedRegionCreationTest-testpartionedRegionCreate() Successfully Complete ..  ");
    }
    final String regionname = "testPartionedRegionCreate";
    int localMaxMemory = 0;
    PartitionedRegion pr = null;
    // Test vanilla creation of a Partitioned Region w/o Scope
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.PARTITION);
        RegionAttributes ra = af.create();
        Cache cache = PartitionedRegionTestHelper.createCache();
        pr = (PartitionedRegion) cache.createRegion(regionname, ra);
    } finally {
        pr.destroyRegion();
    }
    // Assert that setting any scope throws IllegalStateException
    final Scope[] scopes = { Scope.LOCAL, Scope.DISTRIBUTED_ACK, Scope.DISTRIBUTED_NO_ACK, Scope.GLOBAL };
    for (int i = 0; i < scopes.length; i++) {
        try {
            AttributesFactory af = new AttributesFactory();
            af.setDataPolicy(DataPolicy.PARTITION);
            af.setScope(scopes[i]);
            RegionAttributes ra = af.create();
            Cache cache = PartitionedRegionTestHelper.createCache();
            pr = (PartitionedRegion) cache.createRegion(regionname, ra);
            fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for Scope " + scopes[i]);
        } catch (IllegalStateException expected) {
        } finally {
            if (pr != null && !pr.isDestroyed()) {
                pr.destroyRegion();
            }
        }
    }
    // test for redundancy > 3
    int redundancy = 10;
    try {
        pr = (PartitionedRegion) PartitionedRegionTestHelper.createPartitionedRegion(regionname, String.valueOf(localMaxMemory), redundancy);
    } catch (IllegalStateException illex) {
        if (logger.fineEnabled()) {
            logger.fine("testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy > 3 ");
        }
    }
    // test for redundancy < 0
    if (pr != null && !pr.isDestroyed())
        pr.destroyRegion();
    redundancy = -5;
    try {
        pr = (PartitionedRegion) PartitionedRegionTestHelper.createPartitionedRegion(regionname, String.valueOf(200), redundancy);
        fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for redundancy < 0 ");
    } catch (IllegalStateException illex) {
        if (logger.fineEnabled()) {
            logger.fine("testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy < 0 ");
        }
    }
// test for localMaxMemory < 0
/*
     * if (pr!= null && !pr.isDestroyed()) pr.destroyRegion(); ; localMaxMemory = -5; try { pr =
     * (PartitionedRegion)PartitionedRegionTestHelper .createPartitionedRegion(regionname,
     * String.valueOf(localMaxMemory), 2, Scope.DISTRIBUTED_ACK);
     * fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for localMaxMemory < 0 "
     * ); } catch (IllegalStateException illex) { if (logger.fineEnabled()) { logger
     * .fine("testpartionedRegionCreate() Got a correct exception-IllegalStateException for  localMaxMemory < 0  "
     * ); } }
     */
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) Scope(org.apache.geode.cache.Scope) RegionAttributes(org.apache.geode.cache.RegionAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with Scope

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

the class PartitionedRegionCreationJUnitTest method test001PersistentPartitionedRegionCreate.

@Test
public void test001PersistentPartitionedRegionCreate() {
    final String regionname = "testPersistentPartionedRegionCreate";
    PartitionedRegion pr = null;
    // Test vanilla creation of a Partitioned Region w/o Scope
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
        RegionAttributes ra = af.create();
        Cache cache = PartitionedRegionTestHelper.createCache();
        pr = (PartitionedRegion) cache.createRegion(regionname, ra);
    } finally {
        if (pr != null) {
            pr.destroyRegion();
        }
    }
    // Assert that an accessor (localMaxMem == 0) can't be persistent
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
        af.setPartitionAttributes(new PartitionAttributesFactory().setLocalMaxMemory(0).create());
        RegionAttributes ra = af.create();
        Cache cache = PartitionedRegionTestHelper.createCache();
        pr = (PartitionedRegion) cache.createRegion(regionname, ra);
        fail("testpartionedRegionCreate() Expected IllegalStateException not thrown");
    } catch (IllegalStateException expected) {
        assertEquals("Persistence is not allowed when local-max-memory is zero.", expected.getMessage());
    }
    // if configured with a diskStoreName and the disk store has not be created.
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
        af.setDiskStoreName("nonexistentDiskStore");
        RegionAttributes ra = af.create();
        Cache cache = PartitionedRegionTestHelper.createCache();
        pr = (PartitionedRegion) cache.createRegion(regionname, ra);
        fail("testpartionedRegionCreate() Expected IllegalStateException not thrown");
    } catch (RuntimeException expected) {
        assertTrue(expected.getMessage().contains(LocalizedStrings.CacheCreation_DISKSTORE_NOTFOUND_0.toLocalizedString("nonexistentDiskStore")));
    }
    // Assert that you can't have a diskStoreName unless you are persistent or overflow.
    try {
        Cache cache = PartitionedRegionTestHelper.createCache();
        cache.createDiskStoreFactory().create("existentDiskStore");
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.PARTITION);
        af.setDiskStoreName("existentDiskStore");
        RegionAttributes ra = af.create();
        pr = (PartitionedRegion) cache.createRegion(regionname, ra);
        fail("testpartionedRegionCreate() Expected IllegalStateException not thrown");
    } catch (IllegalStateException expected) {
        assertEquals("Only regions with persistence or overflow to disk can specify DiskStore", expected.getMessage());
    }
    // Assert that setting any scope throws IllegalStateException
    final Scope[] scopes = { Scope.LOCAL, Scope.DISTRIBUTED_ACK, Scope.DISTRIBUTED_NO_ACK, Scope.GLOBAL };
    for (int i = 0; i < scopes.length; i++) {
        try {
            AttributesFactory af = new AttributesFactory();
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setScope(scopes[i]);
            RegionAttributes ra = af.create();
            Cache cache = PartitionedRegionTestHelper.createCache();
            pr = (PartitionedRegion) cache.createRegion(regionname, ra);
            fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for Scope " + scopes[i]);
        } catch (IllegalStateException expected) {
        }
    }
    // test for redundancy > 3
    try {
        pr = (PartitionedRegion) PartitionedRegionTestHelper.createPartitionedRegion(regionname, String.valueOf(0), 4);
        fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for redundancy > 3 ");
    } catch (IllegalStateException illex) {
        if (logger.fineEnabled()) {
            logger.fine("testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy > 3 ");
        }
    }
    // test for redundancy < 0
    try {
        pr = (PartitionedRegion) PartitionedRegionTestHelper.createPartitionedRegion(regionname, String.valueOf(200), -1);
        fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for redundancy < 0 ");
    } catch (IllegalStateException illex) {
        if (logger.fineEnabled()) {
            logger.fine("testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy < 0 ");
        }
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) Scope(org.apache.geode.cache.Scope) RegionAttributes(org.apache.geode.cache.RegionAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with Scope

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

the class PartitionedRegionCreationDUnitTest method getCacheSerializableRunnableForPRInitialize.

/**
   * This function tests root, allpartition region and their scope and mirrortype attribute.
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRInitialize() {
    SerializableRunnable initializePrRegion;
    initializePrRegion = new CacheSerializableRunnable("initialize") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region root = cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME);
            if (root == null)
                fail("PartionedRegionInitializationDUnitTest() - the " + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " do not exists");
            RegionAttributes regionAttribs = root.getAttributes();
            Scope scope = regionAttribs.getScope();
            if (!scope.isDistributedAck())
                fail("PartionedRegionInitializationDUnitTest() - the " + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " scope is not distributedAck");
            assertEquals("PartionedRegionInitializationTest() - the " + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " does not have the proper data policy" + DataPolicy.REPLICATE, DataPolicy.REPLICATE, regionAttribs.getDataPolicy());
        // Region allPartitionedRegions = root
        // .getSubregion(PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME);
        // if (allPartitionedRegions == null)
        // fail("PartionedRegionInitializationTest() - the "
        // + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
        // + " do not exists");
        // regionAttribs = allPartitionedRegions.getAttributes();
        // scope = regionAttribs.getScope();
        // if (!scope.isDistributedAck())
        // fail("PartionedRegionInitializationTest() - the "
        // + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
        // + " scope is not global");
        // DataPolicy datapolicy = regionAttribs.getDataPolicy();
        // if (! DataPolicy.REPLICATE.equals(datapolicy))
        // fail("PartionedRegionInitializationTest() - the "
        // + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
        // + " data policy is not " + DataPolicy.REPLICATE);
        }
    };
    return (CacheSerializableRunnable) initializePrRegion;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Scope(org.apache.geode.cache.Scope) CacheException(org.apache.geode.cache.CacheException) RegionAttributes(org.apache.geode.cache.RegionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 4 with Scope

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

the class PartitionedRegionWithSameNameDUnitTest method createMultipleDistributedlRegion.

CacheSerializableRunnable createMultipleDistributedlRegion(final String prPrefix, final int startIndexForRegion, final int endIndexForRegion, final Scope scope, final boolean firstCreationFlag, final boolean multipleVMFlag) {
    CacheSerializableRunnable createLocalRegion = new CacheSerializableRunnable("createDistributedRegion") {

        String innerPrPrefix = prPrefix;

        int innerStartIndexForRegion = startIndexForRegion;

        int innerEndIndexForRegion = endIndexForRegion;

        Scope innerScope = scope;

        boolean innerFirstCreationFlag = firstCreationFlag;

        public void run2() throws CacheException {
            Cache cache = getCache();
            AttributesFactory af = new AttributesFactory();
            af.setScope(innerScope);
            RegionAttributes ra = af.create();
            if (firstCreationFlag) {
                for (int i = innerStartIndexForRegion; i < innerEndIndexForRegion; i++) {
                    try {
                        cache.createRegion(innerPrPrefix + i, ra);
                    } catch (RegionExistsException ex) {
                        Assert.fail("Got incorrect exception because the partition region being created prior to local region", ex);
                    }
                }
            } else {
                for (int i = innerStartIndexForRegion; i < innerEndIndexForRegion; i++) {
                    if (!multipleVMFlag) {
                        try {
                            cache.createRegion(innerPrPrefix + i, ra);
                            fail("test failed : Distributed region with same name as Partitioned region gets created");
                        } catch (RegionExistsException expected) {
                        // getLogWriter()
                        // .info(
                        // "Expected exception RegionExistsException for creating
                        // distributed region with the same name as Partition Region"
                        // + ex);
                        }
                    } else {
                        final String expectedExceptions = IllegalStateException.class.getName();
                        getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions + "</ExpectedException>");
                        try {
                            cache.createRegion(innerPrPrefix + i, ra);
                            fail("test failed : Distributed region with same name as Partitioned region gets created");
                        } catch (IllegalStateException expected) {
                        // getLogWriter()
                        // .info(
                        // "Expected exception IllegalStateException for creating
                        // distributed region with the same name as Partition Region"
                        // + ex);
                        }
                        getCache().getLogger().info("<ExpectedException action=remove>" + expectedExceptions + "</ExpectedException>");
                    }
                }
            }
        }
    };
    return createLocalRegion;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Scope(org.apache.geode.cache.Scope) RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionExistsException(org.apache.geode.cache.RegionExistsException) Cache(org.apache.geode.cache.Cache)

Example 5 with Scope

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

the class LocalRegion method getDistributedLock.

/**
   * This implementation only checks readiness and scope
   */
@Override
public Lock getDistributedLock(Object key) throws IllegalStateException {
    checkReadiness();
    checkForLimitedOrNoAccess();
    Scope theScope = getAttributes().getScope();
    Assert.assertTrue(theScope == Scope.LOCAL);
    throw new IllegalStateException(LocalizedStrings.LocalRegion_ONLY_SUPPORTED_FOR_GLOBAL_SCOPE_NOT_LOCAL.toLocalizedString());
}
Also used : Scope(org.apache.geode.cache.Scope)

Aggregations

Scope (org.apache.geode.cache.Scope)16 RegionAttributes (org.apache.geode.cache.RegionAttributes)11 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 Cache (org.apache.geode.cache.Cache)4 CacheLoader (org.apache.geode.cache.CacheLoader)3 DataPolicy (org.apache.geode.cache.DataPolicy)3 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)3 Region (org.apache.geode.cache.Region)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 CacheException (org.apache.geode.cache.CacheException)2 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)2 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2 File (java.io.File)1 Set (java.util.Set)1 CancelCriterion (org.apache.geode.CancelCriterion)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 CacheEvent (org.apache.geode.cache.CacheEvent)1