Search in sources :

Example 1 with SizeBasedOOBAuditor

use of org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor in project geode by apache.

the class AutoBalancerJUnitTest method testOOBAuditorInit.

@Test
public void testOOBAuditorInit() {
    AutoBalancer balancer = new AutoBalancer();
    balancer.init(getBasicConfig());
    SizeBasedOOBAuditor auditor = (SizeBasedOOBAuditor) balancer.getOOBAuditor();
    assertEquals(AutoBalancer.DEFAULT_SIZE_THRESHOLD_PERCENT, auditor.getSizeThreshold());
    assertEquals(AutoBalancer.DEFAULT_MINIMUM_SIZE, auditor.getSizeMinimum());
    Properties props = getBasicConfig();
    props.put(AutoBalancer.SIZE_THRESHOLD_PERCENT, "17");
    props.put(AutoBalancer.MINIMUM_SIZE, "10");
    balancer = new AutoBalancer();
    balancer.init(props);
    auditor = (SizeBasedOOBAuditor) balancer.getOOBAuditor();
    assertEquals(17, auditor.getSizeThreshold());
    assertEquals(10, auditor.getSizeMinimum());
}
Also used : SizeBasedOOBAuditor(org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with SizeBasedOOBAuditor

use of org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor in project geode by apache.

the class AutoBalancerJUnitTest method testOOBWhenAboveThresholdButBelowMin.

@Test
public void testOOBWhenAboveThresholdButBelowMin() {
    final long totalSize = 1000L;
    mockContext.checking(new Expectations() {

        {
            // first run
            oneOf(mockCacheFacade).getTotalTransferSize();
            // twice threshold
            will(returnValue((AutoBalancer.DEFAULT_SIZE_THRESHOLD_PERCENT * totalSize / 100) * 2));
            // second run
            oneOf(mockCacheFacade).getTotalTransferSize();
            // more than total size
            will(returnValue(2 * totalSize));
        }
    });
    AutoBalancer balancer = new AutoBalancer(null, null, null, mockCacheFacade);
    Properties config = getBasicConfig();
    config.put(AutoBalancer.MINIMUM_SIZE, "" + (totalSize * 5));
    balancer.init(config);
    SizeBasedOOBAuditor auditor = (SizeBasedOOBAuditor) balancer.getOOBAuditor();
    // first run
    assertFalse(auditor.needsRebalancing());
    // second run
    assertFalse(auditor.needsRebalancing());
}
Also used : Expectations(org.jmock.Expectations) SizeBasedOOBAuditor(org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with SizeBasedOOBAuditor

use of org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor in project geode by apache.

the class AutoBalancerJUnitTest method testOOBWhenBelowSizeThreshold.

@Test
public void testOOBWhenBelowSizeThreshold() {
    final long totalSize = 1000L;
    final Map<PartitionedRegion, InternalPRInfo> details = new HashMap<>();
    mockContext.checking(new Expectations() {

        {
            allowing(mockCacheFacade).getRegionMemberDetails();
            will(returnValue(details));
            // first run
            oneOf(mockCacheFacade).getTotalDataSize(details);
            will(returnValue(totalSize));
            oneOf(mockCacheFacade).getTotalTransferSize();
            // half of threshold limit
            will(returnValue((AutoBalancer.DEFAULT_SIZE_THRESHOLD_PERCENT * totalSize / 100) / 2));
            // second run
            oneOf(mockCacheFacade).getTotalTransferSize();
            // nothing to transfer
            will(returnValue(0L));
        }
    });
    AutoBalancer balancer = new AutoBalancer(null, null, null, mockCacheFacade);
    Properties config = getBasicConfig();
    config.put(AutoBalancer.MINIMUM_SIZE, "10");
    balancer.init(config);
    SizeBasedOOBAuditor auditor = (SizeBasedOOBAuditor) balancer.getOOBAuditor();
    // first run
    assertFalse(auditor.needsRebalancing());
    // second run
    assertFalse(auditor.needsRebalancing());
}
Also used : InternalPRInfo(org.apache.geode.internal.cache.partitioned.InternalPRInfo) Expectations(org.jmock.Expectations) SizeBasedOOBAuditor(org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor) HashMap(java.util.HashMap) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with SizeBasedOOBAuditor

use of org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor in project geode by apache.

the class AutoBalancerJUnitTest method testOOBWhenAboveThresholdAndMin.

@Test
public void testOOBWhenAboveThresholdAndMin() {
    final long totalSize = 1000L;
    final Map<PartitionedRegion, InternalPRInfo> details = new HashMap<>();
    mockContext.checking(new Expectations() {

        {
            allowing(mockCacheFacade).getRegionMemberDetails();
            will(returnValue(details));
            // first run
            oneOf(mockCacheFacade).getTotalDataSize(details);
            will(returnValue(totalSize));
            oneOf(mockCacheFacade).getTotalTransferSize();
            // twice threshold
            will(returnValue((AutoBalancer.DEFAULT_SIZE_THRESHOLD_PERCENT * totalSize / 100) * 2));
            // second run
            oneOf(mockCacheFacade).getTotalDataSize(details);
            will(returnValue(totalSize));
            oneOf(mockCacheFacade).getTotalTransferSize();
            // more than total size
            will(returnValue(2 * totalSize));
        }
    });
    AutoBalancer balancer = new AutoBalancer(null, null, null, mockCacheFacade);
    Properties config = getBasicConfig();
    config.put(AutoBalancer.MINIMUM_SIZE, "10");
    balancer.init(config);
    SizeBasedOOBAuditor auditor = (SizeBasedOOBAuditor) balancer.getOOBAuditor();
    // first run
    assertTrue(auditor.needsRebalancing());
    // second run
    assertTrue(auditor.needsRebalancing());
}
Also used : InternalPRInfo(org.apache.geode.internal.cache.partitioned.InternalPRInfo) Expectations(org.jmock.Expectations) SizeBasedOOBAuditor(org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor) HashMap(java.util.HashMap) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Properties (java.util.Properties)4 SizeBasedOOBAuditor (org.apache.geode.cache.util.AutoBalancer.SizeBasedOOBAuditor)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Test (org.junit.Test)4 Expectations (org.jmock.Expectations)3 HashMap (java.util.HashMap)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 InternalPRInfo (org.apache.geode.internal.cache.partitioned.InternalPRInfo)2