Search in sources :

Example 21 with CustId

use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.

the class ClientServerTransactionDUnitTest method testClientCommitsAndJustGets.

@Test
public void testClientCommitsAndJustGets() throws Exception {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    VM client = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore, 0);
    int port = startServer(accessor);
    createClientRegion(client, port, false, true);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            custRegion.getAttributesMutator().addCacheListener(new ClientListener());
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            // Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            // Region<CustId,Customer> refRegion = getCache().getRegion(D_REFERENCE);
            CustId custId = new CustId(1);
            // OrderId orderId = new OrderId(1, custId);
            getCache().getCacheTransactionManager().begin();
            custRegion.get(custId);
            // orderRegion.put(orderId, new Order("fooOrder"));
            // refRegion.put(custId, new Customer("foo", "bar"));
            getCache().getCacheTransactionManager().commit();
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) RollbackException(javax.transaction.RollbackException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 22 with CustId

use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.

the class ClientServerTransactionDUnitTest method testSuspendTimeout.

@Test
public void testSuspendTimeout() throws Exception {
    Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    final int port = createRegionsAndStartServer(server, false);
    createClientRegion(client, port, true);
    final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            TXManagerImpl mgr = (TXManagerImpl) getCache().getCacheTransactionManager();
            mgr.setSuspendedTransactionTimeout(1);
            Region r = getCache().getRegion(CUSTOMER);
            assertNull(r.get(new CustId(101)));
            mgr.begin();
            final TXStateProxy txState = mgr.getTXState();
            assertTrue(txState.isInProgress());
            r.put(new CustId(101), new Customer("name101", "address101"));
            TransactionId txId = mgr.suspend(TimeUnit.MILLISECONDS);
            WaitCriterion waitForTxTimeout = new WaitCriterion() {

                public boolean done() {
                    return !txState.isInProgress();
                }

                public String description() {
                    return "txState stayed in progress indicating that the suspend did not timeout";
                }
            };
            // tx should timeout after 1 ms but to deal with loaded machines and thread
            // scheduling latency wait for 10 seconds before reporting an error.
            Wait.waitForCriterion(waitForTxTimeout, 10 * 1000, 10, true);
            try {
                mgr.resume(txId);
                fail("expected exception not thrown");
            } catch (IllegalStateException expected) {
            }
            assertNull(r.get(new CustId(101)));
            return txId;
        }
    });
    server.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            TXManagerImpl mgr = (TXManagerImpl) getCache().getCacheTransactionManager();
            assertNull(mgr.getHostedTXState((TXId) txId));
            assertEquals(0, mgr.hostedTransactionsInProgressForTest());
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) RollbackException(javax.transaction.RollbackException) CustId(org.apache.geode.internal.cache.execute.data.CustId) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 23 with CustId

use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.

the class ClientServerTransactionDUnitTest method testClientDoesUnsupportedLocalOps.

