Search in sources :

Example 71 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class Fakes method cache.

/**
   * A fake cache, which contains a fake distributed system, distribution manager, etc.
   */
public static GemFireCacheImpl cache() {
    GemFireCacheImpl cache = mock(GemFireCacheImpl.class);
    InternalDistributedSystem system = mock(InternalDistributedSystem.class);
    DistributionConfig config = mock(DistributionConfig.class);
    DistributionManager distributionManager = mock(DistributionManager.class);
    CancelCriterion systemCancelCriterion = mock(CancelCriterion.class);
    DSClock clock = mock(DSClock.class);
    LogWriter logger = mock(LogWriter.class);
    Statistics stats = mock(Statistics.class);
    InternalDistributedMember member;
    member = new InternalDistributedMember("localhost", 5555);
    when(config.getCacheXmlFile()).thenReturn(new File(""));
    when(config.getDeployWorkingDir()).thenReturn(new File("."));
    when(cache.getDistributedSystem()).thenReturn(system);
    when(cache.getInternalDistributedSystem()).thenReturn(system);
    when(cache.getSystem()).thenReturn(system);
    when(cache.getMyId()).thenReturn(member);
    when(cache.getDistributionManager()).thenReturn(distributionManager);
    when(cache.getCancelCriterion()).thenReturn(systemCancelCriterion);
    when(cache.getCachePerfStats()).thenReturn(mock(CachePerfStats.class));
    when(system.getDistributedMember()).thenReturn(member);
    when(system.getConfig()).thenReturn(config);
    when(system.getDistributionManager()).thenReturn(distributionManager);
    when(system.getCancelCriterion()).thenReturn(systemCancelCriterion);
    when(system.getClock()).thenReturn(clock);
    when(system.getLogWriter()).thenReturn(logger);
    when(system.createAtomicStatistics(any(), any(), anyLong())).thenReturn(stats);
    when(system.createAtomicStatistics(any(), any())).thenReturn(stats);
    when(distributionManager.getId()).thenReturn(member);
    when(distributionManager.getDistributionManagerId()).thenReturn(member);
    when(distributionManager.getConfig()).thenReturn(config);
    when(distributionManager.getSystem()).thenReturn(system);
    when(distributionManager.getCancelCriterion()).thenReturn(systemCancelCriterion);
    return cache;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) DSClock(org.apache.geode.distributed.internal.DSClock) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) LogWriter(org.apache.geode.LogWriter) CancelCriterion(org.apache.geode.CancelCriterion) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Statistics(org.apache.geode.Statistics) File(java.io.File)

Example 72 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class DiskStoreCommands method compactDiskStore.

