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);
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations