use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class TXOrderDUnitTest method doCommitOtherVm.
private void doCommitOtherVm() {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
Region r1 = createRootRegion("r1", af.create());
Region r2 = r1.createSubregion("r2", af.create());
Region r3 = r2.createSubregion("r3", af.create());
CacheTransactionManager ctm = getCache().getCacheTransactionManager();
ctm.begin();
r2.put("b", "value1");
r3.put("c", "value2");
r1.put("a", "value3");
r1.put("a2", "value4");
r3.put("c2", "value5");
r2.put("b2", "value6");
ctm.commit();
}
});
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalUpdates.
@Test
public void testTransactionalUpdates() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
mgr.begin();
createPR(false, 0, null);
Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
for (int i = 1; i <= 200; i++) {
custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
}
assertEquals(200, custPR.size());
mgr.rollback();
// mgr.commit();
mgr.begin();
assertEquals(0, custPR.size());
mgr.commit();
mgr.begin();
for (int i = 1; i <= 200; i++) {
custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
}
mgr.commit();
// mgr.begin();
for (int i = 1; i <= 200; i++) {
mgr.begin();
custPR.put(new CustId(i), new Customer("name" + i * 2, "addr" + i * 2));
mgr.commit();
}
mgr.begin();
mgr.rollback();
assertEquals(200, custPR.size());
for (int i = 1; i <= 200; i++) {
assertEquals(new Customer("name" + i * 2, "addr" + i * 2), custPR.get(new CustId(i)));
}
return null;
}
});
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalKeyBasedUpdates.
@Test
public void testTransactionalKeyBasedUpdates() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createPR(new VM[] { server1, server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
// mgr.begin();
LogWriterI18n logger = getGemfireCache().getLoggerI18n();
Region<CustId, Customer> custPR = getCache().getRegion(CUSTOMER_PR);
for (int i = 1; i <= 2; i++) {
mgr.begin();
logger.fine("TEST:PUT-" + i);
custPR.put(new CustId(i), new Customer("name" + i, "addr" + i));
logger.fine("TEST:COMMIT-" + i);
mgr.commit();
}
// Updates
for (int i = 1; i <= 2; i++) {
CustId custId = new CustId(i);
Customer customer = custPR.get(custId);
assertNotNull(customer);
mgr.begin();
logger.fine("TEST:UPDATE-" + i);
custPR.put(custId, new Customer("name" + i * 2, "addr" + i * 2));
logger.fine("TEST:UPDATED-" + i + "=" + custId + "," + custPR.get(custId));
logger.fine("TEST:UPDATE COMMIT-" + i);
mgr.commit();
logger.fine("TEST:POSTCOMMIT-" + i + "=" + custId + "," + custPR.get(custId));
}
// Verify
for (int i = 1; i <= 2; i++) {
CustId custId = new CustId(i);
Customer customer = custPR.get(custId);
assertNotNull(customer);
logger.fine("TEST:VERIFYING-" + i);
assertEquals(new Customer("name" + i * 2, "addr" + i * 2), customer);
}
return null;
}
});
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistributedTransactionDUnitTest method testNonColocatedPutByPartitioning.
/*
* We create 2 partitioned regions one on each server and have a third node as accessor and fire
* transactional operations on it.
*/
@Test
public void testNonColocatedPutByPartitioning() {
Host host = Host.getHost(0);
// datastore
VM server1 = host.getVM(0);
// datastore
VM server2 = host.getVM(1);
// accessor
VM server3 = host.getVM(2);
final String CUSTOMER_PR1 = "CUSTOMER_PR1";
final String CUSTOMER_PR2 = "CUSTOMER_PR2";
// Create CUSTOMER_PR1 on server1
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
getCache().createRegion(CUSTOMER_PR1, af.create());
return null;
}
});
// Create CUSTOMER_PR2 on server2
execute(server2, new SerializableCallable() {
@Override
public Object call() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(0).create());
getCache().createRegion(CUSTOMER_PR2, af.create());
return null;
}
});
// Create both the regions on server3 (accessor)
execute(server3, new SerializableCallable() {
@Override
public Object call() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(// since this is an accessor
0).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
getCache().createRegion(CUSTOMER_PR1, af.create());
return null;
}
});
execute(server3, new SerializableCallable() {
@Override
public Object call() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(// since this is an accessor
0).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(0).create());
getCache().createRegion(CUSTOMER_PR2, af.create());
return null;
}
});
// Now perform tx ops on accessor
execute(server3, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
mgr.begin();
Region<CustId, Customer> custPR1 = getCache().getRegion(CUSTOMER_PR1);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
custPR1.put(custIdOne, customerOne);
Region<CustId, Customer> custPR2 = getCache().getRegion(CUSTOMER_PR2);
custPR2.put(custIdOne, customerOne);
mgr.commit();
// Verify
assertEquals(1, custPR1.size());
assertEquals(1, custPR2.size());
return null;
}
});
// Verify on one of the servers
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> custPR1 = getCache().getRegion(CUSTOMER_PR1);
assertEquals(1, custPR1.size());
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
assertEquals(customerOne, custPR1.get(custIdOne));
return null;
}
});
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistributedTransactionDUnitTest method testTransactionalKeyBasedDestroys_RR.
@Test
public void testTransactionalKeyBasedDestroys_RR() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
createRR(new VM[] { server1, server2, server3 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
// mgr.begin();
Region<CustId, Customer> custRR = getCache().getRegion(CUSTOMER_RR);
for (int i = 1; i <= 1000; i++) {
mgr.begin();
custRR.put(new CustId(i), new Customer("name" + i, "addr" + i));
mgr.commit();
}
// Destroys
for (int i = 1; i <= 100; i++) {
CustId custId = new CustId(i);
mgr.begin();
Object customerRemoved = custRR.remove(custId);
assertNotNull(customerRemoved);
mgr.commit();
}
// Verify
for (int i = 1; i <= 100; i++) {
CustId custId = new CustId(1);
Customer customer = custRR.get(custId);
assertNull(customer);
}
assertEquals(900, custRR.size());
return null;
}
});
}
Aggregations