Search in sources :

Example 71 with Cache

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

the class PartitionedRegionLocalMaxMemoryDUnitTest method destroyRegion.

private void destroyRegion(VM vm) {
    SerializableRunnable destroyObj = new CacheSerializableRunnable("destroyObj") {

        public void run2() {
            Cache cache = getCache();
            PartitionedRegion pr = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + "testLocalMaxMemoryInPartitionedRegion0");
            assertNotNull("Name of region : " + pr.getName(), pr);
            pr.destroyRegion();
        }
    };
    vm.invoke(destroyObj);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 72 with Cache

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

the class PartitionedRegionMultipleDUnitTest method validateContainsAPIForPartitionRegion.

/**
   * This function returns CacheSerializableRunnable Object which checks contains() and
   * containsValueForKey() APIs.
   */
private CacheSerializableRunnable validateContainsAPIForPartitionRegion(final int startIndexForRegion, final int endIndexForRegion) {
    CacheSerializableRunnable validateRegionAPIs = new CacheSerializableRunnable("validateInserts") {

        String innerprPrefix = prPrefix;

        int innerStartIndexForRegion = startIndexForRegion;

        int innerEndIndexForRegion = endIndexForRegion;

        int innerStartIndexForKey = startIndexForKey;

        int innerEndIndexForKey = endIndexForKey;

        int innerStartIndexForDestroy = startIndexForDestroy;

        int innerEndIndexForDestroy = endIndexForDestroy;

        public void run2() throws CacheException {
            Cache cache = getCache();
            // Get Validation.
            for (int j = innerStartIndexForRegion; j < innerEndIndexForRegion; j++) {
                Region pr = cache.getRegion(Region.SEPARATOR + innerprPrefix + (j));
                assertNotNull(pr);
                assertEquals(pr.getName(), innerprPrefix + (j));
                for (int i = innerStartIndexForKey; i < innerEndIndexForKey; i++) {
                    Object val = null;
                    val = pr.get(j + innerprPrefix + i);
                    if (i >= innerStartIndexForDestroy && i < innerEndIndexForDestroy) {
                        assertNull(val);
                    } else if (val != null) {
                        assertEquals(val, innerprPrefix + i);
                        assertTrue(pr.containsValue(innerprPrefix + i));
                    // pass
                    } else {
                        fail("Validation failed for key = " + j + innerprPrefix + i + "Value got = " + val);
                    }
                }
                LogWriterUtils.getLogWriter().info("validateContainsAPIForPartitionRegion() - Get() Validations done Successfully in Partition Region " + pr.getName());
                // containsKey validation.
                for (int i = innerStartIndexForKey; i < innerEndIndexForKey; i++) {
                    boolean conKey = pr.containsKey(j + innerprPrefix + i);
                    if (i >= innerStartIndexForDestroy && i < innerEndIndexForDestroy) {
                        assertFalse(conKey);
                    } else {
                        assertTrue(conKey);
                    }
                }
                LogWriterUtils.getLogWriter().info("validateContainsAPIForPartitionRegion() - containsKey() Validations done Successfully in Partition Region " + pr.getName());
                // containsValueForKey
                for (int i = innerStartIndexForKey; i < innerEndIndexForKey; i++) {
                    boolean conKey = pr.containsValueForKey(j + innerprPrefix + i);
                    if (i >= innerStartIndexForDestroy && i < innerEndIndexForDestroy) {
                        assertFalse(conKey);
                    } else {
                        assertTrue(conKey);
                    }
                }
                LogWriterUtils.getLogWriter().info("validateContainsAPIForPartitionRegion() - containsValueForKey() Validations done Successfully in Partition Region " + pr.getName());
                // containsValue
                for (int i = innerStartIndexForKey; i < innerEndIndexForKey; i++) {
                    boolean conKey = pr.containsValue(innerprPrefix + i);
                    if (i >= innerStartIndexForDestroy && i < innerEndIndexForDestroy) {
                        assertFalse(conKey);
                    } else {
                        assertTrue(conKey);
                    }
                }
                LogWriterUtils.getLogWriter().info("validateContainsAPIForPartitionRegion() - containsValue() Validations done Successfully in Partition Region " + pr.getName());
            }
        }
    };
    return validateRegionAPIs;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 73 with Cache

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

the class PartitionedRegionBucketCreationDistributionDUnitTest method testEnforceUniqueHostForLonerDistributedSystem.

/**
   * Added for defect #47181. Use below combination to reproduce the issue: mcast-port = 0 Locators
   * should be empty enforce-unique-host = true redundancy-zone = "zone"
   */
@Test
public void testEnforceUniqueHostForLonerDistributedSystem() {
    Cache myCache = createLonerCacheWithEnforceUniqueHost();
    try {
        AttributesFactory attr = new AttributesFactory();
        PartitionAttributesFactory paf = new PartitionAttributesFactory();
        PartitionAttributes prAttr = paf.create();
        attr.setPartitionAttributes(prAttr);
        RegionAttributes regionAttribs = attr.create();
        Region region = myCache.createRegion("PR1", regionAttribs);
        for (int i = 0; i < 113; i++) {
            region.put("Key_" + i, new Integer(i));
        }
        // verify region size
        assertEquals(113, region.size());
    } finally {
        myCache.close();
        myCache.getDistributedSystem().disconnect();
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 74 with Cache

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

the class PartitionedRegionCreationDUnitTest method getCacheSerializableRunnableForPRPersistence.

/**
   * this function creates partition region with the specified persistence and throws appropriate
   * exception
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRPersistence(final String regionName, final int localMaxMemory, final boolean isPersistent, final boolean expectException) {
    SerializableRunnable createPrRegion1;
    createPrRegion1 = new CacheSerializableRunnable(regionName) {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionedregion = null;
            try {
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                // 0: accessor
                paf.setLocalMaxMemory(localMaxMemory);
                PartitionAttributes prAttr = paf.create();
                attr.setPartitionAttributes(prAttr);
                if (isPersistent) {
                    attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                } else {
                    attr.setDataPolicy(DataPolicy.PARTITION);
                }
                partitionedregion = cache.createRegion(regionName, attr.create());
                if (expectException) {
                    fail("Expect exception but it did not");
                }
                assertNotNull("Partitioned Region " + regionName + " not in cache", cache.getRegion(regionName));
                assertNotNull("Partitioned Region ref null", partitionedregion);
                assertTrue("Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
            } catch (IllegalStateException ex) {
                if (localMaxMemory > 0) {
                    // datastore
                    assertTrue(ex.getMessage().contains("DataPolicy for Datastore members should all be persistent or not."));
                } else {
                    assertTrue(ex.getMessage().contains("Persistence is not allowed when local-max-memory is zero."));
                }
            }
        }
    };
    return (CacheSerializableRunnable) createPrRegion1;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 75 with Cache

use of org.apache.geode.cache.Cache 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)

Aggregations

Cache (org.apache.geode.cache.Cache)1044 Region (org.apache.geode.cache.Region)478 Test (org.junit.Test)476 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)292 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)277 VM (org.apache.geode.test.dunit.VM)264 Host (org.apache.geode.test.dunit.Host)230 AttributesFactory (org.apache.geode.cache.AttributesFactory)229 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)177 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)176 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)164 LocalRegion (org.apache.geode.internal.cache.LocalRegion)153 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)123 ClientCache (org.apache.geode.cache.client.ClientCache)117 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)112 Properties (java.util.Properties)101 CacheException (org.apache.geode.cache.CacheException)101 RegionAttributes (org.apache.geode.cache.RegionAttributes)99 QueryService (org.apache.geode.cache.query.QueryService)95 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)93