use of org.apache.geode.cache.TransactionId in project geode by apache.
the class RemoteTransactionDUnitTest method testExpirySuspend_bug45984.
@Test
public void testExpirySuspend_bug45984() {
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
final String regionName = getName();
// create region with expiration
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
RegionFactory<String, String> rf = getCache().createRegionFactory();
rf.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.create(regionName);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
return null;
}
});
// create replicate region
vm2.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
return null;
}
});
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
final Region<String, String> r = getCache().getRegion(regionName);
WaitCriterion wc2 = new WaitCriterion() {
@Override
public boolean done() {
return !r.containsKey("key") && !r.containsKey("nonTXKey");
}
@Override
public String description() {
return "did not expire containsKey(key)=" + r.containsKey("key") + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey");
}
};
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
r.put("key", "value");
LocalRegion lr = (LocalRegion) r;
r.put("nonTXkey", "nonTXvalue");
getCache().getCacheTransactionManager().begin();
r.put("key", "newvalue");
TXExpiryJUnitTest.waitForEntryExpiration(lr, "key");
} finally {
ExpiryTask.permitExpiration();
}
TransactionId tx = getCache().getCacheTransactionManager().suspend();
// A remote tx will allow expiration to happen on the side that
// is not hosting the tx. But it will not allow an expiration
// initiated on the hosting jvm.
// tx is hosted in vm2 so expiration can happen in vm1.
Wait.waitForCriterion(wc2, 30000, 5, true);
getCache().getCacheTransactionManager().resume(tx);
assertTrue(r.containsKey("key"));
getCache().getCacheTransactionManager().commit();
Wait.waitForCriterion(wc2, 30000, 5, true);
return null;
}
});
}
use of org.apache.geode.cache.TransactionId in project geode by apache.
the class RemoteTransactionDUnitTest method doSizeTest.
private void doSizeTest(final boolean isAccessor) {
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);
VM taskVM = isAccessor ? accessor : datastore1;
taskVM.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
assertEquals(5, custRegion.size());
assertNotNull(mgr.getTXState());
return null;
}
});
datastore1.invoke(verifyNoTxState);
datastore2.invoke(verifyNoTxState);
taskVM.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
Region orderRegion = getCache().getRegion(ORDER);
TXManagerImpl mgr = getGemfireCache().getTxManager();
TransactionId txId = mgr.suspend();
PartitionedRegion custPR = (PartitionedRegion) custRegion;
int remoteKey = -1;
for (int i = 100; i < 200; i++) {
DistributedMember myId = custPR.getMyId();
if (!myId.equals(custPR.getOwnerForKey(custPR.getKeyInfo(new CustId(i))))) {
remoteKey = i;
break;
}
}
if (remoteKey == -1) {
throw new IllegalStateException("expected non-negative key");
}
mgr.resume(txId);
assertNotNull(mgr.getTXState());
CustId custId = new CustId(remoteKey);
OrderId orderId = new OrderId(remoteKey, custId);
custRegion.put(custId, new Customer("customer" + remoteKey, "address" + remoteKey));
getCache().getLogger().info("Putting " + custId + ", keyInfo:" + custPR.getKeyInfo(new CustId(remoteKey)));
orderRegion.put(orderId, new Order("order" + remoteKey));
assertEquals(6, custRegion.size());
return mgr.getTransactionId();
}
});
final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(1, txOnDatastore1 + txOnDatastore2);
taskVM.invoke(new SerializableCallable() {
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.commit();
return null;
}
});
datastore1.invoke(verifyNoTxState);
datastore2.invoke(verifyNoTxState);
final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress);
final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress);
assertEquals(0, txOnDatastore1_1.intValue());
assertEquals(0, txOnDatastore2_2.intValue());
}
Aggregations