Search in sources :

Example 76 with InternalDistributedMember

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

the class ResourceManagerDUnitTest method testCreateRedundantBucket.

/**
   * Creates a bucket on two members. Then brings up a third member and creates an extra redundant
   * copy of the bucket on it.
   */
@Test
public void testCreateRedundantBucket() {
    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 create extra redundant bucket on
    final int finalNewVM = 2;
    createRegion(Host.getHost(0).getVM(finalNewVM), regionPath[0], localMaxMemory, numBuckets, redundantCopies);
    // create an extra redundant bucket on finalNewVM
    Host.getHost(0).getVM(finalNewVM).invoke(new SerializableRunnable() {

        public void run() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            assertEquals(CreateBucketResult.CREATED, pr.getDataStore().createRedundantBucket(0, false, new InternalDistributedMember()));
            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 + 1, 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) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 77 with InternalDistributedMember

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

the class ResourceManagerDUnitTest method testGetPartitionedRegionDetails.

/**
   * Creates partitioned regions in multiple vms and fully exercises the getPartitionedRegionDetails
   * API on ResourceManager.
   */
@Test
public void testGetPartitionedRegionDetails() {
    // two regions
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0", getUniqueName() + "-PR-1" };
    // numBuckets config for the two regions
    final int[] numBuckets = new int[] { 100, 90 };
    // redundantCopies config for the two regions
    final int[] redundantCopies = new int[] { 1, 0 };
    // localMaxMemory config to use for three members
    final int[] localMaxMemory = new int[] { 50, 100, 0 };
    // bucketKeys to use for making three buckets in first PR
    final Integer[] bucketKeys = new Integer[] { Integer.valueOf(0), Integer.valueOf(42), Integer.valueOf(76) };
    assertEquals(0, bucketKeys[0].hashCode());
    assertEquals(42, bucketKeys[1].hashCode());
    assertEquals(76, bucketKeys[2].hashCode());
    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]);
    createRegion(Host.getHost(0).getVM(2), regionPath[0], localMaxMemory[2], numBuckets[0], redundantCopies[0]);
    createRegion(Host.getHost(0).getVM(0), regionPath[1], localMaxMemory[0], numBuckets[1], redundantCopies[1]);
    // 2 MB in size
    final byte[] value = new byte[1024 * 1024 * 2];
    createBuckets(0, regionPath[0], bucketKeys, value);
    // identify the members and their config values
    final InternalDistributedMember[] members = new InternalDistributedMember[3];
    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]);
    // test everything here
    for (int i = 0; i < localMaxMemory.length; i++) {
        final int vm = i;
        Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {

            public void run() {
                Set<PartitionRegionInfo> detailsSet = PartitionRegionHelper.getPartitionRegionInfo(getCache());
                if (vm == 0) {
                    assertEquals(2, detailsSet.size());
                } else {
                    assertEquals(1, detailsSet.size());
                }
                // iterate over each PartitionedRegionDetails
                for (Iterator<PartitionRegionInfo> prIter = detailsSet.iterator(); prIter.hasNext(); ) {
                    PartitionRegionInfo details = prIter.next();
                    // NOTE: getRegionPath() contains the Region.SEPARATOR + regionPath
                    assertTrue("Unknown regionPath=" + details.getRegionPath(), details.getRegionPath().contains(regionPath[0]) || details.getRegionPath().contains(regionPath[1]));
                    if (details.getRegionPath().contains(regionPath[0])) {
                        assertEquals(numBuckets[0], details.getConfiguredBucketCount());
                        assertEquals(0, details.getLowRedundancyBucketCount());
                        assertEquals(redundantCopies[0], details.getConfiguredRedundantCopies());
                        assertEquals(redundantCopies[0], details.getActualRedundantCopies());
                        assertNull(details.getColocatedWith());
                        Set<PartitionMemberInfo> memberDetails = details.getPartitionMemberInfo();
                        assertNotNull(memberDetails);
                        assertEquals(localMaxMemory.length - 1, memberDetails.size());
                        // iterate over each PartitionMemberDetails (datastores only)
                        for (Iterator<PartitionMemberInfo> mbrIter = memberDetails.iterator(); mbrIter.hasNext(); ) {
                            PartitionMemberInfo mbrDetails = mbrIter.next();
                            assertNotNull(mbrDetails);
                            DistributedMember mbr = mbrDetails.getDistributedMember();
                            assertNotNull(mbr);
                            int membersIdx = -1;
                            for (int idx = 0; idx < members.length; idx++) {
                                if (mbr.equals(members[idx])) {
                                    membersIdx = idx;
                                }
                            }
                            assertEquals(localMaxMemory[membersIdx] * (1024L * 1024L), mbrDetails.getConfiguredMaxMemory());
                            assertEquals(memberSizes[membersIdx], mbrDetails.getSize());
                            assertEquals(memberBucketCounts[membersIdx], mbrDetails.getBucketCount());
                            assertEquals(memberPrimaryCounts[membersIdx], mbrDetails.getPrimaryCount());
                            if (mbr.equals(getSystem().getDistributedMember())) {
                                // PartitionMemberDetails represents the local member
                                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(details.getRegionPath());
                                assertEquals(pr.getLocalMaxMemory() * (1024L * 1024L), mbrDetails.getConfiguredMaxMemory());
                                PartitionedRegionDataStore ds = pr.getDataStore();
                                assertNotNull(ds);
                                assertEquals(getSize(ds), mbrDetails.getSize());
                                assertEquals(ds.getBucketsManaged(), mbrDetails.getBucketCount());
                                assertEquals(ds.getNumberOfPrimaryBucketsManaged(), mbrDetails.getPrimaryCount());
                            }
                        }
                    } else {
                        // found the other PR which has only one datastore and we know
                        // this system memberId is the only entry in mbrDetails
                        assertEquals(numBuckets[1], details.getConfiguredBucketCount());
                        assertEquals(0, details.getLowRedundancyBucketCount());
                        assertEquals(redundantCopies[1], details.getConfiguredRedundantCopies());
                        assertEquals(redundantCopies[1], details.getActualRedundantCopies());
                        assertNull(details.getColocatedWith());
                        Set<PartitionMemberInfo> memberDetails = details.getPartitionMemberInfo();
                        assertNotNull(memberDetails);
                        assertEquals(1, memberDetails.size());
                        PartitionMemberInfo mbrDetails = memberDetails.iterator().next();
                        assertEquals(getSystem().getDistributedMember(), mbrDetails.getDistributedMember());
                        PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(details.getRegionPath());
                        assertEquals(pr.getLocalMaxMemory() * (1024L * 1024L), mbrDetails.getConfiguredMaxMemory());
                        PartitionedRegionDataStore ds = pr.getDataStore();
                        assertNotNull(ds);
                        assertEquals(getSize(ds), mbrDetails.getSize());
                        assertEquals(ds.getBucketsManaged(), mbrDetails.getBucketCount());
                        assertEquals(ds.getNumberOfPrimaryBucketsManaged(), mbrDetails.getPrimaryCount());
                    }
                }
            }
        });
    }
    destroyRegions(0, regionPath);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 78 with InternalDistributedMember

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

