Search in sources :

Example 1 with LoadProbe

use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.

the class RebalanceOperationDUnitTest method setLoadProbe.

private LoadProbe setLoadProbe(VM vm, final LoadProbe probe) {
    LoadProbe oldProbe = (LoadProbe) vm.invoke(new SerializableCallable("set load probe") {

        public Object call() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            InternalResourceManager mgr = cache.getInternalResourceManager();
            return mgr.setLoadProbe(probe);
        }
    });
    return oldProbe;
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LoadProbe(org.apache.geode.internal.cache.partitioned.LoadProbe) BucketCountLoadProbe(org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe)

Example 2 with LoadProbe

use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.

the class RebalanceOperationDUnitTest method balanceBucketsByCount.

/**
   * Check to make sure that we balance buckets between two hosts with no redundancy.
   * 
   * @param simulate
   */
public void balanceBucketsByCount(final boolean simulate) {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    LoadProbe oldProbe = setLoadProbe(vm0, new BucketCountLoadProbe());
    try {
        SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {

            public void run() {
                Cache cache = getCache();
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(0);
                paf.setRecoveryDelay(-1);
                paf.setStartupRecoveryDelay(-1);
                PartitionAttributes prAttr = paf.create();
                attr.setPartitionAttributes(prAttr);
                attr.setCacheLoader(new Bug40228Loader());
                cache.createRegion("region1", attr.create());
            }
        };
        // Create the region in only 1 VM
        vm0.invoke(createPrRegion);
        // Create some buckets with very uneven sizes
        vm0.invoke(new SerializableRunnable("createSomeBuckets") {

            public void run() {
                Cache cache = getCache();
                Region region = cache.getRegion("region1");
                region.put(Integer.valueOf(1), new byte[1024 * 1024]);
                region.put(Integer.valueOf(2), "A");
                region.put(Integer.valueOf(3), "A");
                region.put(Integer.valueOf(4), "A");
                region.put(Integer.valueOf(5), "A");
                region.put(Integer.valueOf(6), "A");
            }
        });
        // Create the region in the other VM (should have no effect)
        vm1.invoke(createPrRegion);
        // Now simulate a rebalance
        vm0.invoke(new SerializableRunnable("simulateRebalance") {

            public void run() {
                Cache cache = getCache();
                ResourceManager manager = cache.getResourceManager();
                RebalanceResults results = doRebalance(simulate, manager);
                assertEquals(0, results.getTotalBucketCreatesCompleted());
                assertEquals(0, results.getTotalPrimaryTransfersCompleted());
                assertEquals(3, results.getTotalBucketTransfersCompleted());
                assertTrue(0 < results.getTotalBucketTransferBytes());
                Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
                assertEquals(1, detailSet.size());
                PartitionRebalanceInfo details = detailSet.iterator().next();
                assertEquals(0, details.getBucketCreatesCompleted());
                assertEquals(0, details.getPrimaryTransfersCompleted());
                assertTrue(0 < details.getBucketTransferBytes());
                assertEquals(3, details.getBucketTransfersCompleted());
                Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
                assertEquals(2, afterDetails.size());
                for (PartitionMemberInfo memberDetails : afterDetails) {
                    assertEquals(3, memberDetails.getBucketCount());
                    assertEquals(3, memberDetails.getPrimaryCount());
                }
                if (!simulate) {
                    verifyStats(manager, results);
                }
            }
        });
        if (!simulate) {
            SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkRedundancyFixed") {

                public void run() {
                    Cache cache = getCache();
                    Region region = cache.getRegion("region1");
                    PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
                    assertEquals(6, details.getCreatedBucketCount());
                    assertEquals(0, details.getActualRedundantCopies());
                    assertEquals(0, details.getLowRedundancyBucketCount());
                    assertEquals(2, details.getPartitionMemberInfo().size());
                    for (PartitionMemberInfo memberDetails : details.getPartitionMemberInfo()) {
                        assertEquals(3, memberDetails.getBucketCount());
                        assertEquals(3, memberDetails.getPrimaryCount());
                    }
                    // check to make sure that moving buckets didn't close the cache loader
                    Bug40228Loader loader = (Bug40228Loader) cache.getRegion("region1").getAttributes().getCacheLoader();
                    assertFalse(loader.isClosed());
                }
            };
            vm0.invoke(checkRedundancyFixed);
            vm1.invoke(checkRedundancyFixed);
        }
    } finally {
        setLoadProbe(vm0, oldProbe);
    }
}
Also used : BucketCountLoadProbe(org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) Host(org.apache.geode.test.dunit.Host) ResourceManager(org.apache.geode.cache.control.ResourceManager) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) LoadProbe(org.apache.geode.internal.cache.partitioned.LoadProbe) BucketCountLoadProbe(org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache)

