use of org.apache.geode.distributed.internal.membership.InternalDistributedMember 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.internal.membership.InternalDistributedMember in project geode by apache.
the class TXLockServiceDUnitTest method testTXOriginatorRecoveryProcessor.
@Test
public void testTXOriginatorRecoveryProcessor() {
LogWriterUtils.getLogWriter().info("[testTXOriginatorRecoveryProcessor]");
final int originatorVM = 0;
final int grantorVM = 1;
final int particpantA = 2;
final int particpantB = 3;
final List regionLockReqs = new ArrayList();
regionLockReqs.add(new TXRegionLockRequestImpl("/testTXOriginatorRecoveryProcessor", new HashSet(Arrays.asList(new String[] { "KEY-1", "KEY-2", "KEY-3", "KEY-4" }))));
// build participants set...
InternalDistributedMember dmId = null;
final Set participants = new HashSet();
for (int i = 1; i <= particpantB; i++) {
final int finalvm = i;
dmId = (InternalDistributedMember) Host.getHost(0).getVM(finalvm).invoke(() -> TXLockServiceDUnitTest.fetchDistributionManagerId());
assertEquals("dmId should not be null for vm " + finalvm, false, dmId == null);
participants.add(dmId);
}
// create grantor
LogWriterUtils.getLogWriter().info("[testTXOriginatorRecoveryProcessor] grantorVM becomes grantor");
Host.getHost(0).getVM(grantorVM).invoke(new SerializableRunnable() {
public void run() {
TXLockService.createDTLS();
}
});
Host.getHost(0).getVM(grantorVM).invoke(() -> TXLockServiceDUnitTest.identifyLockGrantor_DTLS());
Boolean isGrantor = (Boolean) Host.getHost(0).getVM(grantorVM).invoke(() -> TXLockServiceDUnitTest.isLockGrantor_DTLS());
assertEquals("isLockGrantor should not be false for DTLS", Boolean.TRUE, isGrantor);
// have a originatorVM get a txLock with three participants including grantor
LogWriterUtils.getLogWriter().info("[testTXOriginatorRecoveryProcessor] originatorVM requests txLock");
Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable() {
public void run() {
TXLockService.createDTLS();
}
});
Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable("[testTXOriginatorRecoveryProcessor] originatorVM requests txLock") {
public void run() {
TXLockService dtls = TXLockService.getDTLS();
testTXOriginatorRecoveryProcessor_TXLockId = dtls.txLock(regionLockReqs, participants);
assertNotNull("testTXOriginatorRecoveryProcessor_TXLockId is null", testTXOriginatorRecoveryProcessor_TXLockId);
}
});
// create dtls in each participant
Host.getHost(0).getVM(particpantA).invoke(new SerializableRunnable() {
public void run() {
TXLockService.createDTLS();
}
});
Host.getHost(0).getVM(particpantB).invoke(new SerializableRunnable() {
public void run() {
TXLockService.createDTLS();
}
});
// disconnect originatorVM without releasing txLock
/*
* doesn't currently trigger the DLockLessorDepatureHandler... TODO
* Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable() { public void run() {
* TXLockService.destroyServices(); } });
*/
/*
* Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable() { public void run() {
* InternalDistributedSystem sys = (InternalDistributedSystem)
* InternalDistributedSystem.getAnyInstance(); if (sys != null) { sys.disconnect(); } } });
*/
Host.getHost(0).getVM(originatorVM).invoke(new SerializableRunnable() {
public void run() {
TXLockService.destroyServices();
}
});
Host.getHost(0).getVM(originatorVM).invoke(() -> disconnectFromDS());
// grantor sends TXOriginatorRecoveryMessage...
// TODO: verify processing of message? and have test sleep until finished
sleep(200);
// verify txLock is released...
Host.getHost(0).getVM(particpantA).invoke(new SerializableRunnable("[testTXOriginatorRecoveryProcessor] verify txLock is released") {
public void run() {
TXLockService dtls = TXLockService.getDTLS();
testTXOriginatorRecoveryProcessor_TXLockId = dtls.txLock(regionLockReqs, participants);
assertNotNull("testTXOriginatorRecoveryProcessor_TXLockId is null", testTXOriginatorRecoveryProcessor_TXLockId);
}
});
Host.getHost(0).getVM(particpantA).invoke(new SerializableRunnable("[testTXOriginatorRecoveryProcessor] particpantA releases txLock") {
public void run() {
TXLockService dtls = TXLockService.getDTLS();
dtls.release(testTXOriginatorRecoveryProcessor_TXLockId);
}
});
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class StreamingPartitionOperationOneDUnitTest method testStreamingPartitionOneProviderNoExceptions.
@Test
public void testStreamingPartitionOneProviderNoExceptions() throws Exception {
// final String name = this.getUniqueName();
// ask another VM to connect to the distributed system
// this will be the data provider, and get their member id at the same time
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
// get the other member id that connected
InternalDistributedMember otherId = (InternalDistributedMember) vm0.invoke(new IDGetter(), "getMemberId");
vm0.invoke(createPrRegionWithDS_DACK);
// also create the PR here so we can get the regionId
createPrRegionWithDS_DACK.run2();
int regionId = ((PartitionedRegion) getCache().getRegion("PR1")).getPRId();
Set setOfIds = Collections.singleton(otherId);
TestStreamingPartitionOperationOneProviderNoExceptions streamOp = new TestStreamingPartitionOperationOneProviderNoExceptions(getSystem(), regionId);
try {
streamOp.getPartitionedDataFrom(setOfIds);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
Assert.fail("getPartitionedDataFrom failed", t);
}
assertTrue(streamOp.dataValidated);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class PersistentPartitionedRegionTestBase method moveBucket.
protected boolean moveBucket(final int bucketId, VM source, VM target) {
SerializableCallable getId = new SerializableCallable("Get Id") {
public Object call() throws Exception {
Cache cache = getCache();
return cache.getDistributedSystem().getDistributedMember();
}
};
final InternalDistributedMember sourceId = (InternalDistributedMember) source.invoke(getId);
SerializableCallable move = new SerializableCallable("move bucket") {
public Object call() {
Cache cache = getCache();
PartitionedRegion region = (PartitionedRegion) cache.getRegion(PR_REGION_NAME);
return region.getDataStore().moveBucket(bucketId, sourceId, false);
}
};
return (Boolean) target.invoke(move);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class FixedPartitioningTestBase method validateAfterPutPartitionedRegion.
public static void validateAfterPutPartitionedRegion(String customerPartitionedRegionName, String orderPartitionedRegionName, String shipmentPartitionedRegionName) throws ClassNotFoundException {
assertNotNull(cache);
PartitionedRegion customerPartitionedregion = null;
PartitionedRegion orderPartitionedregion = null;
PartitionedRegion shipmentPartitionedregion = null;
try {
customerPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + customerPartitionedRegionName);
orderPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + orderPartitionedRegionName);
shipmentPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + shipmentPartitionedRegionName);
} catch (Exception e) {
org.apache.geode.test.dunit.Assert.fail("validateAfterPutPartitionedRegion : failed while getting the region", e);
}
assertNotNull(customerPartitionedregion);
for (int i = 0; i < 10; i++) {
InternalDistributedMember idmForCustomer = customerPartitionedregion.getBucketPrimary(i);
InternalDistributedMember idmForOrder = orderPartitionedregion.getBucketPrimary(i);
InternalDistributedMember idmForShipment = shipmentPartitionedregion.getBucketPrimary(i);
// take all the keys from the shipment for each bucket
Set customerKey = customerPartitionedregion.getBucketKeys(i);
assertNotNull(customerKey);
Iterator customerIterator = customerKey.iterator();
while (customerIterator.hasNext()) {
CustId custId = (CustId) customerIterator.next();
assertNotNull(customerPartitionedregion.get(custId));
Set orderKey = orderPartitionedregion.getBucketKeys(i);
assertNotNull(orderKey);
Iterator orderIterator = orderKey.iterator();
while (orderIterator.hasNext()) {
OrderId orderId = (OrderId) orderIterator.next();
if (custId.equals(orderId.getCustId())) {
LogWriterUtils.getLogWriter().info(orderId + "belongs to node " + idmForCustomer + " " + idmForOrder);
assertEquals(idmForCustomer, idmForOrder);
}
Set shipmentKey = shipmentPartitionedregion.getBucketKeys(i);
assertNotNull(shipmentKey);
Iterator shipmentIterator = shipmentKey.iterator();
while (shipmentIterator.hasNext()) {
ShipmentId shipmentId = (ShipmentId) shipmentIterator.next();
// assertNotNull(shipmentPartitionedregion.get(shipmentId));
if (orderId.equals(shipmentId.getOrderId())) {
LogWriterUtils.getLogWriter().info(shipmentId + "belongs to node " + idmForOrder + " " + idmForShipment);
}
}
}
}
}
}
Aggregations