use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PartitionListenerDUnitTest method createPR.
protected DistributedMember createPR(VM vm, final String regionName, final boolean isAccessor) throws Throwable {
SerializableCallable createPrRegion = new SerializableCallable("createRegion") {
public Object call() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
if (isAccessor) {
paf.setLocalMaxMemory(0);
}
paf.addPartitionListener(new TestPartitionListener());
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion(regionName, attr.create());
return cache.getDistributedSystem().getDistributedMember();
}
};
return (DistributedMember) vm.invoke(createPrRegion);
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class RemoteTransactionDUnitTest method testTxFunctionWithOtherOps.
@Test
public void testTxFunctionWithOtherOps() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(2);
initAccessorAndDataStore(accessor, datastore1, datastore2, 0);
SerializableCallable registerFunction = new SerializableCallable() {
public Object call() throws Exception {
FunctionService.registerFunction(new TXFunction());
return null;
}
};
accessor.invoke(registerFunction);
datastore1.invoke(registerFunction);
datastore2.invoke(registerFunction);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getGemfireCache().getRegion(CUSTOMER);
TXManagerImpl mgr = getGemfireCache().getTXMgr();
mgr.begin();
try {
FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult();
fail("Expected exception not thrown");
} catch (TransactionException expected) {
}
Set filter = new HashSet();
filter.add(expectedCustId);
FunctionService.onRegion(custRegion).withFilter(filter).execute(TXFunction.id).getResult();
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
TXStateProxy tx = mgr.internalSuspend();
assertNull(custRegion.get(expectedCustId));
mgr.internalResume(tx);
return null;
}
});
final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(1, txOnDatastore1 + txOnDatastore2);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getGemfireCache().getRegion(CUSTOMER);
CacheTransactionManager mgr = getGemfireCache().getTXMgr();
mgr.commit();
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
custRegion.destroy(expectedCustId);
return null;
}
});
// test onMembers
SerializableCallable getMember = new SerializableCallable() {
public Object call() throws Exception {
return getGemfireCache().getMyId();
}
};
final InternalDistributedMember ds1 = (InternalDistributedMember) datastore1.invoke(getMember);
final InternalDistributedMember ds2 = (InternalDistributedMember) datastore2.invoke(getMember);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
// get owner for expectedKey
DistributedMember owner = pr.getOwnerForKey(pr.getKeyInfo(expectedCustId));
// get key on datastore1
CustId keyOnOwner = null;
keyOnOwner = getKeyOnMember(owner, pr);
TXManagerImpl mgr = getGemfireCache().getTXMgr();
mgr.begin();
// bootstrap tx on owner
pr.get(keyOnOwner);
Set<DistributedMember> members = new HashSet<DistributedMember>();
members.add(ds1);
members.add(ds2);
try {
FunctionService.onMembers(members).execute(TXFunction.id).getResult();
fail("expected exception not thrown");
} catch (TransactionException expected) {
}
FunctionService.onMember(owner).execute(TXFunction.id).getResult();
assertEquals(expectedCustomer, pr.get(expectedCustId));
TXStateProxy tx = mgr.internalSuspend();
assertNull(pr.get(expectedCustId));
mgr.internalResume(tx);
return null;
}
});
final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2_1 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(1, txOnDatastore1_1 + txOnDatastore2_1);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getGemfireCache().getRegion(CUSTOMER);
CacheTransactionManager mgr = getGemfireCache().getTXMgr();
mgr.commit();
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
custRegion.destroy(expectedCustId);
return null;
}
});
// test function execution on data store
final DistributedMember owner = (DistributedMember) accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
return pr.getOwnerForKey(pr.getKeyInfo(expectedCustId));
}
});
SerializableCallable testFnOnDs = new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTXMgr();
PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
CustId keyOnDs = getKeyOnMember(pr.getMyId(), pr);
mgr.begin();
pr.get(keyOnDs);
Set filter = new HashSet();
filter.add(keyOnDs);
FunctionService.onRegion(pr).withFilter(filter).execute(TXFunction.id).getResult();
assertEquals(expectedCustomer, pr.get(expectedCustId));
TXStateProxy tx = mgr.internalSuspend();
assertNull(pr.get(expectedCustId));
mgr.internalResume(tx);
return null;
}
};
SerializableCallable closeTx = new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getGemfireCache().getRegion(CUSTOMER);
CacheTransactionManager mgr = getGemfireCache().getTXMgr();
mgr.commit();
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
custRegion.destroy(expectedCustId);
return null;
}
};
if (owner.equals(ds1)) {
datastore1.invoke(testFnOnDs);
final Integer txOnDatastore1_2 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
// ds1 has a local transaction, not
assertEquals(0, txOnDatastore1_2 + txOnDatastore2_2);
// remote
datastore1.invoke(closeTx);
} else {
datastore2.invoke(testFnOnDs);
final Integer txOnDatastore1_2 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
// ds1 has a local transaction, not
assertEquals(0, txOnDatastore1_2 + txOnDatastore2_2);
// remote
datastore2.invoke(closeTx);
}
// test that function is rejected if function target is not same as txState target
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTXMgr();
PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
CustId keyOnDs1 = getKeyOnMember(ds1, pr);
CustId keyOnDs2 = getKeyOnMember(ds2, pr);
mgr.begin();
// bootstrap txState
pr.get(keyOnDs1);
Set filter = new HashSet();
filter.add(keyOnDs2);
try {
FunctionService.onRegion(pr).withFilter(filter).execute(TXFunction.id).getResult();
fail("expected Exception not thrown");
} catch (TransactionDataRebalancedException expected) {
}
try {
FunctionService.onMember(ds2).execute(TXFunction.id).getResult();
fail("expected exception not thrown");
} catch (TransactionDataNotColocatedException expected) {
}
mgr.commit();
return null;
}
});
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class RemoteTransactionDUnitTest method doTestTxFunction.
private void doTestTxFunction(final Executions e) {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(2);
initAccessorAndDataStore(accessor, datastore1, datastore2, 0);
SerializableCallable registerFunction = new SerializableCallable() {
public Object call() throws Exception {
FunctionService.registerFunction(new TXFunction());
return null;
}
};
accessor.invoke(registerFunction);
datastore1.invoke(registerFunction);
datastore2.invoke(registerFunction);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
PartitionedRegion custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
TXManagerImpl mgr = getGemfireCache().getTXMgr();
Set regions = new HashSet();
regions.add(custRegion);
regions.add(getGemfireCache().getRegion(ORDER));
mgr.begin();
try {
switch(e) {
case OnRegion:
FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult();
break;
case OnMember:
FunctionService.onMembers().execute(TXFunction.id).getResult();
break;
}
fail("Expected exception not thrown");
} catch (TransactionException expected) {
}
try {
InternalFunctionService.onRegions(regions).execute(TXFunction.id).getResult();
fail("Expected exception not thrown");
} catch (TransactionException expected) {
}
Set filter = new HashSet();
filter.add(expectedCustId);
switch(e) {
case OnRegion:
FunctionService.onRegion(custRegion).withFilter(filter).execute(TXFunction.id).getResult();
break;
case OnMember:
DistributedMember owner = custRegion.getOwnerForKey(custRegion.getKeyInfo(expectedCustId));
FunctionService.onMember(owner).execute(TXFunction.id).getResult();
break;
}
TXStateProxy tx = mgr.internalSuspend();
GemFireCacheImpl.getInstance().getLogger().warning("TX SUSPENDO:" + tx);
assertNull(custRegion.get(expectedCustId));
mgr.internalResume(tx);
return null;
}
});
final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(1, txOnDatastore1 + txOnDatastore2);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTXMgr();
mgr.commit();
return null;
}
});
datastore1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getGemfireCache().getRegion(CUSTOMER);
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTXMgr();
mgr.begin();
PartitionedRegion custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
Set filter = new HashSet();
filter.add(expectedCustId);
switch(e) {
case OnRegion:
FunctionService.onRegion(custRegion).withFilter(filter).execute(TXFunction.id).getResult();
break;
case OnMember:
DistributedMember owner = custRegion.getOwnerForKey(custRegion.getKeyInfo(expectedCustId));
FunctionService.onMember(owner).execute(TXFunction.id).getResult();
break;
}
TXStateProxy tx = mgr.internalSuspend();
custRegion.put(expectedCustId, new Customer("Cust6", "updated6"));
mgr.internalResume(tx);
try {
mgr.commit();
fail("expected commit conflict not thrown");
} catch (CommitConflictException expected) {
}
return null;
}
});
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method serverAllKeyExecution.
public static void serverAllKeyExecution(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() / 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TEST_FUNCTION2);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = executeOnAll(dataSet, Boolean.TRUE, function, isByName);
List resultList = (List) ((List) rc1.getResult());
LogWriterUtils.getLogWriter().info("Result size : " + resultList.size());
LogWriterUtils.getLogWriter().info("Result are SSSS : " + resultList);
assertEquals(3, resultList.size());
Iterator resultIterator = resultList.iterator();
Map.Entry entry = null;
DistributedMember key = null;
List resultListForMember = new ArrayList();
// }
for (Object result : resultList) {
assertEquals(Boolean.TRUE, result);
}
List l2 = null;
ResultCollector rc2 = executeOnAll(dataSet, testKeysSet, function, isByName);
l2 = ((List) rc2.getResult());
assertEquals(3, l2.size());
HashSet foundVals = new HashSet();
for (Iterator i = l2.iterator(); i.hasNext(); ) {
ArrayList subL = (ArrayList) (i.next());
assertTrue(subL.size() > 0);
for (Iterator subI = subL.iterator(); subI.hasNext(); ) {
assertTrue(foundVals.add(subI.next()));
}
}
assertEquals(origVals, foundVals);
} catch (Exception e) {
Assert.fail("Test failed after the put operation", e);
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method FunctionExecution_Inline_Bug40714.
public static void FunctionExecution_Inline_Bug40714() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
int j = 0;
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
region.put(i.next(), val);
}
HashMap resultMap = (HashMap) FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else if (context.getArguments() instanceof Boolean) {
context.getResultSender().lastResult(Boolean.TRUE);
}
}
public String getId() {
return "Function";
}
public boolean hasResult() {
return true;
}
}).getResult();
assertEquals(3, resultMap.size());
Iterator mapIterator = resultMap.entrySet().iterator();
Map.Entry entry = null;
DistributedMember key = null;
ArrayList resultListForMember = null;
while (mapIterator.hasNext()) {
entry = (Map.Entry) mapIterator.next();
key = (DistributedMember) entry.getKey();
resultListForMember = (ArrayList) entry.getValue();
for (Object result : resultListForMember) {
assertEquals(Boolean.TRUE, result);
}
}
}
Aggregations