@CliCommand(value = CliStrings.COMPACT_DISK_STORE, help = CliStrings.COMPACT_DISK_STORE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result compactDiskStore(@CliOption(key = CliStrings.COMPACT_DISK_STORE__NAME, mandatory = true, optionContext = ConverterHint.DISKSTORE, help = CliStrings.COMPACT_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = CliStrings.COMPACT_DISK_STORE__GROUP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.COMPACT_DISK_STORE__GROUP__HELP) String[] groups) {
    Result result = null;
    try {
        // disk store exists validation
        if (!diskStoreExists(diskStoreName)) {
            result = ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.COMPACT_DISK_STORE__DISKSTORE_0_DOESNOT_EXIST, new Object[] { diskStoreName }));
        } else {
            InternalDistributedSystem ds = getCache().getInternalDistributedSystem();
            Map<DistributedMember, PersistentID> overallCompactInfo = new HashMap<DistributedMember, PersistentID>();
            Set<?> otherMembers = ds.getDistributionManager().getOtherNormalDistributionManagerIds();
            Set<InternalDistributedMember> allMembers = new HashSet<InternalDistributedMember>();
            for (Object member : otherMembers) {
                allMembers.add((InternalDistributedMember) member);
            }
            allMembers.add(ds.getDistributedMember());
            otherMembers = null;
            String groupInfo = "";
            // if groups are specified, find members in the specified group
            if (groups != null && groups.length > 0) {
                groupInfo = CliStrings.format(CliStrings.COMPACT_DISK_STORE__MSG__FOR_GROUP, new Object[] { Arrays.toString(groups) + "." });
                final Set<InternalDistributedMember> selectedMembers = new HashSet<InternalDistributedMember>();
                List<String> targetedGroups = Arrays.asList(groups);
                for (Iterator<InternalDistributedMember> iterator = allMembers.iterator(); iterator.hasNext(); ) {
                    InternalDistributedMember member = iterator.next();
                    List<String> memberGroups = member.getGroups();
                    if (!Collections.disjoint(targetedGroups, memberGroups)) {
                        selectedMembers.add(member);
                    }
                }
                allMembers = selectedMembers;
            }
            // have at least one member
            if (allMembers.isEmpty()) {
                result = ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.COMPACT_DISK_STORE__NO_MEMBERS_FOUND_IN_SPECIFED_GROUP, new Object[] { Arrays.toString(groups) }));
            } else {
                // first invoke on local member if it exists in the targeted set
                if (allMembers.remove(ds.getDistributedMember())) {
                    PersistentID compactedDiskStoreId = CompactRequest.compactDiskStore(diskStoreName);
                    if (compactedDiskStoreId != null) {
                        overallCompactInfo.put(ds.getDistributedMember(), compactedDiskStoreId);
                    }
                }
                // CompactRequest. Otherwise, send the request to others
                if (!allMembers.isEmpty()) {
                    // Invoke compact on all 'other' members
                    Map<DistributedMember, PersistentID> memberCompactInfo = CompactRequest.send(ds.getDistributionManager(), diskStoreName, allMembers);
                    if (memberCompactInfo != null && !memberCompactInfo.isEmpty()) {
                        overallCompactInfo.putAll(memberCompactInfo);
                        memberCompactInfo.clear();
                    }
                    String notExecutedMembers = CompactRequest.getNotExecutedMembers();
                    LogWrapper.getInstance().info("compact disk-store \"" + diskStoreName + "\" message was scheduled to be sent to but was not send to " + notExecutedMembers);
                }
                // If compaction happened at all, then prepare the summary
                if (overallCompactInfo != null && !overallCompactInfo.isEmpty()) {
                    CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
                    SectionResultData section = null;
                    Set<Entry<DistributedMember, PersistentID>> entries = overallCompactInfo.entrySet();
                    for (Entry<DistributedMember, PersistentID> entry : entries) {
                        String memberId = entry.getKey().getId();
                        section = compositeResultData.addSection(memberId);
                        section.addData("On Member", memberId);
                        PersistentID persistentID = entry.getValue();
                        if (persistentID != null) {
                            SectionResultData subSection = section.addSection("DiskStore" + memberId);
                            subSection.addData("UUID", persistentID.getUUID());
                            subSection.addData("Host", persistentID.getHost().getHostName());
                            subSection.addData("Directory", persistentID.getDirectory());
                        }
                    }
                    compositeResultData.setHeader("Compacted " + diskStoreName + groupInfo);
                    result = ResultBuilder.buildResult(compositeResultData);
                } else {
                    result = ResultBuilder.createInfoResult(CliStrings.COMPACT_DISK_STORE__COMPACTION_ATTEMPTED_BUT_NOTHING_TO_COMPACT);
                }
            }
        // all members' if
        }
    // disk store exists' if
    } catch (RuntimeException e) {
        LogWrapper.getInstance().info(e.getMessage(), e);
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMPACT_DISK_STORE__ERROR_WHILE_COMPACTING_REASON_0, new Object[] { e.getMessage() }));
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) HashMap(java.util.HashMap) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Entry(java.util.Map.Entry) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) PersistentID(org.apache.geode.cache.persistence.PersistentID) HashSet(java.util.HashSet) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 73 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class MemoryThresholdsOffHeapDUnitTest method prRemotePutRejection.

