Search in sources :

Example 71 with CacheTransactionManager

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();
}
Also used : SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 72 with CacheTransactionManager

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();
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 73 with CacheTransactionManager

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);
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 74 with CacheTransactionManager

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"));
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 75 with CacheTransactionManager

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);
}
Also used : HashMap(java.util.HashMap) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)120 Region (org.apache.geode.cache.Region)81 Test (org.junit.Test)77 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)53 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)52 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)51 VM (org.apache.geode.test.dunit.VM)51 LocalRegion (org.apache.geode.internal.cache.LocalRegion)46 CommitConflictException (org.apache.geode.cache.CommitConflictException)45 Host (org.apache.geode.test.dunit.Host)45 CustId (org.apache.geode.internal.cache.execute.data.CustId)37 Customer (org.apache.geode.internal.cache.execute.data.Customer)34 BucketRegion (org.apache.geode.internal.cache.BucketRegion)27 AttributesFactory (org.apache.geode.cache.AttributesFactory)26 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)24 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)23 IgnoredException (org.apache.geode.test.dunit.IgnoredException)23 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)22 CacheWriterException (org.apache.geode.cache.CacheWriterException)21 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)21