@Test
public void testClientDoesUnsupportedLocalOps() throws Exception {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    VM client = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore, 0);
    int port = startServer(accessor);
    createClientRegion(client, port, false, true);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER);
            custRegion.getAttributesMutator().addCacheListener(new ClientListener());
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            // Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            // Region<CustId,Customer> refRegion = getCache().getRegion(D_REFERENCE);
            CustId custId = new CustId(1);
            // OrderId orderId = new OrderId(1, custId);
            custRegion.put(custId, new Customer("foo", "bar"));
            getCache().getCacheTransactionManager().begin();
            try {
                custRegion.localDestroy(custId);
                fail("Should have thrown UOE");
            } catch (UnsupportedOperationInTransactionException uoi) {
            // chill
            }
            try {
                custRegion.localInvalidate(custId);
                fail("Should have thrown UOE");
            } catch (UnsupportedOperationInTransactionException uoi) {
            // chill
            }
            // orderRegion.put(orderId, new Order("fooOrder"));
            // refRegion.put(custId, new Customer("foo", "bar"));
            getCache().getCacheTransactionManager().commit();
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) RollbackException(javax.transaction.RollbackException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 24 with CustId

use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.

the class ClientServerTransactionDUnitTest method doFailoverWork.

private void doFailoverWork(VM accessor1, VM accessor2, VM datastore, VM client, boolean serverOnDatastore, final boolean cachingProxy) {
    final int port1 = createRegionsAndStartServer(accessor1, true);
    final int port2 = accessor2 == null ? 0 : createRegionsAndStartServer(accessor2, true);
    final int port3 = serverOnDatastore ? createRegionsAndStartServer(datastore, false) : createRegionOnServer(datastore, false, false);
    /* final TXId txid = (TXId) */
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
            port1);
            if (port2 != 0)
                ccf.addPoolServer("localhost", port2);
            if (port3 != 0)
                ccf.addPoolServer("localhost", port3);
            ccf.setPoolSubscriptionEnabled(false);
            ccf.set(LOG_LEVEL, getDUnitLogLevel());
            ClientCache cCache = getClientCache(ccf);
            ClientRegionFactory<CustId, Customer> custrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
            ClientRegionFactory<Integer, String> refrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
            Region<Integer, String> r = refrf.create(D_REFERENCE);
            Region<CustId, Customer> pr = custrf.create(CUSTOMER);
            // Region<Integer, String> order = refrf.create(ORDER);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            for (int i = 0; i < 5; i++) {
                CustId custId = new CustId(i);
                Customer cust = new Customer("name" + i, "address" + i);
                getGemfireCache().getLogger().info("SWAP:putting:" + custId);
                pr.put(custId, cust);
                r.put(i, "value" + i);
            }
            return mgr.getTransactionId();
        }
    });
    accessor1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            for (CacheServer s : getCache().getCacheServers()) {
                getCache().getLogger().info("SWAP:Stopping " + s);
                s.stop();
            }
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            /* TXManagerImpl mgr = */
            getGemfireCache().getTxManager();
            Region<Integer, String> r = getGemfireCache().getRegion(D_REFERENCE);
            Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
            for (int i = 5; i < 10; i++) {
                CustId custId = new CustId(i);
                Customer cust = new Customer("name" + i, "address" + i);
                getGemfireCache().getLogger().info("SWAP:AfterFailover:putting:" + custId);
                pr.put(custId, cust);
                r.put(i, "value" + i);
            }
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertEquals(1, mgr.hostedTransactionsInProgressForTest());
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            Region<Integer, String> r = getGemfireCache().getRegion(D_REFERENCE);
            Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
            mgr.commit();
            for (int i = 0; i < 10; i++) {
                if (cachingProxy) {
                    assertTrue(pr.containsKey(new CustId(i)));
                    assertTrue(r.containsKey(i));
                }
                assertEquals(new Customer("name" + i, "address" + i), pr.get(new CustId(i)));
                assertEquals("value" + i, r.get(i));
            }
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) CacheServer(org.apache.geode.cache.server.CacheServer) RollbackException(javax.transaction.RollbackException)

Example 25 with CustId

use of org.apache.geode.internal.cache.execute.data.CustId in project geode by apache.

the class ClientServerTransactionDUnitTest method testSuspendResumeOnDifferentThreads.

@Test
public void testSuspendResumeOnDifferentThreads() {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client = host.getVM(2);
    final int port1 = createRegionsAndStartServer(server1, false);
    final int port2 = createRegionsAndStartServer(server2, false);
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
            port1);
            ccf.addPoolServer("localhost", port2);
            ccf.setPoolSubscriptionEnabled(false);
            ccf.setPoolLoadConditioningInterval(1);
            ccf.set(LOG_LEVEL, getDUnitLogLevel());
            ClientCache cCache = getClientCache(ccf);
            ClientRegionFactory<CustId, Customer> custrf = cCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
            ClientRegionFactory<Integer, String> refrf = cCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
            Region<Integer, String> r = refrf.create(D_REFERENCE);
            Region<CustId, Customer> pr = custrf.create(CUSTOMER);
            final TXManagerImpl mgr = getGemfireCache().getTxManager();
            CustId custId = new CustId(10);
            mgr.begin();
            pr.put(custId, new Customer("name10", "address10"));
            r.put(10, "value10");
            final TXStateProxy txState = mgr.internalSuspend();
            assertNull(pr.get(custId));
            assertNull(r.get(10));
            final CountDownLatch latch = new CountDownLatch(1);
            Thread t = new Thread(new Runnable() {

                public void run() {
                    mgr.internalResume(txState);
                    mgr.commit();
                    latch.countDown();
                }
            });
            t.start();
            latch.await();
            assertEquals(new Customer("name10", "address10"), pr.get(custId));
            assertEquals("value10", r.get(10));
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) CountDownLatch(java.util.concurrent.CountDownLatch) RollbackException(javax.transaction.RollbackException) CustId(org.apache.geode.internal.cache.execute.data.CustId) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

CustId (org.apache.geode.internal.cache.execute.data.CustId)167 Customer (org.apache.geode.internal.cache.execute.data.Customer)114 Region (org.apache.geode.cache.Region)87 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)81 Test (org.junit.Test)81 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)73 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)62 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)61 RollbackException (javax.transaction.RollbackException)58 Host (org.apache.geode.test.dunit.Host)55 VM (org.apache.geode.test.dunit.VM)55 CommitConflictException (org.apache.geode.cache.CommitConflictException)49 Order (org.apache.geode.internal.cache.execute.data.Order)48 IgnoredException (org.apache.geode.test.dunit.IgnoredException)44 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)37 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)37 CacheWriterException (org.apache.geode.cache.CacheWriterException)33 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)33 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)33 IOException (java.io.IOException)30