Search in sources :

Example 61 with OrderId

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

the class RemoteTransactionDUnitTest method verifyAfterCommit.

void verifyAfterCommit(OP op) {
    Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
    Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
    Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
    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;
    Order expectedOrder2;
    Order expectedOrder3;
    Customer expectedRef;
    switch(op) {
        case PUT:
            expectedCust = new Customer("foo", "bar");
            expectedOrder = new Order("fooOrder");
            expectedOrder2 = new Order("fooOrder2");
            expectedOrder3 = new Order("fooOrder3");
            expectedRef = expectedCust;
            assertNotNull(custRegion.getEntry(custId));
            assertEquals(expectedCust, custRegion.getEntry(custId).getValue());
            /*
         * assertNotNull(orderRegion.getEntry(orderId)); assertIndexDetailsEquals(expectedOrder,
         * orderRegion.getEntry(orderId).getValue());
         * 
         * assertNotNull(orderRegion.getEntry(orderId2)); assertIndexDetailsEquals(expectedOrder2,
         * orderRegion.getEntry(orderId2).getValue());
         * 
         * assertNotNull(orderRegion.getEntry(orderId3)); assertIndexDetailsEquals(expectedOrder3,
         * orderRegion.getEntry(orderId3).getValue());
         */
            assertNotNull(refRegion.getEntry(custId));
            assertEquals(expectedRef, refRegion.getEntry(custId).getValue());
            // validateContains(custId, ordersSet, true);
            break;
        case GET:
            expectedCust = custRegion.get(custId);
            expectedOrder = orderRegion.get(orderId);
            expectedRef = refRegion.get(custId);
            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), false);
            break;
        case INVALIDATE:
            boolean validateContainsKey = true;
            if (!((GemFireCacheImpl) custRegion.getCache()).isClient()) {
                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), validateContainsKey, false);
            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 62 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId 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 63 with OrderId

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

the class RemoteCQTransactionDUnitTest method createRegion.

void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    getCache().createRegion(D_REFERENCE, af.create());
    af = new AttributesFactory();
    af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
    if (interestPolicy != null) {
        af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy));
    }
    af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(redundantCopies).create());
    getCache().createRegion(CUSTOMER, af.create());
    af.setPartitionAttributes(new PartitionAttributesFactory<OrderId, Order>().setTotalNumBuckets(4).setLocalMaxMemory(accessor ? 0 : 1).setPartitionResolver(new CustomerIDPartitionResolver("resolver2")).setRedundantCopies(redundantCopies).setColocatedWith(CUSTOMER).create());
    getCache().createRegion(ORDER, af.create());
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 64 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId 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 65 with OrderId

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

Aggregations

OrderId (org.apache.geode.internal.cache.execute.data.OrderId)80 CustId (org.apache.geode.internal.cache.execute.data.CustId)73 Order (org.apache.geode.internal.cache.execute.data.Order)53 Region (org.apache.geode.cache.Region)44 Customer (org.apache.geode.internal.cache.execute.data.Customer)35 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)31 ShipmentId (org.apache.geode.internal.cache.execute.data.ShipmentId)25 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 Test (org.junit.Test)20 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)19 IOException (java.io.IOException)17 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)16 Host (org.apache.geode.test.dunit.Host)15 IgnoredException (org.apache.geode.test.dunit.IgnoredException)15 VM (org.apache.geode.test.dunit.VM)15 ArrayList (java.util.ArrayList)13 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)12 CacheWriterException (org.apache.geode.cache.CacheWriterException)12 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)12 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)12