the class ResourceManagerDUnitTest method testRemoveBucketMessage.

@Test
public void testRemoveBucketMessage() {
    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 2 members
    final int[] localMaxMemory = new int[] { 100, 100 };
    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 Integer bucketKey = Integer.valueOf(0);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKey, 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());
        }
    });
    boolean sentRemoveBucket = ((Boolean) Host.getHost(0).getVM(primaryVM).invoke(new SerializableCallable() {

        public Object call() {
            InternalDistributedMember recipient = members[finalOtherVM];
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            RemoveBucketResponse response = RemoveBucketMessage.send(recipient, pr, 0, false);
            if (response != null) {
                response.waitForRepliesUninterruptibly();
                return true;
            } else {
                return Boolean.FALSE;
            }
        }
    })).booleanValue();
    assertTrue("Failed to get reply to RemoveBucketMessage", sentRemoveBucket);
    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.isHosting());
            assertNull("BucketRegion is not null on target member", bucketRegion);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RemoveBucketResponse(org.apache.geode.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse) 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)

Example 79 with InternalDistributedMember

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

the class ResourceManagerDUnitTest method testGetInternalPRDetails.

/**
   * Creates partitioned regions in multiple vms and fully exercises the internal-only
   * getInternalPRDetails API on ResourceManager.
   */
