use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testReplicatedRegionAttributesForMemLruWithoutMaxMem.
@Test
public void testReplicatedRegionAttributesForMemLruWithoutMaxMem() throws Exception {
final int redundantCopies = 1;
CacheCreation cache = new CacheCreation();
AttributesFactory fac = new AttributesFactory();
fac.setDataPolicy(DataPolicy.REPLICATE);
fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(null, EvictionAction.OVERFLOW_TO_DISK));
cache.createRegion("parRoot", fac.create());
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("parRoot");
assertNotNull(region);
RegionAttributes regionAttrs = region.getAttributes();
EvictionAttributes ea = regionAttrs.getEvictionAttributes();
assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK);
assertEquals(ea.getMaximum(), MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testReplicatedRegionAttributesForMemLruWithMaxMem.
@Test
public void testReplicatedRegionAttributesForMemLruWithMaxMem() throws Exception {
final int redundantCopies = 1;
final int maxMem = 25;
CacheCreation cache = new CacheCreation();
AttributesFactory fac = new AttributesFactory();
fac.setDataPolicy(DataPolicy.REPLICATE);
fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(maxMem, null, EvictionAction.OVERFLOW_TO_DISK));
cache.createRegion("parRoot", fac.create());
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("parRoot");
assertNotNull(region);
RegionAttributes regionAttrs = region.getAttributes();
EvictionAttributes ea = regionAttrs.getEvictionAttributes();
assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK);
assertEquals(ea.getMaximum(), maxMem);
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class PartitionRegionConfigValidator method validateDistributedEvictionAttributes.
/**
* The 2nd step of Eviction Attributes validation to ensure that all VMs are reasonably similar to
* prevent weird config. issues.
*
* @param prconfEa the eviction attributes currently used by other VMs
* @see AttributesFactory#validateAttributes(RegionAttributes)
* @see #validateEvictionAttributesAgainstLocalMaxMemory()
*/
private void validateDistributedEvictionAttributes(final EvictionAttributes prconfEa) {
final EvictionAttributes ea = pr.getAttributes().getEvictionAttributes();
// there is no such thing as null EvictionAttributes, assert that is true
Assert.assertTrue(ea != null);
Assert.assertTrue(prconfEa != null);
// Enforce that all VMs with this PR have the same Eviction Attributes
// Even an accessor should do this to stay consistent with all other
// accessor validation/enforcement
// *and* because an accessor can set the first/global eviction attributes
// If this is an accessor with Evicitonttributes, log an info message
// indicating that no eviction will
// occur in this VM (duh)
// Further validation should occur for datastores to ensure consistent
// behavior wrt local max memory and
// total number of buckets
final boolean equivAlgoAndAction = ea.getAlgorithm().equals(prconfEa.getAlgorithm()) && ea.getAction().equals(prconfEa.getAction());
if (!equivAlgoAndAction) {
throw new IllegalStateException("For Partitioned Region " + pr.getFullPath() + " the configured EvictionAttributes " + ea + EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE + prconfEa);
} else {
// but allow the configuration.
if (ea.getAction().isLocalDestroy()) {
// LRUHeap doesn't support maximum, but other eviction algos do
if (!ea.getAlgorithm().isLRUHeap() && ea.getMaximum() != prconfEa.getMaximum()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_0_EVICTIONATTRIBUTES_1_DO_NOT_MATCH_WITH_OTHER_2, new Object[] { pr.getFullPath(), ea, prconfEa }));
}
}
}
// end Same algo, action...
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class LocalRegion method getObjectSizer.
/**
* Returns the object sizer on this region or null if it has no sizer.
*
* @since GemFire 6.1.2.9
*/
public ObjectSizer getObjectSizer() {
ObjectSizer result = null;
EvictionAttributes ea = getEvictionAttributes();
if (ea != null) {
result = ea.getObjectSizer();
}
return result;
}
use of org.apache.geode.cache.EvictionAttributes in project geode by apache.
the class DescribeDiskStoreFunctionJUnitTest method testSetRegionDetails.
@Test
public void testSetRegionDetails() {
final String diskStoreName = "companyDiskStore";
final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
final Region mockCompanyRegion = mockContext.mock(Region.class, "/CompanyRegion");
final Region mockContractorsRegion = mockContext.mock(Region.class, "/CompanyRegion/ContractorsRegion");
final Region mockEmployeeRegion = mockContext.mock(Region.class, "/CompanyRegion/EmployeeRegion");
final Region mockRolesRegion = mockContext.mock(Region.class, "/CompanyRegion/EmployeeRegion/RolesRegion");
final Region mockProductsRegion = mockContext.mock(Region.class, "/CompanyRegion/ProductsRegion");
final Region mockServicesRegion = mockContext.mock(Region.class, "/CompanyRegion/ServicesRegion");
final Region mockPartnersRegion = mockContext.mock(Region.class, "/PartnersRegion");
final Region mockCustomersRegion = mockContext.mock(Region.class, "/CustomersRegion");
final RegionAttributes mockCompanyRegionAttributes = mockContext.mock(RegionAttributes.class, "CompanyRegionAttributes");
final RegionAttributes mockContractorsRegionAttributes = mockContext.mock(RegionAttributes.class, "ContractorsRegionAttributes");
final RegionAttributes mockProductsServicesRegionAttributes = mockContext.mock(RegionAttributes.class, "ProductsServicesRegionAttributes");
final RegionAttributes mockPartnersRegionAttributes = mockContext.mock(RegionAttributes.class, "PartnersRegionAttributes");
final RegionAttributes mockCustomersRegionAttributes = mockContext.mock(RegionAttributes.class, "CustomersRegionAttributes");
final EvictionAttributes mockCompanyEvictionAttributes = mockContext.mock(EvictionAttributes.class, "CompanyEvictionAttributes");
final EvictionAttributes mockContractorsEvictionAttributes = mockContext.mock(EvictionAttributes.class, "ContractorsEvictionAttributes");
final EvictionAttributes mockCustomersEvictionAttributes = mockContext.mock(EvictionAttributes.class, "CustomersEvictionAttributes");
final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).rootRegions();
will(returnValue(CollectionUtils.asSet(mockCompanyRegion, mockPartnersRegion, mockCustomersRegion)));
exactly(5).of(mockCompanyRegion).getAttributes();
will(returnValue(mockCompanyRegionAttributes));
oneOf(mockCompanyRegion).getFullPath();
will(returnValue("/CompanyRegion"));
oneOf(mockCompanyRegion).getName();
will(returnValue("CompanyRegion"));
oneOf(mockCompanyRegion).subregions(false);
will(returnValue(CollectionUtils.asSet(mockContractorsRegion, mockEmployeeRegion, mockProductsRegion, mockServicesRegion)));
exactly(5).of(mockEmployeeRegion).getAttributes();
will(returnValue(mockCompanyRegionAttributes));
oneOf(mockEmployeeRegion).getFullPath();
will(returnValue("/CompanyRegion/EmployeeRegion"));
oneOf(mockEmployeeRegion).getName();
will(returnValue("EmployeeRegion"));
oneOf(mockEmployeeRegion).subregions(false);
will(returnValue(CollectionUtils.asSet(mockRolesRegion)));
exactly(5).of(mockRolesRegion).getAttributes();
will(returnValue(mockCompanyRegionAttributes));
oneOf(mockRolesRegion).getFullPath();
will(returnValue("/CompanyRegion/EmployeeRegion/RolesRegion"));
oneOf(mockRolesRegion).getName();
will(returnValue("RolesRegion"));
oneOf(mockRolesRegion).subregions(false);
will(returnValue(Collections.emptySet()));
exactly(6).of(mockCompanyRegionAttributes).getDataPolicy();
will(returnValue(DataPolicy.PERSISTENT_PARTITION));
exactly(3).of(mockCompanyRegionAttributes).getDiskStoreName();
will(returnValue(diskStoreName));
exactly(6).of(mockCompanyRegionAttributes).getEvictionAttributes();
will(returnValue(mockCompanyEvictionAttributes));
exactly(3).of(mockCompanyEvictionAttributes).getAction();
will(returnValue(EvictionAction.LOCAL_DESTROY));
exactly(7).of(mockContractorsRegion).getAttributes();
will(returnValue(mockContractorsRegionAttributes));
oneOf(mockContractorsRegion).getFullPath();
will(returnValue("/CompanyRegion/ContractorsRegion"));
oneOf(mockContractorsRegion).getName();
will(returnValue("ContractorsRegion"));
oneOf(mockContractorsRegion).subregions(false);
will(returnValue(Collections.emptySet()));
exactly(2).of(mockContractorsRegionAttributes).getDataPolicy();
will(returnValue(DataPolicy.REPLICATE));
oneOf(mockContractorsRegionAttributes).getDiskStoreName();
will(returnValue(diskStoreName));
exactly(4).of(mockContractorsRegionAttributes).getEvictionAttributes();
will(returnValue(mockContractorsEvictionAttributes));
exactly(2).of(mockContractorsEvictionAttributes).getAction();
will(returnValue(EvictionAction.OVERFLOW_TO_DISK));
exactly(2).of(mockProductsRegion).getAttributes();
will(returnValue(mockProductsServicesRegionAttributes));
oneOf(mockProductsRegion).subregions(false);
will(returnValue(Collections.emptySet()));
exactly(2).of(mockServicesRegion).getAttributes();
will(returnValue(mockProductsServicesRegionAttributes));
oneOf(mockServicesRegion).subregions(false);
will(returnValue(Collections.emptySet()));
exactly(2).of(mockProductsServicesRegionAttributes).getDataPolicy();
will(returnValue(DataPolicy.PERSISTENT_REPLICATE));
exactly(2).of(mockProductsServicesRegionAttributes).getDiskStoreName();
will(returnValue("productsServicesDiskStore"));
exactly(2).of(mockPartnersRegion).getAttributes();
will(returnValue(mockPartnersRegionAttributes));
oneOf(mockPartnersRegion).subregions(false);
will(returnValue(Collections.emptySet()));
oneOf(mockPartnersRegionAttributes).getDataPolicy();
will(returnValue(DataPolicy.PERSISTENT_PARTITION));
oneOf(mockPartnersRegionAttributes).getDiskStoreName();
will(returnValue(""));
exactly(4).of(mockCustomersRegion).getAttributes();
will(returnValue(mockCustomersRegionAttributes));
oneOf(mockCustomersRegion).subregions(false);
will(returnValue(Collections.emptySet()));
oneOf(mockCustomersRegionAttributes).getDataPolicy();
will(returnValue(DataPolicy.REPLICATE));
oneOf(mockCustomersRegionAttributes).getDiskStoreName();
will(returnValue(null));
exactly(2).of(mockCustomersRegionAttributes).getEvictionAttributes();
will(returnValue(mockCustomersEvictionAttributes));
oneOf(mockCustomersEvictionAttributes).getAction();
will(returnValue(EvictionAction.OVERFLOW_TO_DISK));
atLeast(1).of(mockDiskStore).getName();
will(returnValue(diskStoreName));
}
});
final Set<DiskStoreDetails.RegionDetails> expectedRegionDetails = CollectionUtils.asSet(createRegionDetails("/CompanyRegion", "CompanyRegion", true, false), createRegionDetails("/CompanyRegion/EmployeeRegion", "EmployeeRegion", true, false), createRegionDetails("/CompanyRegion/EmployeeRegion/RolesRegion", "RolesRegion", true, false), createRegionDetails("/CompanyRegion/ContractorsRegion", "ContractorsRegion", false, true));
final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne");
final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
function.setRegionDetails(mockCache, mockDiskStore, diskStoreDetails);
assertRegionDetails(expectedRegionDetails, diskStoreDetails);
}
Aggregations