private void prRemotePutRejection(boolean cacheClose, boolean localDestroy, final boolean useTx) throws Exception {
    final Host host = Host.getHost(0);
    final VM accessor = host.getVM(0);
    final VM[] servers = new VM[3];
    servers[0] = host.getVM(1);
    servers[1] = host.getVM(2);
    servers[2] = host.getVM(3);
    final String regionName = "offHeapPRRemotePutRejection";
    final int redundancy = 1;
    startCacheServer(servers[0], 0f, 90f, regionName, true, /* createPR */
    false, /* notifyBySubscription */
    redundancy);
    startCacheServer(servers[1], 0f, 90f, regionName, true, /* createPR */
    false, /* notifyBySubscription */
    redundancy);
    startCacheServer(servers[2], 0f, 90f, regionName, true, /* createPR */
    false, /* notifyBySubscription */
    redundancy);
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getSystem(getOffHeapProperties());
            getCache();
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(redundancy);
            paf.setLocalMaxMemory(0);
            paf.setTotalNumBuckets(11);
            factory.setPartitionAttributes(paf.create());
            factory.setOffHeap(true);
            createRegion(regionName, factory.create());
            return null;
        }
    });
    doPuts(accessor, regionName, false, false);
    final Range r1 = Range.DEFAULT;
    doPutAlls(accessor, regionName, false, false, r1);
    servers[0].invoke(addExpectedException);
    servers[1].invoke(addExpectedException);
    servers[2].invoke(addExpectedException);
    setUsageAboveCriticalThreshold(servers[0], regionName);
    final Set<InternalDistributedMember> criticalMembers = (Set) servers[0].invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final PartitionedRegion pr = (PartitionedRegion) getRootRegion().getSubregion(regionName);
            final int hashKey = PartitionedRegionHelper.getHashKey(pr, null, "oh5", null, null);
            return pr.getRegionAdvisor().getBucketOwners(hashKey);
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final PartitionedRegion pr = (PartitionedRegion) getRootRegion().getSubregion(regionName);
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "remote bucket not marked sick";
                }

                public boolean done() {
                    boolean keyFoundOnSickMember = false;
                    boolean caughtException = false;
                    for (int i = 0; i < 20; i++) {
                        Integer key = Integer.valueOf(i);
                        int hKey = PartitionedRegionHelper.getHashKey(pr, null, key, null, null);
                        Set<InternalDistributedMember> owners = pr.getRegionAdvisor().getBucketOwners(hKey);
                        final boolean hasCriticalOwners = owners.removeAll(criticalMembers);
                        if (hasCriticalOwners) {
                            keyFoundOnSickMember = true;
                            try {
                                if (useTx)
                                    getCache().getCacheTransactionManager().begin();
                                pr.getCache().getLogger().fine("SWAP:putting in tx:" + useTx);
                                pr.put(key, "value");
                                if (useTx)
                                    getCache().getCacheTransactionManager().commit();
                            } catch (LowMemoryException ex) {
                                caughtException = true;
                                if (useTx)
                                    getCache().getCacheTransactionManager().rollback();
                            }
                        } else {
                            // puts on healthy member should continue
                            pr.put(key, "value");
                        }
                    }
                    return keyFoundOnSickMember && caughtException;
                }
            };
            Wait.waitForCriterion(wc, 10000, 10, true);
            return null;
        }
    });
    {
        Range r2 = new Range(r1, r1.width() + 1);
        doPutAlls(accessor, regionName, false, true, r2);
    }
    // Find all VMs that have a critical region
    SerializableCallable getMyId = new SerializableCallable() {

        public Object call() throws Exception {
            return ((GemFireCacheImpl) getCache()).getMyId();
        }
    };
    final Set<VM> criticalServers = new HashSet<VM>();
    for (final VM server : servers) {
        DistributedMember member = (DistributedMember) server.invoke(getMyId);
        if (criticalMembers.contains(member)) {
            criticalServers.add(server);
        }
    }
    if (localDestroy) {
        // local destroy the region on sick members
        for (final VM vm : criticalServers) {
            vm.invoke(new SerializableCallable("local destroy sick member") {

                public Object call() throws Exception {
                    Region r = getRootRegion().getSubregion(regionName);
                    LogWriterUtils.getLogWriter().info("PRLocalDestroy");
                    r.localDestroyRegion();
                    return null;
                }
            });
        }
    } else if (cacheClose) {
        // close cache on sick members
        for (final VM vm : criticalServers) {
            vm.invoke(new SerializableCallable("close cache sick member") {

                public Object call() throws Exception {
                    getCache().close();
                    return null;
                }
            });
        }
    } else {
        setUsageBelowEviction(servers[0], regionName);
        servers[0].invoke(removeExpectedException);
        servers[1].invoke(removeExpectedException);
        servers[2].invoke(removeExpectedException);
    }
    // do put all in a loop to allow distribution of message
    accessor.invoke(new SerializableCallable("Put in a loop") {

        public Object call() throws Exception {
            final Region r = getRootRegion().getSubregion(regionName);
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "pr should have gone un-critical";
                }

                public boolean done() {
                    boolean done = true;
                    for (int i = 0; i < 20; i++) {
                        try {
                            r.put(i, "value");
                        } catch (LowMemoryException e) {
                            // expected
                            done = false;
                        }
                    }
                    return done;
                }
            };
            Wait.waitForCriterion(wc, 10000, 10, true);
            return null;
        }
    });
    doPutAlls(accessor, regionName, false, false, r1);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Host(org.apache.geode.test.dunit.Host) Range(org.apache.geode.cache.management.MemoryThresholdsDUnitTest.Range) IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheException(org.apache.geode.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) LowMemoryException(org.apache.geode.cache.LowMemoryException) HashSet(java.util.HashSet)

