Search in sources :

Example 46 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class RemoteTransactionDUnitTest method testPRTXGet.

@Test
public void testPRTXGet() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(accessor, datastore, 0);
    final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.GET));
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertTrue(mgr.isHostedTxInProgress(txId));
            TXStateProxy tx = mgr.getHostedTXState(txId);
            System.out.println("TXRS:" + tx.getRegions());
            // 2 buckets for the two puts we
            assertEquals(3, tx.getRegions().size());
            // plus the dist. region
            for (LocalRegion r : tx.getRegions()) {
                assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion);
                TXRegionState rs = tx.readRegion(r);
                for (Object key : rs.getEntryKeys()) {
                    TXEntryState es = rs.readEntry(key);
                    assertNotNull(es.getValue(key, r, false));
                    assertFalse(es.isDirty());
                }
            }
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.commit();
            verifyAfterCommit(OP.GET);
            return null;
        }
    });
}
Also used : Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 47 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class RemoteTransactionDUnitTest method testRemoteExceptionThrown.

@Test
public void testRemoteExceptionThrown() {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(acc, datastore, 0);
    VM accessor = getVMForTransactions(acc, datastore);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getGemfireCache().getTxManager().setWriter(new TransactionWriter() {

                public void close() {
                }

                public void beforeCommit(TransactionEvent event) throws TransactionWriterException {
                    throw new TransactionWriterException("AssertionError");
                }
            });
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getGemfireCache().getTxManager().begin();
            Region r = getCache().getRegion(CUSTOMER);
            r.put(new CustId(8), new Customer("name8", "address8"));
            try {
                getGemfireCache().getTxManager().commit();
                fail("Expected exception not thrown");
            } catch (Exception e) {
                assertEquals("AssertionError", e.getCause().getMessage());
            }
            return null;
        }
    });
}
Also used : TransactionEvent(org.apache.geode.cache.TransactionEvent) TransactionWriter(org.apache.geode.cache.TransactionWriter) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 48 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class TransactionsWithDeltaDUnitTest method createRegionOnServer.

private Integer createRegionOnServer(VM vm, final boolean startServer, final boolean accessor) {
    return (Integer) vm.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            createRegion(accessor, 0, null);
            if (startServer) {
                int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
                CacheServer s = getCache().addCacheServer();
                s.setPort(port);
                s.start();
                return port;
            }
            return 0;
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 49 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class TransactionsWithDeltaDUnitTest method testExceptionThrown.

@Test
public void testExceptionThrown() {
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setScope(Scope.DISTRIBUTED_ACK);
    final RegionAttributes attr = af.create();
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    final String regionName = getUniqueName();
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            getCache().createRegion(regionName, attr);
            return null;
        }
    };
    vm1.invoke(createRegion);
    vm2.invoke(createRegion);
    final String key = "cust1";
    vm1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            Region r = getCache().getRegion(regionName);
            Customer cust = new Customer(1, "cust1");
            r.put(key, cust);
            mgr.begin();
            cust.setName("");
            try {
                r.put(key, cust);
                fail("exception not thrown");
            } catch (UnsupportedOperationInTransactionException expected) {
            }
            mgr.rollback();
            return null;
        }
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Host(org.apache.geode.test.dunit.Host) InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 50 with SerializableCallable

use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.

the class RemoteTransactionDUnitTest method testTxRemoveAllNotColocated.

@Test
public void testTxRemoveAllNotColocated() {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore1 = host.getVM(1);
    VM datastore2 = host.getVM(3);
    datastore2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            createRegion(false, /* accessor */
            0, null);
            return null;
        }
    });
    initAccessorAndDataStore(acc, datastore1, 0);
    VM accessor = getVMForTransactions(acc, datastore1);
    final CustId custId0 = new CustId(0);
    final CustId custId1 = new CustId(1);
    final CustId custId2 = new CustId(2);
    final CustId custId3 = new CustId(3);
    final CustId custId4 = new CustId(4);
    final CustId custId20 = new CustId(20);
    final TXId txId = (TXId) accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> cust = getGemfireCache().getRegion(CUSTOMER);
            Region<CustId, Customer> ref = getGemfireCache().getRegion(D_REFERENCE);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Customer customer = new Customer("customer1", "address1");
            Customer customer2 = new Customer("customer2", "address2");
            Customer fakeCust = new Customer("foo2", "bar2");
            try {
                cust.removeAll(Arrays.asList(custId0, custId4, custId1, custId2, custId3, custId20));
                fail("expected exception not thrown");
            } catch (TransactionDataNotColocatedException e) {
                mgr.rollback();
            }
            assertNotNull(cust.get(custId0));
            assertNotNull(cust.get(custId1));
            assertNotNull(cust.get(custId2));
            assertNotNull(cust.get(custId3));
            assertNotNull(cust.get(custId4));
            return mgr.getTransactionId();
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Aggregations

SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)502 VM (org.apache.geode.test.dunit.VM)326 Test (org.junit.Test)314 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)311 Host (org.apache.geode.test.dunit.Host)306 Region (org.apache.geode.cache.Region)224 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)157 IgnoredException (org.apache.geode.test.dunit.IgnoredException)155 AttributesFactory (org.apache.geode.cache.AttributesFactory)139 Cache (org.apache.geode.cache.Cache)109 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)95 FunctionException (org.apache.geode.cache.execute.FunctionException)88 ArrayList (java.util.ArrayList)83 HashSet (java.util.HashSet)83 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)77 Execution (org.apache.geode.cache.execute.Execution)74 CommitConflictException (org.apache.geode.cache.CommitConflictException)70 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)66 Function (org.apache.geode.cache.execute.Function)63 IOException (java.io.IOException)62