use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUEntry_AccessorFirst.
@Test
public void testEvictionValidationForLRUEntry_AccessorFirst() {
final Host host = Host.getHost(0);
final VM firstAccessor = host.getVM(0);
final VM testAccessor = host.getVM(1);
final VM testDatastore = host.getVM(2);
final VM firstDatastore = host.getVM(3);
final String uniqName = getUniqueName();
final int redundantCopies = 1;
final int maxEntries = 226;
final String name = uniqName + "-PR";
final EvictionAttributes firstEvictionAttrs = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
final EvictionAttributes secondEvictionAttrs = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.OVERFLOW_TO_DISK);
final SerializableRunnable createFirstAccessor = new CacheSerializableRunnable("Create an accessor without eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createFirstDataStore = new CacheSerializableRunnable("Create a data store with eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createSecondAccessor = new CacheSerializableRunnable("Create an accessor with incorrect eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(secondEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createSecondDataStore = new CacheSerializableRunnable("Create a data store with eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
firstAccessor.invoke(createFirstAccessor);
firstDatastore.invoke(createFirstDataStore);
testAccessor.invoke(createSecondAccessor);
testDatastore.invoke(createSecondDataStore);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUEntry_DatastoreFirst.
@Test
public void testEvictionValidationForLRUEntry_DatastoreFirst() {
final Host host = Host.getHost(0);
final VM firstAccessor = host.getVM(0);
final VM testAccessor = host.getVM(1);
final VM testDatastore = host.getVM(2);
final VM firstDatastore = host.getVM(3);
final String uniqName = getUniqueName();
final int redundantCopies = 1;
final int maxEntries = 226;
final String name = uniqName + "-PR";
final EvictionAttributes firstEvictionAttrs = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
final EvictionAttributes secondEvictionAttrs = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.OVERFLOW_TO_DISK);
final SerializableRunnable createFirstAccessor = new CacheSerializableRunnable("Create an accessor without eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createFirstDataStore = new CacheSerializableRunnable("Create a data store with eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createSecondAccessor = new CacheSerializableRunnable("Create an accessor with incorrect eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(secondEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createSecondDataStore = new CacheSerializableRunnable("Create a data store with eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
firstDatastore.invoke(createFirstDataStore);
firstAccessor.invoke(createFirstAccessor);
testDatastore.invoke(createSecondDataStore);
testAccessor.invoke(createSecondAccessor);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEvictionValidationWhenInitializedByAccessor.
// Test to validate an accessor can set the initial attributes
@Test
public void testEvictionValidationWhenInitializedByAccessor() {
final Host host = Host.getHost(0);
final VM testDatastore = host.getVM(2);
final VM accessor = host.getVM(3);
final String uniqName = getUniqueName();
final int redundantCopies = 1;
final String name = uniqName;
final EvictionAttributes firstEvictionAttributes = EvictionAttributes.createLRUMemoryAttributes(PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT);
accessor.invoke(new CacheSerializableRunnable("Create an Accessor which sets the first PR eviction attrs") {
public void run2() {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setLocalMaxMemory(0).setRedundantCopies(redundantCopies).create());
factory.setEvictionAttributes(firstEvictionAttributes);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
assertNotSame(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
assertEquals(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
assertEquals(PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT, pr.getAttributes().getEvictionAttributes().getMaximum());
}
});
testDatastore.invoke(new SerializableRunnable("Create a datastore to test existing eviction attributes") {
public void run() {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
// Assert that the same attrs is valid
factory.setEvictionAttributes(firstEvictionAttributes);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
assertNotSame(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
assertNotSame(PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT, pr.getAttributes().getEvictionAttributes().getMaximum());
assertEquals(pr.getAttributes().getPartitionAttributes().getLocalMaxMemory(), pr.getAttributes().getEvictionAttributes().getMaximum());
}
});
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUEntry_TwoAccessors.
@Test
public void testEvictionValidationForLRUEntry_TwoAccessors() {
final Host host = Host.getHost(0);
final VM firstAccessor = host.getVM(0);
final VM testAccessor = host.getVM(1);
final VM testDatastore = host.getVM(2);
final VM firstDatastore = host.getVM(3);
final String uniqName = getUniqueName();
final int redundantCopies = 1;
final int maxEntries = 226;
final String name = uniqName + "-PR";
final EvictionAttributes firstEvictionAttrs = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
final SerializableRunnable createFirstAccessor = new CacheSerializableRunnable("Create an accessor without eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createFirstDataStore = new CacheSerializableRunnable("Create a data store with eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createSecondAccessor = new CacheSerializableRunnable("Create an accessor with correct eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
final SerializableRunnable createSecondDataStore = new CacheSerializableRunnable("Create a data store with eviction attributes") {
public void run2() {
final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(pra);
factory.setEvictionAttributes(firstEvictionAttrs);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
firstAccessor.invoke(createFirstAccessor);
testAccessor.invoke(createSecondAccessor);
firstDatastore.invoke(createFirstDataStore);
testDatastore.invoke(createSecondDataStore);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUHeap.
// Test to validate the Eviction Attribute for LRUHeap
@Test
public void testEvictionValidationForLRUHeap() {
final Host host = Host.getHost(0);
final VM testDatastore = host.getVM(2);
final VM firstDatastore = host.getVM(3);
final String uniqName = getUniqueName();
final int redundantCopies = 1;
final String name = uniqName + "-PR";
final int heapPercentage = 66;
final int evictorInterval = 100;
final EvictionAttributes firstEvictionAttributes = EvictionAttributes.createLRUHeapAttributes();
// Creating Heap LRU Eviction Attribute : evictorInterval : 100
final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {
public void run2() {
getCache().getResourceManager().setEvictionHeapPercentage(heapPercentage);
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
factory.setEvictionAttributes(firstEvictionAttributes);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
assertEquals(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
}
};
firstDatastore.invoke(create);
final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with Overflow to disk partitioned Region") {
public void run() {
setEvictionPercentage(heapPercentage);
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
// Assert that a different algo is invalid
try {
getCache().getLogger().info("<ExpectedException action=add>" + "IllegalStateException</ExpectedException>");
assertTrue(!firstEvictionAttributes.getAlgorithm().isLRUEntry());
final EvictionAttributes invalidEa = EvictionAttributes.createLRUEntryAttributes();
assertTrue(!invalidEa.equals(firstEvictionAttributes));
factory.setEvictionAttributes(invalidEa);
createRootRegion(name, factory.create());
fail("Expected an IllegalStateException");
} catch (final IllegalStateException expected) {
assertTrue(expected.getMessage().contains(PartitionRegionConfigValidator.EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE));
} finally {
getCache().getLogger().info("<ExpectedException action=remove>" + "IllegalStateException</ExpectedException>");
}
// Assert that a different action is invalid
try {
getCache().getLogger().info("<ExpectedException action=add>" + "IllegalStateException</ExpectedException>");
assertTrue(firstEvictionAttributes.getAlgorithm().isLRUHeap());
assertTrue(!firstEvictionAttributes.getAction().isOverflowToDisk());
final EvictionAttributes invalidEa = EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK);
assertTrue(!invalidEa.equals(firstEvictionAttributes));
factory.setEvictionAttributes(invalidEa);
createRootRegion(name, factory.create());
fail("Expected an IllegalStateException");
} catch (final IllegalStateException expected) {
assertTrue(expected.getMessage().contains(PartitionRegionConfigValidator.EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE));
} finally {
getCache().getLogger().info("<ExpectedException action=remove>" + "IllegalStateException</ExpectedException>");
}
// Assert that a different interval is valid
// {
// assertTrue(firstEvictionAttributes.getAlgorithm().isLRUHeap());
// final EvictionAttributes okHeapLRUea = EvictionAttributes
// .createLRUHeapAttributes((int)(firstEvictionAttributes.getInterval() + 100),
// firstEvictionAttributes.getAction());
// factory.setEvictionAttributes(okHeapLRUea);
// final Region pr = createRootRegion(name, factory.create());
// assertNotNull(pr);
// assertIndexDetailsEquals(okHeapLRUea, pr.getAttributes().getEvictionAttributes());
// pr.localDestroyRegion();
// }
// Assert that a different maximum is valid
// {
// assertTrue(firstEvictionAttributes.getAlgorithm().isLRUHeap());
// final EvictionAttributes okHeapLRUea = EvictionAttributes
// .createLRUHeapAttributes(
// (int)firstEvictionAttributes.getInterval(),
// firstEvictionAttributes.getAction());
// factory.setEvictionAttributes(okHeapLRUea);
// final Region pr = createRootRegion(name, factory.create());
// assertNotNull(pr);
// assertIndexDetailsEquals(okHeapLRUea, pr.getAttributes().getEvictionAttributes());
// pr.localDestroyRegion();
// }
// Assert that all attributes can be the same
{
factory.setEvictionAttributes(firstEvictionAttributes);
final Region pr = createRootRegion(name, factory.create());
assertNotNull(pr);
assertEquals(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
}
}
};
testDatastore.invoke(create2);
}
Aggregations