use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GemFireDeadlockDetectorDUnitTest method testDistributedDeadlockWithFunction.
// @Category(FlakyTest.class) // GEODE-516 & GEODE-576: async actions, thread sleeps, time
// sensitive
@Test
public void testDistributedDeadlockWithFunction() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
getSystem();
InternalDistributedMember member1 = createCache(vm0);
final InternalDistributedMember member2 = createCache(vm1);
getBlackboard().initBlackboard();
// Have two threads lock locks on different members in different orders.
String gateOnMember1 = "gateOnMember1";
String gateOnMember2 = "gateOnMember2";
// This thread locks the lock member1 first, then member2.
AsyncInvocation async1 = lockTheLocks(vm0, member2, gateOnMember1, gateOnMember2);
// This thread locks the lock member2 first, then member1.
AsyncInvocation async2 = lockTheLocks(vm1, member1, gateOnMember2, gateOnMember1);
try {
final LinkedList<Dependency>[] deadlockHolder = new LinkedList[1];
Awaitility.await("waiting for deadlock").atMost(20, TimeUnit.SECONDS).until(() -> {
GemFireDeadlockDetector detect = new GemFireDeadlockDetector();
LinkedList<Dependency> deadlock = detect.find().findCycle();
if (deadlock != null) {
deadlockHolder[0] = deadlock;
}
return deadlock != null;
});
LinkedList<Dependency> deadlock = deadlockHolder[0];
LogWriterUtils.getLogWriter().info("Deadlock=" + DeadlockDetector.prettyFormat(deadlock));
assertEquals(8, deadlock.size());
stopStuckThreads();
} finally {
try {
waitForAsyncInvocation(async1, 45, TimeUnit.SECONDS);
} finally {
waitForAsyncInvocation(async2, 45, TimeUnit.SECONDS);
}
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionAdvisorDUnitTest method postSetUp.
@Override
public final void postSetUp() throws Exception {
// connect to distributed system in every VM
Invoke.invokeInEveryVM(new SerializableRunnable("DistributionAdvisorDUnitTest: SetUp") {
public void run() {
getSystem();
}
});
// reinitialize the advisor
this.advisor = DistributionAdvisor.createDistributionAdvisor(new DistributionAdvisee() {
public DistributionAdvisee getParentAdvisee() {
return null;
}
public InternalDistributedSystem getSystem() {
return DistributionAdvisorDUnitTest.this.getSystem();
}
public String getName() {
return "DistributionAdvisorDUnitTest";
}
public String getFullPath() {
return getName();
}
public DM getDistributionManager() {
return getSystem().getDistributionManager();
}
public DistributionAdvisor getDistributionAdvisor() {
return DistributionAdvisorDUnitTest.this.advisor;
}
public DistributionAdvisor.Profile getProfile() {
return null;
}
public void fillInProfile(DistributionAdvisor.Profile profile) {
}
public int getSerialNumber() {
return 0;
}
public CancelCriterion getCancelCriterion() {
return DistributionAdvisorDUnitTest.this.getSystem().getCancelCriterion();
}
});
Set ids = getSystem().getDistributionManager().getOtherNormalDistributionManagerIds();
assertEquals(VM.getVMCount(), ids.size());
List profileList = new ArrayList();
int i = 0;
for (Iterator itr = ids.iterator(); itr.hasNext(); i++) {
InternalDistributedMember id = (InternalDistributedMember) itr.next();
DistributionAdvisor.Profile profile = new DistributionAdvisor.Profile(id, 0);
// add profile to advisor
advisor.putProfile(profile);
profileList.add(profile);
}
this.profiles = (DistributionAdvisor.Profile[]) profileList.toArray(new DistributionAdvisor.Profile[profileList.size()]);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class CacheAdvisorDUnitTest method testNetWriteAdvice.
@Test
public void testNetWriteAdvice() throws Exception {
final String rgnName = getUniqueName();
Set expected = new HashSet();
for (int i = 0; i < vms.length; i++) {
VM vm = vms[i];
InternalDistributedMember id = ids[i];
if (i % 2 == 0) {
expected.add(id);
}
final int index = i;
vm.invoke(new CacheSerializableRunnable("CacheAdvisorDUnitTest.testNetWriteAdvice") {
public void run2() throws CacheException {
AttributesFactory fac = new AttributesFactory();
if (index % 2 == 0) {
fac.setCacheWriter(new CacheWriterAdapter());
}
createRegion(rgnName, fac.create());
}
});
}
RegionAttributes attrs = new AttributesFactory().create();
DistributedRegion rgn = (DistributedRegion) createRegion(rgnName, attrs);
assertEquals(expected, rgn.getCacheDistributionAdvisor().adviseNetWrite());
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributedCacheOperationTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
DistributedCacheOperation mockDistributedCacheOperation = mock(DistributedCacheOperation.class);
CacheOperationMessage mockCacheOperationMessage = mock(CacheOperationMessage.class);
Map<InternalDistributedMember, PersistentMemberID> persistentIds = new HashMap<>();
when(mockDistributedCacheOperation.supportsDirectAck()).thenReturn(false);
mockDistributedCacheOperation.waitForAckIfNeeded(mockCacheOperationMessage, persistentIds);
verify(mockDistributedCacheOperation, times(1)).waitForAckIfNeeded(mockCacheOperationMessage, persistentIds);
assertThat(mockDistributedCacheOperation.supportsDirectAck()).isFalse();
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember 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;
}
});
}
Aggregations