Example 74 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class ResourceManagerDUnitTest method doOpDuringBucketRemove.

private void doOpDuringBucketRemove(final OpDuringBucketRemove op) {
    final String[] regionPath = new String[] { getUniqueName() + "_PR_0" };
    final int[] numBuckets = new int[] { 1 };
    final int[] redundantCopies = new int[] { 1 };
    // localMaxMemory config to use for three members
    final int[] localMaxMemory = new int[] { 100, 100 };
    final Integer KEY = Integer.valueOf(69);
    // bucketKeys to use for making one bucket
    final Integer[] bucketKeys = new Integer[] { KEY };
    createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory[0], numBuckets[0], redundantCopies[0]);
    createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory[1], numBuckets[0], redundantCopies[0]);
    final String VALUE = "doOpDuringBucketRemove.VALUE";
    createBuckets(0, regionPath[0], bucketKeys, VALUE);
    // identify the members and their config values
    final InternalDistributedMember[] members = new InternalDistributedMember[2];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
    int primaryVM = -1;
    int otherVM = -1;
    for (int i = 0; i < memberPrimaryCounts.length; i++) {
        if (memberPrimaryCounts[i] == 0) {
            otherVM = i;
        } else if (memberPrimaryCounts[i] == 1) {
            // found the primary
            primaryVM = i;
        }
    }
    assertTrue(primaryVM > -1);
    assertTrue(otherVM > -1);
    assertTrue(primaryVM != otherVM);
    final int finalOtherVM = otherVM;
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertTrue("Target member is not hosting bucket to remove", bucket.isHosting());
            assertNotNull("Bucket is null on target member", bucket);
            assertNotNull("BucketRegion is null on target member", bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion());
            EntrySnapshot re = (EntrySnapshot) pr.getEntry(KEY);
            assertEquals(true, re.wasInitiallyLocal());
            assertEquals(false, re.isLocal());
            assertEquals(VALUE, re.getValue());
        }
    });
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            final PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            final boolean[] invoked = new boolean[] { false };
            final PartitionedRegionDataStore prds = pr.getDataStore();
            prds.setBucketReadHook(new Runnable() {

                public void run() {
                    invoked[0] = true;
                    logger.debug("In bucketReadHook");
                    assertTrue(prds.removeBucket(0, false));
                }
            });
            try {
                Bucket bucket = pr.getRegionAdvisor().getBucket(0);
                assertTrue("Target member is not hosting bucket to remove", bucket.isHosting());
                assertNotNull("Bucket is null on target member", bucket);
                assertNotNull("BucketRegion is null on target member", bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion());
                assertEquals(false, invoked[0]);
                op.runit(pr, KEY, VALUE);
                assertEquals(true, invoked[0]);
            } finally {
                prds.setBucketReadHook(null);
            }
        }
    });
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertFalse("Target member is still hosting removed bucket. Bucket:" + bucket + " Advisor state:" + bucket.getBucketAdvisor(), bucket.isHosting());
            assertNull(bucketRegion);
            // assertTrue(bucketRegion == null || bucketRegion.isDestroyed());
            EntrySnapshot re = (EntrySnapshot) pr.getEntry(KEY);
            assertEquals(false, re.wasInitiallyLocal());
            assertEquals(false, re.isLocal());
            assertEquals(VALUE, re.getValue());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 75 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.

