Search in sources :

Example 31 with EvictionAttributes

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);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 32 with EvictionAttributes

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);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 33 with EvictionAttributes

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...
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes)

Example 34 with EvictionAttributes

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;
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) ObjectSizer(org.apache.geode.cache.util.ObjectSizer)

Example 35 with EvictionAttributes

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);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) Expectations(org.jmock.Expectations) EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) InternalCache(org.apache.geode.internal.cache.InternalCache) Region(org.apache.geode.cache.Region) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

EvictionAttributes (org.apache.geode.cache.EvictionAttributes)41 AttributesFactory (org.apache.geode.cache.AttributesFactory)25 Region (org.apache.geode.cache.Region)24 Test (org.junit.Test)24 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)21 RegionAttributes (org.apache.geode.cache.RegionAttributes)17 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)11 Host (org.apache.geode.test.dunit.Host)10 VM (org.apache.geode.test.dunit.VM)10 Cache (org.apache.geode.cache.Cache)9 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)7 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)6 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)6 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)6 File (java.io.File)5