Search in sources :

Example 76 with Customer

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

the class RemoteCQTransactionDUnitTest method verifyAfterRollback.

void verifyAfterRollback(OP op) {
    Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
    Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
    Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
    assertNotNull(custRegion);
    assertNotNull(orderRegion);
    assertNotNull(refRegion);
    CustId custId = new CustId(1);
    OrderId orderId = new OrderId(1, custId);
    OrderId orderId2 = new OrderId(2, custId);
    OrderId orderId3 = new OrderId(3, custId);
    Customer expectedCust;
    Order expectedOrder;
    Customer expectedRef;
    switch(op) {
        case PUT:
            expectedCust = new Customer("customer1", "address1");
            expectedOrder = new Order("order1");
            expectedRef = new Customer("customer1", "address1");
            assertEquals(expectedCust, custRegion.getEntry(custId).getValue());
            assertEquals(expectedOrder, orderRegion.getEntry(orderId).getValue());
            getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion);
            getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion.getEntry(orderId2));
            assertNull(getGemfireCache().getTXMgr().getTXState());
            assertNull("" + orderRegion.getEntry(orderId2), orderRegion.getEntry(orderId2));
            assertNull(orderRegion.getEntry(orderId3));
            assertNull(orderRegion.get(orderId2));
            assertNull(orderRegion.get(orderId3));
            assertEquals(expectedRef, refRegion.getEntry(custId).getValue());
            validateContains(custId, Collections.singleton(orderId), true);
            break;
        case GET:
            expectedCust = custRegion.getEntry(custId).getValue();
            expectedOrder = orderRegion.getEntry(orderId).getValue();
            expectedRef = refRegion.getEntry(custId).getValue();
            validateContains(custId, Collections.singleton(orderId), true);
            break;
        case DESTROY:
            assertTrue(!custRegion.containsKey(custId));
            assertTrue(!orderRegion.containsKey(orderId));
            assertTrue(!refRegion.containsKey(custId));
            validateContains(custId, Collections.singleton(orderId), true);
            break;
        case INVALIDATE:
            assertTrue(custRegion.containsKey(custId));
            assertTrue(orderRegion.containsKey(orderId));
            assertTrue(refRegion.containsKey(custId));
            assertNull(custRegion.get(custId));
            assertNull(orderRegion.get(orderId));
            assertNull(refRegion.get(custId));
            validateContains(custId, Collections.singleton(orderId), true, true);
            break;
        default:
            throw new IllegalStateException();
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 77 with Customer

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

the class RemoteCQTransactionDUnitTest method populateData.

void populateData() {
    Region custRegion = getCache().getRegion(CUSTOMER);
    Region orderRegion = getCache().getRegion(ORDER);
    Region refRegion = getCache().getRegion(D_REFERENCE);
    for (int i = 0; i < 5; i++) {
        CustId custId = new CustId(i);
        Customer customer = new Customer("customer" + i, "address" + i);
        OrderId orderId = new OrderId(i, custId);
        Order order = new Order("order" + i);
        custRegion.put(custId, customer);
        orderRegion.put(orderId, order);
        refRegion.put(custId, customer);
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) Region(org.apache.geode.cache.Region) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 78 with Customer

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

the class RemoteCQTransactionDUnitTest method testTXWithCQCommitInDatastoreConnectedToDatastoreCQ.

@Test
public void testTXWithCQCommitInDatastoreConnectedToDatastoreCQ() 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(datastore);
    createClientRegion(client, port, false, true, true);
    datastore.invoke(new SerializableCallable() {

        @Override
        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"));
            getCache().getCacheTransactionManager().commit();
            return null;
        }
    });
    Thread.sleep(10000);
    client.invoke(new SerializableCallable() {

        @Override
        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);
            ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
            assertTrue(cl.invoked);
            assertTrue(((ClientCQListener) custRegion.getCache().getQueryService().getCqs()[0].getCqAttributes().getCqListener()).invoked);
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) Host(org.apache.geode.test.dunit.Host) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheWriterException(org.apache.geode.cache.CacheWriterException) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 79 with Customer

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

the class DistTXPersistentDebugDUnitTest method testBasicDistributedTX.

@Test
public void testBasicDistributedTX() throws Exception {
    createCacheInAllVms();
    final String regionName = "persistentCustomerPRRegion";
    Object[] attrs = new Object[] { regionName };
    createPersistentPR(attrs);
    SerializableCallable TxOps = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheTransactionManager mgr = basicGetCache().getCacheTransactionManager();
            mgr.setDistributed(true);
            LogWriterUtils.getLogWriter().fine("SJ:TX BEGIN");
            mgr.begin();
            Region<CustId, Customer> prRegion = basicGetCache().getRegion(regionName);
            CustId custIdOne = new CustId(1);
            Customer customerOne = new Customer("name1", "addr1");
            LogWriterUtils.getLogWriter().fine("SJ:TX PUT 1");
            prRegion.put(custIdOne, customerOne);
            CustId custIdTwo = new CustId(2);
            Customer customerTwo = new Customer("name2", "addr2");
            LogWriterUtils.getLogWriter().fine("SJ:TX PUT 2");
            prRegion.put(custIdTwo, customerTwo);
            LogWriterUtils.getLogWriter().fine("SJ:TX COMMIT");
            mgr.commit();
            return null;
        }
    };
    dataStore2.invoke(TxOps);
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) 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 80 with Customer

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

the class PartitionResolverDUnitTest method populateData.

void populateData() {
    Region custRegion = getCache().getRegion(CUSTOMER);
    Region orderRegion = getCache().getRegion(ORDER);
    for (int i = 0; i < 5; i++) {
        CustId custId = new CustId(i);
        Customer customer = new Customer("customer" + i, "address" + i);
        OrderId orderId = new OrderId(i, custId);
        Order order = new Order("order" + i);
        custRegion.put(custId, customer);
        orderRegion.put(orderId, order);
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

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