Search in sources :

Example 1 with BecomePrimaryBucketResponse

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

the class ResourceManagerDUnitTest method testBecomePrimaryBucketMessage.

@Test
public void testBecomePrimaryBucketMessage() {
    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 two members
    final int[] localMaxMemory = new int[] { 100, 100, 0 };
    // bucketKeys to use for making one bucket
    final Integer[] bucketKeys = new Integer[] { Integer.valueOf(0) };
    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]);
    // 2 MB in size
    final byte[] value = new byte[1];
    createBucket(0, regionPath[0], bucketKeys[0], 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);
    int accessorVM = 2;
    assertTrue(accessorVM != primaryVM && accessorVM != otherVM);
    final int finalOtherVM = otherVM;
    boolean becamePrimary = ((Boolean) Host.getHost(0).getVM(accessorVM).invoke(new SerializableCallable() {

        public Object call() {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
            BecomePrimaryBucketResponse response = BecomePrimaryBucketMessage.send(members[finalOtherVM], pr, 0, false);
            if (response != null) {
                return Boolean.valueOf(response.waitForResponse());
            } else {
                return Boolean.FALSE;
            }
        }
    })).booleanValue();
    assertTrue(becamePrimary);
    // do a put from all three members to ensure primary is identified
    for (int i = 0; i < localMaxMemory.length; i++) {
        final int vm = i;
        performPuts(vm, regionPath[0], bucketKeys, value);
    }
    // use BucketAdvisor on all three members to assert that otherVM is now the primary
    for (int i = 0; i < localMaxMemory.length; i++) {
        final int vm = i;
        Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {

            public void run() {
                PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
                BucketAdvisor advisor = pr.getRegionAdvisor().getBucketAdvisor(0);
                assertEquals(members[finalOtherVM], advisor.getPrimary());
            }
        });
    }
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) BecomePrimaryBucketResponse(org.apache.geode.internal.cache.partitioned.BecomePrimaryBucketMessage.BecomePrimaryBucketResponse) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 2 with BecomePrimaryBucketResponse

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

the class LuceneQueriesAccessorBase method movePrimary.

private void movePrimary(final DistributedMember destination, final Object key) {
    PartitionedRegion region = (PartitionedRegion) getCache().getRegion(REGION_NAME);
    BecomePrimaryBucketResponse response = BecomePrimaryBucketMessage.send((InternalDistributedMember) destination, region, region.getKeyInfo(key).getBucketId(), true);
    assertNotNull(response);
    assertTrue(response.waitForResponse());
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BecomePrimaryBucketResponse(org.apache.geode.internal.cache.partitioned.BecomePrimaryBucketMessage.BecomePrimaryBucketResponse)

Aggregations

PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 BecomePrimaryBucketResponse (org.apache.geode.internal.cache.partitioned.BecomePrimaryBucketMessage.BecomePrimaryBucketResponse)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 BucketAdvisor (org.apache.geode.internal.cache.BucketAdvisor)1 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Test (org.junit.Test)1