@Test
public void testGetInternalPRDetails() {
    // two regions
    final String[] regionPath = new String[] { getUniqueName() + "-PR-0", getUniqueName() + "-PR-1" };
    // numBuckets config for the two regions
    final int[] numBuckets = new int[] { 100, 90 };
    // redundantCopies config for the two regions
    final int[] redundantCopies = new int[] { 1, 0 };
    // localMaxMemory config to use for three members
    final int[] localMaxMemory = new int[] { 50, 100, 0 };
    // bucketKeys to use for making three bckets in first PR
    final Integer[] bucketKeys = new Integer[] { Integer.valueOf(0), Integer.valueOf(42), Integer.valueOf(76) };
    assertEquals(0, bucketKeys[0].hashCode());
    assertEquals(42, bucketKeys[1].hashCode());
    assertEquals(76, bucketKeys[2].hashCode());
    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]);
    createRegion(Host.getHost(0).getVM(2), regionPath[0], localMaxMemory[2], numBuckets[0], redundantCopies[0]);
    createRegion(Host.getHost(0).getVM(0), regionPath[1], localMaxMemory[0], numBuckets[1], redundantCopies[1]);
    // 2 MB in size
    final byte[] value = new byte[1024 * 1024 * 2];
    createBuckets(0, regionPath[0], bucketKeys, value);
    // identify the members and their config values
    final InternalDistributedMember[] members = new InternalDistributedMember[3];
    final long[] memberSizes = new long[members.length];
    final int[] memberBucketCounts = new int[members.length];
    final int[] memberPrimaryCounts = new int[members.length];
    for (int i = 0; i < members.length; i++) {
        final int vm = i;
        members[vm] = (InternalDistributedMember) Host.getHost(0).getVM(vm).invoke(new SerializableCallable() {

            public Object call() {
                return getSystem().getDistributedMember();
            }
        });
        memberSizes[vm] = ((Long) Host.getHost(0).getVM(vm).invoke(new SerializableCallable() {

            public Object call() {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
                PartitionedRegionDataStore ds = pr.getDataStore();
                if (ds == null) {
                    return Long.valueOf(0);
                } else {
                    return Long.valueOf(getSize(ds));
                }
            }
        })).longValue();
        memberBucketCounts[vm] = ((Integer) Host.getHost(0).getVM(vm).invoke(new SerializableCallable() {

            public Object call() {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
                PartitionedRegionDataStore ds = pr.getDataStore();
                if (ds == null) {
                    return new Integer(0);
                } else {
                    return new Integer(ds.getBucketsManaged());
                }
            }
        })).intValue();
        memberPrimaryCounts[vm] = ((Integer) Host.getHost(0).getVM(vm).invoke(new SerializableCallable() {

            public Object call() {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
                PartitionedRegionDataStore ds = pr.getDataStore();
                if (ds == null) {
                    return new Integer(0);
                } else {
                    return new Integer(ds.getNumberOfPrimaryBucketsManaged());
                }
            }
        })).intValue();
    }
    // test everything here
    for (int i = 0; i < localMaxMemory.length; i++) {
        final int vm = i;
        Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {

            public void run() {
                Set<InternalPRInfo> detailsSet = new HashSet<InternalPRInfo>();
                GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
                for (PartitionedRegion pr : cache.getPartitionedRegions()) {
                    InternalPRInfo info = pr.getRedundancyProvider().buildPartitionedRegionInfo(true, cache.getInternalResourceManager().getLoadProbe());
                    detailsSet.add(info);
                }
                if (vm == 0) {
                    assertEquals(2, detailsSet.size());
                } else {
                    assertEquals(1, detailsSet.size());
                }
                // iterate over each InternalPRDetails
                for (Iterator<InternalPRInfo> prIter = detailsSet.iterator(); prIter.hasNext(); ) {
                    InternalPRInfo details = prIter.next();
                    // NOTE: getRegionPath() contains the Region.SEPARATOR + regionPath
                    assertTrue("Unknown regionPath=" + details.getRegionPath(), details.getRegionPath().contains(regionPath[0]) || details.getRegionPath().contains(regionPath[1]));
                    if (details.getRegionPath().contains(regionPath[0])) {
                        assertEquals(numBuckets[0], details.getConfiguredBucketCount());
                        assertEquals(0, details.getLowRedundancyBucketCount());
                        assertEquals(redundantCopies[0], details.getConfiguredRedundantCopies());
                        assertEquals(redundantCopies[0], details.getActualRedundantCopies());
                        assertNull(details.getColocatedWith());
                        Set<InternalPartitionDetails> memberDetails = details.getInternalPartitionDetails();
                        assertNotNull(memberDetails);
                        assertEquals(localMaxMemory.length - 1, memberDetails.size());
                        // iterate over each InternalPartitionDetails (datastores only)
                        for (Iterator<InternalPartitionDetails> mbrIter = memberDetails.iterator(); mbrIter.hasNext(); ) {
                            InternalPartitionDetails mbrDetails = mbrIter.next();
                            assertNotNull(mbrDetails);
                            DistributedMember mbr = mbrDetails.getDistributedMember();
                            assertNotNull(mbr);
                            int membersIdx = -1;
                            for (int idx = 0; idx < members.length; idx++) {
                                if (mbr.equals(members[idx])) {
                                    membersIdx = idx;
                                }
                            }
                            assertEquals(localMaxMemory[membersIdx] * 1024 * 1024, mbrDetails.getConfiguredMaxMemory());
                            assertEquals(memberSizes[membersIdx], mbrDetails.getSize());
                            assertEquals(memberBucketCounts[membersIdx], mbrDetails.getBucketCount());
                            assertEquals(memberPrimaryCounts[membersIdx], mbrDetails.getPrimaryCount());
                            PRLoad load = mbrDetails.getPRLoad();
                            assertNotNull(load);
                            assertEquals((float) localMaxMemory[membersIdx], load.getWeight(), 0);
                            int totalBucketBytes = 0;
                            int primaryCount = 0;
                            for (int bid = 0; bid < numBuckets[0]; bid++) {
                                long bucketBytes = mbrDetails.getBucketSize(bid);
                                assertTrue(bucketBytes >= 0);
                                totalBucketBytes += bucketBytes;
                                // validate against the PRLoad
                                assertEquals((float) bucketBytes, load.getReadLoad(bid), 0);
                                if (load.getWriteLoad(bid) > 0) {
                                    // found a primary
                                    primaryCount++;
                                }
                            }
                            // assertIndexDetailsEquals(memberSizes[membersIdx] * (1024* 1024),
                            // totalBucketBytes);
                            assertEquals(memberPrimaryCounts[membersIdx], primaryCount);
                            if (mbr.equals(getSystem().getDistributedMember())) {
                                // PartitionMemberDetails represents the local member
                                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(details.getRegionPath());
                                assertEquals(pr.getLocalMaxMemory() * (1024L * 1024L), mbrDetails.getConfiguredMaxMemory());
                                PartitionedRegionDataStore ds = pr.getDataStore();
                                assertNotNull(ds);
                                assertEquals(getSize(ds), mbrDetails.getSize());
                                assertEquals(ds.getBucketsManaged(), mbrDetails.getBucketCount());
                                assertEquals(ds.getNumberOfPrimaryBucketsManaged(), mbrDetails.getPrimaryCount());
                            }
                        }
                    } else {
                        // found the other PR which has only one datastore and we know
                        // this system memberId is the only entry in mbrDetails
                        assertEquals(numBuckets[1], details.getConfiguredBucketCount());
                        assertEquals(0, details.getLowRedundancyBucketCount());
                        assertEquals(redundantCopies[1], details.getConfiguredRedundantCopies());
                        assertEquals(redundantCopies[1], details.getActualRedundantCopies());
                        assertNull(details.getColocatedWith());
                        Set<PartitionMemberInfo> memberDetails = details.getPartitionMemberInfo();
                        assertNotNull(memberDetails);
                        assertEquals(1, memberDetails.size());
                        PartitionMemberInfo mbrDetails = memberDetails.iterator().next();
                        assertEquals(getSystem().getDistributedMember(), mbrDetails.getDistributedMember());
                        PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(details.getRegionPath());
                        assertEquals(pr.getLocalMaxMemory() * (1024L * 1024L), mbrDetails.getConfiguredMaxMemory());
                        PartitionedRegionDataStore ds = pr.getDataStore();
                        assertNotNull(ds);
                        assertEquals(getSize(ds), mbrDetails.getSize());
                        assertEquals(ds.getBucketsManaged(), mbrDetails.getBucketCount());
                        assertEquals(ds.getNumberOfPrimaryBucketsManaged(), mbrDetails.getPrimaryCount());
                    }
                }
            }
        });
    }
    destroyRegions(0, regionPath);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PRLoad(org.apache.geode.internal.cache.partitioned.PRLoad) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) InternalPRInfo(org.apache.geode.internal.cache.partitioned.InternalPRInfo) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalPartitionDetails(org.apache.geode.internal.cache.partitioned.InternalPartitionDetails) Iterator(java.util.Iterator) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 80 with InternalDistributedMember

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