the class ResourceManagerDUnitTest method testMoveBucket.

/**
   * Creates a bucket on two members. Then brings up a third member and moves the non-primary bucket
   * to it.
   */
@Test
public void testMoveBucket() {
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0" };
    final int numBuckets = 1;
    final int redundantCopies = 1;
    final int localMaxMemory = 100;
    // create the PartitionedRegion on the first two members
    createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // create the bucket on the first two members
    final Integer bucketKey = Integer.valueOf(0);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, value);
    // identify the primaryVM and otherVM
    final InternalDistributedMember[] members = new InternalDistributedMember[2];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
    int primaryVM = -1;
    int otherVM = -1;
    for (int i = 0; i < memberPrimaryCounts.length; i++) {
        if (memberPrimaryCounts[i] == 0) {
            otherVM = i;
        } else if (memberPrimaryCounts[i] == 1) {
            // found the primary
            primaryVM = i;
        }
    }
    assertTrue(primaryVM > -1);
    assertTrue(otherVM > -1);
    assertTrue(primaryVM != otherVM);
    final int finalOtherVM = otherVM;
    // make sure bucket exists on otherVM
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertNotNull("Bucket is null on SRC member", bucket);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertTrue("SRC member is not hosting bucket", bucket.isHosting());
            assertNotNull("BucketRegion is null on SRC member", bucketRegion);
            int redundancy = bucket.getBucketAdvisor().getBucketRedundancy();
            assertEquals("SRC member reports redundancy " + redundancy, redundantCopies, redundancy);
        }
    });
    // create newVM to move bucket to
    final int finalNewVM = 2;
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // initiate moveBucket to move from otherVM to newVM
    boolean movedBucket = ((Boolean) Host.getHost(0).getVM(finalNewVM).invoke(new SerializableCallable() {

        public Object call() {
            InternalDistributedMember recipient = members[finalOtherVM];
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            return pr.getDataStore().moveBucket(0, recipient, true);
        }
    })).booleanValue();
    assertTrue("Failed in call to moveBucket", movedBucket);
    // validate that otherVM no longer hosts bucket
    Host.getHost(0).getVM(otherVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertFalse("SRC member is still hosting moved bucket", bucket.isHosting());
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertNull("BucketRegion is not null on SRC member", bucketRegion);
        }
    });
    // validate that newVM now hosts bucket
    Host.getHost(0).getVM(finalNewVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            Bucket bucket = pr.getRegionAdvisor().getBucket(0);
            assertNotNull("Bucket is null on DST member", bucket);
            BucketRegion bucketRegion = bucket.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
            assertTrue("DST member is not hosting bucket", bucket.isHosting());
            assertNotNull("BucketRegion is null on DST member", bucketRegion);
            assertEquals(redundantCopies, bucket.getBucketAdvisor().getBucketRedundancy());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)516 Test (org.junit.Test)162 HashSet (java.util.HashSet)124 Set (java.util.Set)77 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)63 NetView (org.apache.geode.distributed.internal.membership.NetView)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)56 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 ArrayList (java.util.ArrayList)54 DistributedMember (org.apache.geode.distributed.DistributedMember)49 UnitTest (org.apache.geode.test.junit.categories.UnitTest)49 HashMap (java.util.HashMap)46 IOException (java.io.IOException)36 Iterator (java.util.Iterator)34 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)32 Map (java.util.Map)29 CancelException (org.apache.geode.CancelException)29 DM (org.apache.geode.distributed.internal.DM)29