Search in sources :

Example 16 with CacheTransactionManager

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);
}
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)

Example 17 with CacheTransactionManager

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"));
}
Also used : 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)

Example 18 with CacheTransactionManager

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"));
}
Also used : 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)

Example 19 with CacheTransactionManager

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);
    }
}
Also used : 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)

Example 20 with CacheTransactionManager

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);
}
Also used : HashMap(java.util.HashMap) 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)

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