use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class IndexCommandsDUnitTest method createParRegWithPersistence.
private Region<?, ?> createParRegWithPersistence(String regionName, String diskStoreName, String diskDirName) {
Cache cache = getCache();
File diskStoreDirFile = new File(diskDirName);
diskStoreDirFile.deleteOnExit();
if (!diskStoreDirFile.exists()) {
diskStoreDirFile.mkdirs();
}
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
diskStoreFactory.setMaxOplogSize(1);
diskStoreFactory.setAllowForceCompaction(true);
diskStoreFactory.setAutoCompact(false);
diskStoreFactory.create(diskStoreName);
/****
* Eviction Attributes
*/
EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(diskStoreName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
regionFactory.setEvictionAttributes(ea);
return regionFactory.create(regionName);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class MemberCommandsDUnitTest method createPartitionedRegion.
private void createPartitionedRegion(String regionName) {
final Cache cache = getCache();
// Create the data region
RegionFactory<String, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
dataRegionFactory.setConcurrencyLevel(4);
EvictionAttributes ea = EvictionAttributes.createLIFOEntryAttributes(100, EvictionAction.LOCAL_DESTROY);
dataRegionFactory.setEvictionAttributes(ea);
dataRegionFactory.setEnableAsyncConflation(true);
FixedPartitionAttributes fpa = FixedPartitionAttributes.createFixedPartition("Par1", true);
PartitionAttributes pa = new PartitionAttributesFactory().setLocalMaxMemory(100).setRecoveryDelay(2).setTotalMaxMemory(200).setRedundantCopies(1).addFixedPartitionAttributes(fpa).create();
dataRegionFactory.setPartitionAttributes(pa);
dataRegionFactory.create(regionName);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class QueryMonitorDUnitTest method createRegion.
private void createRegion(final boolean eviction, final String dirName) {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setDataPolicy(DataPolicy.REPLICATE);
// setting the eviction attributes.
if (eviction) {
File[] f = new File[1];
f[0] = new File(dirName);
f[0].mkdir();
DiskStoreFactory dsf = GemFireCacheImpl.getInstance().createDiskStoreFactory();
DiskStore ds1 = dsf.setDiskDirs(f).create("ds1");
factory.setDiskStoreName("ds1");
EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK);
factory.setEvictionAttributes(evictAttrs);
}
// Create region
createRegion(exampleRegionName, factory.create());
createRegion(exampleRegionName2, factory.create());
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class HARegionJUnitTest method testEventIdSetForEvictDestroy.
/**
* Test to verify event id exists when evict destroy happens.
*/
@Test
public void testEventIdSetForEvictDestroy() throws Exception {
AttributesFactory factory = new AttributesFactory();
factory.setCacheListener(new CacheListenerAdapter() {
public void afterDestroy(EntryEvent event) {
assertTrue("eventId has not been set for " + event, ((EntryEventImpl) event).getEventId() != null);
}
});
EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.LOCAL_DESTROY);
factory.setEvictionAttributes(evAttr);
RegionAttributes attrs = factory.createRegionAttributes();
Region region = cache.createVMRegion("TEST_REGION", attrs);
region.put("key1", "value1");
region.put("key2", "value2");
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testDiskStoreValidation.
@Test
public void testDiskStoreValidation() throws Exception {
CacheCreation cache = new CacheCreation();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
DiskStore ds1 = dsf.create(getUniqueName());
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setDataPolicy(DataPolicy.REPLICATE);
attrs.setDiskStoreName(getUniqueName());
RegionCreation root;
try {
root = (RegionCreation) cache.createRegion("root", attrs);
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString()));
}
EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1000, EvictionAction.OVERFLOW_TO_DISK);
attrs.setEvictionAttributes(ea);
root = (RegionCreation) cache.createRegion("root", attrs);
File dir = new File("testDiskStoreValidation");
dir.mkdir();
dir.deleteOnExit();
File[] dirs2 = new File[] { dir, new File("").getAbsoluteFile() };
try {
AttributesFactory factory = new AttributesFactory();
factory.setDiskDirs(dirs2);
factory.setDiskStoreName(getUniqueName());
RegionAttributes ra = factory.create();
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1.toLocalizedString("setDiskDirs or setDiskWriteAttributes", getUniqueName())));
}
try {
AttributesFactory factory = new AttributesFactory();
factory.setDiskStoreName(getUniqueName());
factory.setDiskDirs(dirs2);
RegionAttributes ra = factory.create();
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1.toLocalizedString("setDiskDirs", getUniqueName())));
}
testXml(cache);
}
Aggregations