the class PartitionRegionHelperDUnitTest method testMoveSingleBucket.

@Test
public void testMoveSingleBucket() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    SerializableCallable createPrRegion = new SerializableCallable("createRegion") {

        public Object call() {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(12);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
            return cache.getDistributedSystem().getDistributedMember();
        }
    };
    final DistributedMember member0 = (DistributedMember) vm0.invoke(createPrRegion);
    final DistributedMember member1 = (DistributedMember) vm1.invoke(createPrRegion);
    // populate the region with data so we have some buckets
    vm0.invoke(new SerializableRunnable("create data") {

        public void run() {
            for (int i = 0; i < 8; i++) {
                Region<Object, Object> region = getCache().getRegion("region1");
                region.put(i, "one");
            }
        }
    });
    // Create VM 2 later so that it doesn't have any buckets
    final DistributedMember member2 = (DistributedMember) vm2.invoke(createPrRegion);
    // Try some explicit moves
    vm0.invoke(new SerializableRunnable("create data") {

        public void run() {
            Region<Object, Object> region = getCache().getRegion("region1");
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 1), member0, member1);
            // Try to move a bucket to a member that already has the bucket
            try {
                PartitionRegionHelper.moveBucketByKey(region, member0, member1, 1);
                fail("Should have received an exception");
            } catch (IllegalStateException expected) {
                System.err.println(expected);
            }
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 1), member0, member1);
            // Try to move the bucket from a member that doesn't have the bucket
            try {
                PartitionRegionHelper.moveBucketByKey(region, member2, member2, 1);
                fail("Should have received an exception");
            } catch (IllegalStateException expected) {
                System.err.println(expected);
            }
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 1), member0, member1);
            // Try to move the bucket from an invalid member
            try {
                PartitionRegionHelper.moveBucketByKey(region, member2, new InternalDistributedMember("localhost", 5), 1);
                fail("Should have received an exception");
            } catch (IllegalStateException expected) {
                System.err.println(expected);
            }
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 1), member0, member1);
            // Try to move the bucket that doesn't exist
            try {
                PartitionRegionHelper.moveBucketByKey(region, member0, member2, 10);
                fail("Should have received an exception");
            } catch (IllegalStateException expected) {
                System.err.println(expected);
            }
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 10));
            // Do some successful moves.
            PartitionRegionHelper.moveBucketByKey(region, member0, member2, 1);
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 1), member1, member2);
            PartitionRegionHelper.moveBucketByKey(region, member2, member0, 1);
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 1), member0, member1);
            PartitionRegionHelper.moveBucketByKey(region, member0, member2, 2);
            PartitionRegionHelper.moveBucketByKey(region, member1, member2, 3);
            PartitionRegionHelper.moveBucketByKey(region, member1, member2, 4);
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 2), member1, member2);
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 3), member0, member2);
            assertHasMembers(PartitionRegionHelper.getAllMembersForKey(region, 4), member0, member2);
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Host(org.apache.geode.test.dunit.Host) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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