use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class ClientGetEntryAuthDUnitTest method testGetEntry.
@Test
public void testGetEntry() throws Exception {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
try {
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.getEntry("key3"), "DATA:READ:AuthRegion:key3");
} finally {
transactionManager.commit();
}
});
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
try {
Region region = createProxyRegion(cache, REGION_NAME);
region.getEntry("key3");
} finally {
transactionManager.commit();
}
});
ai1.await();
ai2.await();
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class WANTestBase method doTxPuts.
public static void doTxPuts(String regionName) {
Region r = cache.getRegion(Region.SEPARATOR + regionName);
assertNotNull(r);
CacheTransactionManager mgr = cache.getCacheTransactionManager();
mgr.begin();
r.put(0, 0);
r.put(100, 100);
r.put(200, 200);
mgr.commit();
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method testTXPRRR2_create.
@Test
public void testTXPRRR2_create() throws Exception {
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 {
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
Region rr1 = basicGetCache().getRegion("rregion1");
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.create in tx 1");
pr1.create(dummy, "2_entry__" + i);
LogWriterUtils.getLogWriter().info(" calling rr.create " + "2_entry__" + i);
rr1.create(new Integer(i), "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));
LogWriterUtils.getLogWriter().info(" calling rr.get " + rr1.get(new Integer(i)));
assertEquals("2_entry__" + i, rr1.get(new Integer(i)));
}
return null;
}
};
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());
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
LogWriterUtils.getLogWriter().info(" calling pr.getLocalSize " + pr1.getLocalSize());
assertEquals(2, pr1.getLocalSize());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method testTXPR_RR.
@Test
public void testTXPR_RR() throws Exception {
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 {
// PartitionedRegion pr1 = (PartitionedRegion)
// basicGetCache().getRegion(
// "pregion1");
PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1");
// Region rr1 = basicGetCache().getRegion("rregion1");
Region rr1 = basicGetCache().getRegion("rregion1");
// put some data (non tx ops)
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
LogWriterUtils.getLogWriter().info(" calling pr.put non-tx PR1_entry__" + i);
pr1.put(dummy, "PR1_entry__" + i);
LogWriterUtils.getLogWriter().info(" calling rr.put non-tx RR1_entry__" + i);
rr1.put(new Integer(i), "RR1_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 PR2_entry__" + i);
pr1.put(dummy, "PR2_entry__" + i);
LogWriterUtils.getLogWriter().info(" calling rr.put in tx RR2_entry__" + i);
rr1.put(new Integer(i), "RR2_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 PR2_entry__" + i);
assertEquals("PR2_entry__" + i, pr1.get(dummy));
LogWriterUtils.getLogWriter().info(" calling rr.get RR2_entry__" + i);
assertEquals("RR2_entry__" + i, rr1.get(new Integer(i)));
}
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(2, pr1.getLocalSize());
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);
accessor.invoke(() -> DistTXDebugDUnitTest.destroyPR("pregion1"));
}
use of org.apache.geode.cache.CacheTransactionManager in project geode by apache.
the class DistTXDebugDUnitTest method testTXPR_putall.
@Test
public void testTXPR_putall() 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");
CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager();
ctx.setDistributed(true);
ctx.begin();
HashMap<DummyKeyBasedRoutingResolver, String> phm = new HashMap<DummyKeyBasedRoutingResolver, String>();
HashMap<Integer, String> rhm = new HashMap<Integer, String>();
for (int i = 1; i <= 3; i++) {
DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver(i);
phm.put(dummy, "2_entry__" + i);
}
pr1.putAll(phm);
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;
}
};
// dataStore1.invoke(TxOps);
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(2, pr1.getLocalSize());
return null;
}
};
dataStore1.invoke(verifySize);
dataStore2.invoke(verifySize);
dataStore3.invoke(verifySize);
// accessor.invoke(TxOps);
}
Aggregations