use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class MemberFunctionExecutionDUnitTest method excuteOnMembers_SendException.
public static void excuteOnMembers_SendException(Integer noOfMembers) {
assertNotNull(ds);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SEND_EXCEPTION);
InternalExecution memberExcution = null;
Execution executor = null;
Map memArgs = new HashMap();
if (noOfMembers.intValue() == 1) {
// Local VM
DistributedMember localmember = ds.getDistributedMember();
memberExcution = (InternalExecution) FunctionService.onMember(localmember);
} else if (noOfMembers.intValue() == 5) {
memberExcution = (InternalExecution) FunctionService.onMembers();
} else {
Set memberSet = new HashSet(ds.getDistributionManager().getNormalDistributionManagerIds());
InternalDistributedMember localVM = ds.getDistributionManager().getDistributionManagerId();
memberSet.remove(localVM);
Iterator iter = memberSet.iterator();
while (iter.hasNext()) {
InternalDistributedMember member = (InternalDistributedMember) iter.next();
}
memberExcution = (InternalExecution) FunctionService.onMembers(memberSet);
}
try {
ResultCollector rc = memberExcution.setArguments(Boolean.TRUE).execute(function);
List li = (ArrayList) rc.getResult();
LogWriterUtils.getLogWriter().info("MemberFunctionExecutionDUnitTest#excuteOnMembers: Result : " + li);
assertEquals(noOfMembers.intValue(), li.size());
for (Object obj : li) {
assertTrue(obj instanceof MyFunctionExecutionException);
}
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("Exception Occurred : " + e.getMessage());
e.printStackTrace();
Assert.fail("Test failed", e);
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PRTransactionDUnitTest method testTxWithGetOnMovedBucketUsingBucketReadHook.
@SuppressWarnings("unchecked")
@Test
public void testTxWithGetOnMovedBucketUsingBucketReadHook() {
setupMoveBucket(0);
DistributedMember dm1 = (DistributedMember) dataStore1.invoke(getDM());
DistributedMember dm2 = (DistributedMember) dataStore2.invoke(getDM());
Op op = Op.GET;
useBucketReadHook = true;
basicPRTXWithOpOnMovedBucket(op, 0, dm1, dm2);
useBucketReadHook = false;
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PRTransactionDUnitTest method moveBucket.
@SuppressWarnings("unchecked")
private void moveBucket(Op op, DistributedMember dm1, DistributedMember dm2) {
PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
CustId cust1 = new CustId(1);
OrderId order1 = new OrderId(11, cust1);
boolean isCust1Local = isCust1LocalSingleBucket(pr, cust1);
DistributedMember source = isCust1Local ? dm1 : dm2;
DistributedMember destination = isCust1Local ? dm2 : dm1;
PartitionedRegion prOrder = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
LogService.getLogger().info("source ={}, destination ={}", source, destination);
switch(op) {
case GET:
moveBucketForGet(order1, isCust1Local, source, destination, prOrder);
break;
case CONTAINSVALUEFORKEY:
case CONTAINSKEY:
case CREATE:
case PUT:
case INVALIDATE:
case DESTROY:
case GETENTRY:
PartitionRegionHelper.moveBucketByKey(prOrder, source, destination, order1);
break;
default:
throw new AssertionError("Unknown operations " + op);
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class InterestListDUnitTest method testInterestRegistrationListeners.
/**
* two servers one client create Entries in all the vms register interest in various ways and
* ensure that registration listeners are properly invoked
*/
@Test
public void testInterestRegistrationListeners() throws Exception {
int port2;
createCache();
server = addCacheServer();
port2 = server.getPort();
addRegisterInterestListener();
vm0.invoke(() -> InterestListDUnitTest.addRegisterInterestListener());
// servers are set up, now do the clients
DistributedMember c1 = (DistributedMember) vm1.invoke(() -> InterestListDUnitTest.createClientCache(NetworkUtils.getServerHostName(vm0.getHost()), PORT1, port2));
DistributedMember c2 = (DistributedMember) vm2.invoke(() -> InterestListDUnitTest.createClientCache(NetworkUtils.getServerHostName(vm0.getHost()), PORT1, port2));
vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2());
vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2());
// interest registration from clients should cause listeners to be invoked
// in both servers
LogWriterUtils.getLogWriter().info("test phase 1");
vm1.invoke(() -> InterestListDUnitTest.registerKey(key1));
vm2.invoke(() -> InterestListDUnitTest.registerKey(key2));
Integer zero = new Integer(0);
Integer two = new Integer(2);
interestListener.verifyCountsAndClear(2, 0);
vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear(two, zero));
// unregistration from clients should invoke listeners on both servers
LogWriterUtils.getLogWriter().info("test phase 2");
vm1.invoke(() -> InterestListDUnitTest.unregisterKey(key1));
vm2.invoke(() -> InterestListDUnitTest.unregisterKey(key2));
interestListener.verifyCountsAndClear(0, 2);
vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear(zero, two));
// now the primary server for eache client will register and unregister
LogWriterUtils.getLogWriter().info("test phase 3");
registerKeyForClient(c1, key1);
vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient(c1, key1));
registerKeyForClient(c2, key2);
vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient(c2, key2));
interestListener.verifyCountsAndClear(2, 0);
vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear(two, zero));
LogWriterUtils.getLogWriter().info("test phase 4");
unregisterKeyForClient(c1, key1);
vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient(c1, key1));
unregisterKeyForClient(c2, key2);
vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient(c2, key2));
interestListener.verifyCountsAndClear(0, 2);
vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear(zero, two));
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class AsyncEventListenerDUnitTest method testParallelAsyncEventQueueMoveBucketAndMoveItBackDuringDispatching.
@Test
public void testParallelAsyncEventQueueMoveBucketAndMoveItBackDuringDispatching() {
Integer lnPort = (Integer) vm0.invoke(() -> AsyncEventQueueTestBase.createFirstLocatorWithDSId(1));
vm1.invoke(createCacheRunnable(lnPort));
vm2.invoke(createCacheRunnable(lnPort));
final DistributedMember member1 = vm1.invoke(() -> cache.getDistributedSystem().getDistributedMember());
final DistributedMember member2 = vm2.invoke(() -> cache.getDistributedSystem().getDistributedMember());
vm1.invoke(() -> AsyncEventQueueTestBase.createAsyncEventQueue("ln", true, 100, 10, false, false, null, false, new BucketMovingAsyncEventListener(member2)));
vm1.invoke(() -> AsyncEventQueueTestBase.createPartitionedRegionWithAsyncEventQueue(getTestMethodName() + "_PR", "ln", isOffHeap()));
vm1.invoke(() -> AsyncEventQueueTestBase.pauseAsyncEventQueue("ln"));
vm1.invoke(() -> AsyncEventQueueTestBase.doPuts(getTestMethodName() + "_PR", 113));
vm2.invoke(() -> AsyncEventQueueTestBase.createAsyncEventQueue("ln", true, 100, 10, false, false, null, false, new BucketMovingAsyncEventListener(member1)));
vm2.invoke(() -> AsyncEventQueueTestBase.createPartitionedRegionWithAsyncEventQueue(getTestMethodName() + "_PR", "ln", isOffHeap()));
vm1.invoke(() -> AsyncEventQueueTestBase.resumeAsyncEventQueue("ln"));
vm1.invoke(() -> AsyncEventQueueTestBase.waitForAsyncQueueToGetEmpty("ln"));
vm2.invoke(() -> AsyncEventQueueTestBase.waitForAsyncQueueToGetEmpty("ln"));
Set<Object> allKeys = new HashSet<Object>();
allKeys.addAll(getKeysSeen(vm1, "ln"));
allKeys.addAll(getKeysSeen(vm2, "ln"));
final Set<Long> expectedKeys = LongStream.range(0, 113).mapToObj(Long::valueOf).collect(Collectors.toSet());
assertEquals(expectedKeys, allKeys);
assertTrue(getBucketMoved(vm1, "ln"));
Awaitility.waitAtMost(10000, TimeUnit.MILLISECONDS).until(() -> getBucketMoved(vm2, "ln"));
}
Aggregations