use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method testTXPR_removeAll.
@Test
public void testTXPR_removeAll() throws Exception {
createCacheInAllVms();
Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, Boolean.FALSE, Boolean.FALSE };
createPartitionedRegion(prAttrs);
SerializableCallable TxOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
HashMap<DummyKeyBasedRoutingResolver, String> phm = new HashMap<DummyKeyBasedRoutingResolver, String>();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
phm.put(dummy, "2_entry__" + i);
}
pr1.putAll(phm);
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
pr1.removeAll(phm.keySet());
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy));
assertEquals(null, pr1.get(dummy));
}
return null;
}
};
accessor.invoke(TxOps);
// verify data size on all replicas
SerializableCallable verifySize = new SerializableCallable("getOps") {
@Override
public Object call() throws CacheException {
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
LogWriterUtils.getLogWriter().info(" calling pr.getLocalSize " + pr1.getLocalSize());
assertEquals(0, pr1.getLocalSize());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
// accessor.invoke(TxOps);
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method testTXPR2.
@Test
public void testTXPR2() throws Exception {
createCacheInAllVms();
Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, Boolean.FALSE, Boolean.FALSE };
createPartitionedRegion(prAttrs);
SerializableCallable TxOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
// PartitionedRegion pr1 = (PartitionedRegion)
// basicGetCache().getRegion(
// "pregion1");
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
// put in tx and commit
// CacheTransactionManager ctx = basicGetCache()
// .getCacheTransactionManager();
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.put in tx 1");
pr1.put(dummy, "2_entry__" + i);
}
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy));
assertEquals("2_entry__" + i, pr1.get(dummy));
}
return null;
}
};
accessor.invoke(TxOps);
SerializableCallable TxGetOps = new SerializableCallable("TxGetOps") {
@Override
public Object call() throws CacheException {
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
LogWriterUtils.getLogWriter().info(" calling pr.getLocalSize " + pr1.getLocalSize());
assertEquals(2, pr1.getLocalSize());
return null;
}
};
dataStore1.invoke(TxGetOps);
dataStore2.invoke(TxGetOps);
dataStore3.invoke(TxGetOps);
SerializableCallable TxRollbackOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
// PartitionedRegion pr1 = (PartitionedRegion)
// basicGetCache().getRegion(
// "pregion1");
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
// put in tx and commit
// CacheTransactionManager ctx = basicGetCache()
// .getCacheTransactionManager();
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.put in tx for rollback no_entry__" + i);
pr1.put(dummy, "no_entry__" + i);
}
ctx.rollback();
// verify the data
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.get after rollback " + pr1.get(dummy));
assertEquals("2_entry__" + i, pr1.get(dummy));
}
return null;
}
};
accessor.invoke(TxRollbackOps);
accessor.invoke(() -> DistTXDebugDUnitTest.destroyPR("pregion1"));
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method testTXPR.
@Test
public void testTXPR() throws Exception {
createCacheInAllVms();
Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, Boolean.FALSE, Boolean.FALSE };
createPartitionedRegion(prAttrs);
SerializableCallable TxOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
// PartitionedRegion pr1 = (PartitionedRegion)
// basicGetCache().getRegion(
// "pregion1");
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
// put some data (non tx ops)
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.put");
pr1.put(dummy, "1_entry__" + i);
}
// put in tx and commit
// CacheTransactionManager ctx = basicGetCache()
// .getCacheTransactionManager();
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.put in tx 1");
pr1.put(dummy, "2_entry__" + i);
}
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.get");
assertEquals("2_entry__" + i, pr1.get(dummy));
}
// put data in tx and rollback
ctx.begin();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.put in tx 2");
pr1.put(dummy, "3_entry__" + i);
}
ctx.rollback();
// verify the data
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.get");
assertEquals("2_entry__" + i, pr1.get(dummy));
}
// destroy data in tx and commit
ctx.begin();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.destroy in tx 3");
pr1.destroy(dummy);
}
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.get");
assertEquals(null, pr1.get(dummy));
}
// verify data size on all replicas
SerializableCallable verifySize = new SerializableCallable("getOps") {
@Override
public Object call() throws CacheException {
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
LogWriterUtils.getLogWriter().info(" calling pr.getLocalSize " + pr1.getLocalSize());
assertEquals(0, pr1.getLocalSize());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
return null;
}
};
accessor.invoke(TxOps);
accessor.invoke(() -> DistTXDebugDUnitTest.destroyPR("pregion1"));
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method performTXRRtestOps.
public void performTXRRtestOps(boolean makeDatNodeAsCoordinator) {
createCacheInAllVms();
Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, Boolean.FALSE, Boolean.FALSE };
createPartitionedRegion(prAttrs);
Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE };
createReplicatedRegion(rrAttrs);
SerializableCallable TxOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
for (int i = 1; i <= 3; i++) {
LogWriterUtils.getLogWriter().info(" calling rr.put " + "2_entry__" + i);
rr1.put(new Integer(i), "2_entry__" + i);
}
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
LogWriterUtils.getLogWriter().info(" calling rr.get " + rr1.get(new Integer(i)));
assertEquals("2_entry__" + i, rr1.get(new Integer(i)));
}
return null;
}
};
if (makeDatNodeAsCoordinator) {
dataStore1.invoke(TxOps);
} else {
accessor.invoke(TxOps);
}
// verify data size on all replicas
SerializableCallable verifySize = new SerializableCallable("getOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
LogWriterUtils.getLogWriter().info(" calling rr.getLocalSize " + rr1.size());
assertEquals(3, rr1.size());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
SerializableCallable TxRollbackOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
for (int i = 1; i <= 3; i++) {
LogWriterUtils.getLogWriter().info(" calling rr.put for rollback no_entry__" + i);
rr1.put(new Integer(i), "no_entry__" + i);
}
ctx.rollback();
;
// verify the data
for (int i = 1; i <= 3; i++) {
LogWriterUtils.getLogWriter().info(" calling rr.get after rollback " + rr1.get(new Integer(i)));
assertEquals("2_entry__" + i, rr1.get(new Integer(i)));
}
return null;
}
};
if (makeDatNodeAsCoordinator) {
dataStore1.invoke(TxRollbackOps);
} else {
accessor.invoke(TxRollbackOps);
}
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method performRR_removeAllTest.
/**
* @param dataNodeAsCoordinator TODO
*
*/
private void performRR_removeAllTest(boolean dataNodeAsCoordinator) {
createCacheInAllVms();
Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE };
createReplicatedRegion(rrAttrs);
SerializableCallable TxOps = new SerializableCallable("TxOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
// put some data
HashMap<Integer, String> rhm = new HashMap<Integer, String>();
for (int i = 1; i <= 3; i++) {
rhm.put(i, "2_entry__" + i);
}
rr1.putAll(rhm);
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
rr1.removeAll(rhm.keySet());
ctx.commit();
// verify the data
for (int i = 1; i <= 3; i++) {
LogWriterUtils.getLogWriter().info(" calling rr.get " + rr1.get(new Integer(i)));
assertEquals(null, rr1.get(new Integer(i)));
}
return null;
}
};
if (dataNodeAsCoordinator) {
dataStore1.invoke(TxOps);
} else {
accessor.invoke(TxOps);
}
// verify data size on all replicas
SerializableCallable verifySize = new SerializableCallable("getOps") {
@Override
public Object call() throws CacheException {
Region rr1 = basicGetCache().getRegion("rregion1");
LogWriterUtils.getLogWriter().info(" calling rr.getLocalSize " + rr1.size());
assertEquals(0, rr1.size());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
// accessor.invoke(TxOps);
}
Aggregations