Search in sources :

Example 11 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer 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)

Example 12 with Customer

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

the class ClientServerTransactionDUnitTest method doTxOps.

void doTxOps(Region<Integer, String> r, Region<CustId, Customer> pr) {
    for (int i = 0; i < 5; i++) {
        CustId custId = new CustId(i);
        Customer cust = new Customer("name" + i, "address" + i);
        getGemfireCache().getLogger().info("putting:" + custId);
        pr.put(custId, cust);
        r.put(i, "value" + i);
    }
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer)

Example 13 with Customer

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

the class ClientServerTransactionDUnitTest method testCleanupAfterClientAndProxyFailure.

@Test
public void testCleanupAfterClientAndProxyFailure() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    final boolean cachingProxy = false;
    // some other VMs seem to be hanging around and have the region this
    disconnectAllFromDS();
    // tests uses
    final int port1 = createRegionsAndStartServerWithTimeout(accessor, true, 5);
    createRegionOnServerWithTimeout(datastore, false, false, 5);
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true");
    ClientCacheFactory ccf = new ClientCacheFactory();
    setCCF(port1, ccf);
    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);
    TXManagerImpl mgr = getGemfireCache().getTxManager();
    mgr.begin();
    doTxOps(r, pr);
    final DistributedMember myId = cCache.getDistributedSystem().getDistributedMember();
    SerializableCallable verifyExists = new SerializableCallable("verify txstate for client exists") {

        public Object call() throws Exception {
            TXManagerImpl txmgr = getGemfireCache().getTxManager();
            Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId);
            // only one in-progress transaction
            assertEquals(1, states.size());
            return null;
        }
    };
    accessor.invoke(verifyExists);
    datastore.invoke(verifyExists);
    accessor.invoke(() -> closeCache());
    accessor.invoke(() -> disconnectFromDS());
    SerializableCallable verifyExpired = new SerializableCallable("verify txstate is expired") {

        public Object call() throws Exception {
            final TXManagerImpl txmgr = getGemfireCache().getTxManager();
            return verifyTXStateExpired(myId, txmgr);
        }
    };
    try {
        datastore.invoke(verifyExpired);
    } finally {
        cCache.close();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Customer(org.apache.geode.internal.cache.execute.data.Customer) CustId(org.apache.geode.internal.cache.execute.data.CustId) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 14 with Customer

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

the class ClientServerTransactionDUnitTest method testClientCommitAndDataStoreGetsEvent.

@Test
public void testClientCommitAndDataStoreGetsEvent() 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 ServerListener());
            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.put(custId, new Customer("foo", "bar"));
            // orderRegion.put(orderId, new Order("fooOrder"));
            // refRegion.put(custId, new Customer("foo", "bar"));
            getCache().getCacheTransactionManager().commit();
            return null;
        }
    });
    datastore.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);
            ServerListener l = (ServerListener) custRegion.getAttributes().getCacheListeners()[0];
            getCache().getLogger().info("SWAP:CLIENTinvoked:" + l.invoked);
            assertTrue(l.invoked);
            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 15 with Customer

use of org.apache.geode.internal.cache.execute.data.Customer 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)

Aggregations

Customer (org.apache.geode.internal.cache.execute.data.Customer)115 CustId (org.apache.geode.internal.cache.execute.data.CustId)114 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 Test (org.junit.Test)73 Region (org.apache.geode.cache.Region)71 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)58 Host (org.apache.geode.test.dunit.Host)54 VM (org.apache.geode.test.dunit.VM)54 RollbackException (javax.transaction.RollbackException)53 CommitConflictException (org.apache.geode.cache.CommitConflictException)48 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)39 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)37 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)35 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)34 CacheWriterException (org.apache.geode.cache.CacheWriterException)33 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)33 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)33 IgnoredException (org.apache.geode.test.dunit.IgnoredException)32 Order (org.apache.geode.internal.cache.execute.data.Order)30 NamingException (javax.naming.NamingException)28