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());
}
});
}
}
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());
}
Aggregations