Search in sources :

Example 1 with PRHARedundancyProvider

use of org.apache.geode.internal.cache.PRHARedundancyProvider in project geode by apache.

the class RebalanceOperationDUnitTest method testRecoverRedundancyBalancingIfCreateBucketFails.

@Test
public void testRecoverRedundancyBalancingIfCreateBucketFails() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final DistributedMember member1 = createPrRegion(vm0, "region1", 100, null);
    vm0.invoke(new SerializableRunnable("createSomeBuckets") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            for (int i = 0; i < 1; i++) {
                region.put(Integer.valueOf(i), "A");
            }
        }
    });
    SerializableRunnable checkRedundancy = new SerializableRunnable("checkRedundancy") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
            assertEquals(1, details.getCreatedBucketCount());
            assertEquals(0, details.getActualRedundantCopies());
            assertEquals(1, details.getLowRedundancyBucketCount());
        }
    };
    vm0.invoke(checkRedundancy);
    // Now create the region in 2 more VMs
    // Let localMaxMemory(VM1) > localMaxMemory(VM2)
    // so that redundant bucket will always be attempted on VM1
    final DistributedMember member2 = createPrRegion(vm1, "region1", 100, null);
    final DistributedMember member3 = createPrRegion(vm2, "region1", 90, null);
    vm0.invoke(checkRedundancy);
    // Inject mock PRHARedundancyProvider to simulate createBucketFailures
    vm0.invoke(new SerializableRunnable("injectCreateBucketFailureAndRebalance") {

        @Override
        public void run() {
            GemFireCacheImpl cache = spy(getGemfireCache());
            // set the spied cache instance
            GemFireCacheImpl origCache = GemFireCacheImpl.setInstanceForTests(cache);
            PartitionedRegion origRegion = (PartitionedRegion) cache.getRegion("region1");
            PartitionedRegion spyRegion = spy(origRegion);
            PRHARedundancyProvider redundancyProvider = spy(new PRHARedundancyProvider(spyRegion));
            // return the spied region when ever getPartitionedRegions() is invoked
            Set<PartitionedRegion> parRegions = cache.getPartitionedRegions();
            parRegions.remove(origRegion);
            parRegions.add(spyRegion);
            doReturn(parRegions).when(cache).getPartitionedRegions();
            doReturn(redundancyProvider).when(spyRegion).getRedundancyProvider();
            // simulate create bucket fails on member2 and test if it creates on member3
            doReturn(false).when(redundancyProvider).createBackupBucketOnMember(anyInt(), eq((InternalDistributedMember) member2), anyBoolean(), anyBoolean(), any(), anyBoolean());
            // Now simulate a rebalance
            // Create operationImpl and not factory as we need spied cache to be passed to operationImpl
            RegionFilter filter = new FilterByPath(null, null);
            RebalanceOperationImpl operation = new RebalanceOperationImpl(cache, false, filter);
            operation.start();
            RebalanceResults results = null;
            try {
                results = operation.getResults(MAX_WAIT, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Assert.fail("Interrupted waiting on rebalance", e);
            } catch (TimeoutException e) {
                Assert.fail("Timeout waiting on rebalance", e);
            }
            assertEquals(1, results.getTotalBucketCreatesCompleted());
            assertEquals(0, results.getTotalPrimaryTransfersCompleted());
            assertEquals(0, results.getTotalBucketTransferBytes());
            assertEquals(0, results.getTotalBucketTransfersCompleted());
            Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
            assertEquals(1, detailSet.size());
            PartitionRebalanceInfo details = detailSet.iterator().next();
            assertEquals(1, details.getBucketCreatesCompleted());
            assertEquals(0, details.getPrimaryTransfersCompleted());
            assertEquals(0, details.getBucketTransferBytes());
            assertEquals(0, details.getBucketTransfersCompleted());
            Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
            assertEquals(3, afterDetails.size());
            for (PartitionMemberInfo memberDetails : afterDetails) {
                if (memberDetails.getDistributedMember().equals(member1)) {
                    assertEquals(1, memberDetails.getBucketCount());
                    assertEquals(1, memberDetails.getPrimaryCount());
                } else if (memberDetails.getDistributedMember().equals(member2)) {
                    assertEquals(0, memberDetails.getBucketCount());
                    assertEquals(0, memberDetails.getPrimaryCount());
                } else if (memberDetails.getDistributedMember().equals(member3)) {
                    assertEquals(1, memberDetails.getBucketCount());
                    assertEquals(0, memberDetails.getPrimaryCount());
                }
            }
            ResourceManagerStats stats = cache.getInternalResourceManager().getStats();
            assertEquals(0, stats.getRebalancesInProgress());
            assertEquals(1, stats.getRebalancesCompleted());
            assertEquals(0, stats.getRebalanceBucketCreatesInProgress());
            assertEquals(results.getTotalBucketCreatesCompleted(), stats.getRebalanceBucketCreatesCompleted());
            assertEquals(1, stats.getRebalanceBucketCreatesFailed());
            // set the original cache
            GemFireCacheImpl.setInstanceForTests(origCache);
        }
    });
    SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkLowRedundancy") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
            assertEquals(1, details.getCreatedBucketCount());
            assertEquals(1, details.getActualRedundantCopies());
            assertEquals(0, details.getLowRedundancyBucketCount());
        }
    };
    vm0.invoke(checkRedundancyFixed);
    vm1.invoke(checkRedundancyFixed);
    vm2.invoke(checkRedundancyFixed);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) Host(org.apache.geode.test.dunit.Host) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) PRHARedundancyProvider(org.apache.geode.internal.cache.PRHARedundancyProvider) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache) TimeoutException(java.util.concurrent.TimeoutException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 2 with PRHARedundancyProvider

use of org.apache.geode.internal.cache.PRHARedundancyProvider 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)

Aggregations

HashSet (java.util.HashSet)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 PRHARedundancyProvider (org.apache.geode.internal.cache.PRHARedundancyProvider)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 Test (org.junit.Test)2 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 TimeoutException (java.util.concurrent.TimeoutException)1 Cache (org.apache.geode.cache.Cache)1 Region (org.apache.geode.cache.Region)1 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)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 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)1 InternalPRInfo (org.apache.geode.internal.cache.partitioned.InternalPRInfo)1