use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testTxRemoveAllWithRedundancy.
@Test
public void testTxRemoveAllWithRedundancy() {
Host host = Host.getHost(0);
VM acc = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(3);
// Create a second data store.
datastore2.invoke(new SerializableCallable() {
public Object call() throws Exception {
createRegion(false, /* accessor */
1, null);
return null;
}
});
initAccessorAndDataStore(acc, datastore1, 1);
VM accessor = getVMForTransactions(acc, datastore1);
// There are 4 buckets, so 0, 4, and 20 are all colocated
final CustId custId0 = new CustId(0);
final CustId custId4 = new CustId(4);
final CustId custId20 = new CustId(20);
final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
cust.removeAll(Arrays.asList(custId0, custId4));
mgr.commit();
assertNull(cust.get(custId0));
assertNull(cust.get(custId4));
return mgr.getTransactionId();
}
});
SerializableCallable checkArtifacts = new SerializableCallable() {
public Object call() throws Exception {
PartitionedRegion cust = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
assertNull(cust.get(custId0));
assertNull(cust.get(custId4));
return null;
}
};
datastore1.invoke(checkArtifacts);
datastore2.invoke(checkArtifacts);
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testRemoteTxCleanupOnCrash.
@Test
public void testRemoteTxCleanupOnCrash() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(accessor, datastore, 0);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region cust = getGemfireCache().getRegion(CUSTOMER);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
cust.put(new CustId(6), new Customer("customer6", "address6"));
return null;
}
});
final InternalDistributedMember member = (InternalDistributedMember) accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
return getGemfireCache().getMyId();
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertEquals(1, mgr.hostedTransactionsInProgressForTest());
mgr.memberDeparted(member, true);
assertEquals(0, mgr.hostedTransactionsInProgressForTest());
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method populateData.
void populateData() {
Region custRegion = getCache().getRegion(CUSTOMER);
Region orderRegion = getCache().getRegion(ORDER);
Region refRegion = getCache().getRegion(D_REFERENCE);
for (int i = 0; i < 5; i++) {
CustId custId = new CustId(i);
Customer customer = new Customer("customer" + i, "address" + i);
OrderId orderId = new OrderId(i, custId);
Order order = new Order("order" + i);
custRegion.put(custId, customer);
orderRegion.put(orderId, order);
refRegion.put(custId, customer);
}
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method testTxRemoveAll.
@Test
public void testTxRemoveAll() {
Host host = Host.getHost(0);
VM acc = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(acc, datastore, 0);
VM accessor = getVMForTransactions(acc, datastore);
final CustId custId1 = new CustId(1);
final CustId custId2 = new CustId(2);
final CustId custId20 = new CustId(20);
final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
Customer customer = new Customer("customer1", "address1");
Customer customer2 = new Customer("customer2", "address2");
Customer fakeCust = new Customer("foo2", "bar2");
cust.removeAll(Arrays.asList(custId1, custId2, custId20));
ref.removeAll(Arrays.asList(custId1, custId2, custId20));
TXStateProxy tx = mgr.internalSuspend();
assertNotNull(cust.get(custId1));
assertNotNull(ref.get(custId2));
mgr.internalResume(tx);
return mgr.getTransactionId();
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertTrue(mgr.isHostedTxInProgress(txId));
TXStateProxy tx = mgr.getHostedTXState(txId);
// 2 buckets for the two puts we
assertEquals(4, tx.getRegions().size());
// different buckets
for (LocalRegion r : tx.getRegions()) {
assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion);
TXRegionState rs = tx.readRegion(r);
for (Object key : rs.getEntryKeys()) {
TXEntryState es = rs.readEntry(key);
assertNull(es.getValue(key, r, false));
// custId20 won't be dirty because it doesn't exist.
assertTrue("key:" + key + " r:" + r.getFullPath(), key.equals(custId20) || es.isDirty());
}
}
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.commit();
Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
Region<CustId, Customer> rr = getGemfireCache().getRegion(D_REFERENCE);
assertNull(cust.get(custId1));
assertNull(rr.get(custId2));
// check conflict
mgr.begin();
CustId custId3 = new CustId(3);
CustId custId4 = new CustId(4);
getGemfireCache().getLoggerI18n().fine("SWAP:removeConflict");
cust.removeAll(Arrays.asList(custId3, custId20, custId4));
TXStateProxy tx = mgr.internalSuspend();
// cust.put(custId3, new Customer("foo", "bar"));
cust.put(custId20, new Customer("foo", "bar"));
assertNotNull(cust.get(custId20));
cust.put(custId4, new Customer("foo", "bar"));
mgr.internalResume(tx);
try {
mgr.commit();
fail("expected exception not thrown");
} catch (CommitConflictException e) {
}
assertNotNull(cust.get(custId3));
assertNotNull(cust.get(custId4));
assertNotNull(cust.get(custId20));
// Test a removeall an already missing key.
// custId2 has already been removed
mgr.begin();
getGemfireCache().getLoggerI18n().fine("SWAP:removeConflict");
cust.removeAll(Arrays.asList(custId2, custId3));
tx = mgr.internalSuspend();
cust.put(custId2, new Customer("foo", "bar"));
mgr.internalResume(tx);
mgr.commit();
assertNotNull(cust.get(custId2));
assertNull(cust.get(custId3));
return null;
}
});
}
use of org.apache.geode.internal.cache.execute.data.Customer in project geode by apache.
the class RemoteTransactionDUnitTest method doRemoteJTA.
private void doRemoteJTA(final boolean isCommit) {
Host host = Host.getHost(0);
VM acc = host.getVM(0);
VM datastore = host.getVM(1);
initAccessorAndDataStore(acc, datastore, 0);
VM accessor = getVMForTransactions(acc, datastore);
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
getGemfireCache().getTxManager().addListener(new TestTxListener(false));
return null;
}
});
final CustId expectedCustId = new CustId(6);
final Customer expectedCustomer = new Customer("customer6", "address6");
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
getGemfireCache().getTxManager().addListener(new TestTxListener(true));
Region custRegion = getCache().getRegion(CUSTOMER);
Context ctx = getCache().getJNDIContext();
UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");
assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
tx.begin();
assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
custRegion.put(expectedCustId, expectedCustomer);
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
return null;
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
assertNull(custRegion.get(expectedCustId));
return null;
}
});
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region custRegion = getCache().getRegion(CUSTOMER);
Context ctx = getCache().getJNDIContext();
UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");
if (isCommit) {
tx.commit();
assertEquals(expectedCustomer, custRegion.get(expectedCustId));
} else {
tx.rollback();
assertNull(custRegion.get(expectedCustId));
}
return null;
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
TestTxListener l = (TestTxListener) getGemfireCache().getTXMgr().getListener();
assertTrue(l.isListenerInvoked());
return null;
}
});
}
Aggregations