Example 3 with LoadProbe

use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.

the class AutoBalancerJUnitTest method testFacadeCollectMemberDetails2Regions.

@Test
@Ignore("GEODE-2789: need to rewrite this test")
public void testFacadeCollectMemberDetails2Regions() {
    final GemFireCacheImpl mockCache = mockContext.mock(GemFireCacheImpl.class);
    final InternalResourceManager mockRM = mockContext.mock(InternalResourceManager.class);
    final LoadProbe mockProbe = mockContext.mock(LoadProbe.class);
    final PartitionedRegion mockR1 = mockContext.mock(PartitionedRegion.class, "r1");
    final PartitionedRegion mockR2 = mockContext.mock(PartitionedRegion.class, "r2");
    final HashSet<PartitionedRegion> regions = new HashSet<>();
    regions.add(mockR1);
    regions.add(mockR2);
    final PRHARedundancyProvider mockRedundancyProviderR1 = mockContext.mock(PRHARedundancyProvider.class, "prhaR1");
    final InternalPRInfo mockR1PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR1");
    final PRHARedundancyProvider mockRedundancyProviderR2 = mockContext.mock(PRHARedundancyProvider.class, "prhaR2");
    final InternalPRInfo mockR2PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR2");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).isClosed();
            will(returnValue(false));
            oneOf(mockCache).getPartitionedRegions();
            will(returnValue(regions));
            exactly(2).of(mockCache).getResourceManager();
            will(returnValue(mockRM));
            exactly(2).of(mockRM).getLoadProbe();
            will(returnValue(mockProbe));
            allowing(mockR1).getFullPath();
            oneOf(mockR1).getRedundancyProvider();
            will(returnValue(mockRedundancyProviderR1));
            allowing(mockR2).getFullPath();
            oneOf(mockR2).getRedundancyProvider();
            will(returnValue(mockRedundancyProviderR2));
            oneOf(mockRedundancyProviderR1).buildPartitionedRegionInfo(with(true), with(any(LoadProbe.class)));
            will(returnValue(mockR1PRInfo));
            oneOf(mockRedundancyProviderR2).buildPartitionedRegionInfo(with(true), with(any(LoadProbe.class)));
            will(returnValue(mockR2PRInfo));
        }
    });
    GeodeCacheFacade facade = new GeodeCacheFacade(mockCache);
    Map<PartitionedRegion, InternalPRInfo> map = facade.getRegionMemberDetails();
    assertNotNull(map);
    assertEquals(2, map.size());
    assertEquals(map.get(mockR1), mockR1PRInfo);
    assertEquals(map.get(mockR2), mockR2PRInfo);
}
Also used : InternalPRInfo(org.apache.geode.internal.cache.partitioned.InternalPRInfo) Expectations(org.jmock.Expectations) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PRHARedundancyProvider(org.apache.geode.internal.cache.PRHARedundancyProvider) GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LoadProbe(org.apache.geode.internal.cache.partitioned.LoadProbe) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with LoadProbe

use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.

the class InternalResourceManager method setLoadProbe.

/**
   * This method is test purposes only.
   */
public LoadProbe setLoadProbe(LoadProbe probe) {
    LoadProbe old = this.loadProbe;
    this.loadProbe = probe;
    return old;
}
Also used : LoadProbe(org.apache.geode.internal.cache.partitioned.LoadProbe) SizedBasedLoadProbe(org.apache.geode.internal.cache.partitioned.SizedBasedLoadProbe)

Aggregations

LoadProbe (org.apache.geode.internal.cache.partitioned.LoadProbe)4 HashSet (java.util.HashSet)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 BucketCountLoadProbe (org.apache.geode.internal.cache.partitioned.BucketCountLoadProbe)2 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 Cache (org.apache.geode.cache.Cache)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)1 ResourceManager (org.apache.geode.cache.control.ResourceManager)1 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)1 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)1 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)1 GeodeCacheFacade (org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 PRHARedundancyProvider (org.apache.geode.internal.cache.PRHARedundancyProvider)1