Search in sources :

Example 11 with OrderId

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

the class ClientServerTransactionDUnitTest method testPutallRollbackInServer.

@Test
public void testPutallRollbackInServer() throws Exception {
    Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    int port1 = createRegionsAndStartServer(server, false);
    createClientRegionAndPopulateData(client, port1, false);
    server.invoke(new SerializableCallable("verify tx") {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            mgr.begin();
            CustId custId = new CustId(1);
            OrderId orderId = new OrderId(1000, custId);
            Order expectedOrder = new Order("fooOrder");
            Map map = new HashMap();
            map.put(orderId, expectedOrder);
            orderRegion.putAll(map);
            mgr.rollback();
            assertNull(orderRegion.get(orderId));
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) HashMap(java.util.HashMap) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) RollbackException(javax.transaction.RollbackException) CustId(org.apache.geode.internal.cache.execute.data.CustId) Map(java.util.Map) HashMap(java.util.HashMap) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 12 with OrderId

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

the class ClientServerTransactionDUnitTest method testGetAllRollbackInServer.

@Ignore
@Test
public void testGetAllRollbackInServer() throws Exception {
    Host host = Host.getHost(0);
    VM server = host.getVM(0);
    createRegionsAndStartServer(server, false);
    server.invoke(new SerializableCallable("verify getAll tx") {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            orderRegion.getAttributesMutator().setCacheLoader(new CacheLoader() {

                public void close() {
                }

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    return new Order(helper.getKey() + "_loaded");
                }
            });
            mgr.begin();
            CustId custId = new CustId(1);
            OrderId orderId = new OrderId(1000, custId);
            Set<OrderId> keys = new HashSet();
            keys.add(orderId);
            Order order = (orderRegion.getAll(keys)).get(orderId);
            assertNotNull(order);
            mgr.rollback();
            assertNull(orderRegion.getEntry(orderId));
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) Set(java.util.Set) HashSet(java.util.HashSet) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) RollbackException(javax.transaction.RollbackException) CustId(org.apache.geode.internal.cache.execute.data.CustId) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 13 with OrderId

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

the class SingleHopStatsDUnitTest method createdColocatedPRData.

private void createdColocatedPRData(GemFireCacheImpl cache) {
    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
    Region shipmentRegion = cache.getRegion(SHIPMENT_REGION_NAME);
    for (int i = 0; i <= 20; i++) {
        CustId custid = new CustId(i);
        Customer customer = new Customer("name" + i, "Address" + i);
        customerRegion.put(custid, customer);
        for (int j = 1; j <= 10; j++) {
            int oid = (i * 10) + j;
            OrderId orderId = new OrderId(oid, custid);
            Order order = new Order(ORDER_REGION_NAME + oid);
            orderRegion.put(orderId, order);
            for (int k = 1; k <= 10; k++) {
                int sid = (oid * 10) + k;
                ShipmentId shipmentId = new ShipmentId(sid, orderId);
                Shipment shipment = new Shipment("Shipment" + sid);
                shipmentRegion.put(shipmentId, shipment);
            }
        }
    }
    ClientMetadataService cms = cache.getClientMetadataService();
    Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    assertEquals(3, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
    regionMetaData.get(customerRegion.getFullPath());
    metaDataRefreshCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount();
    // hops are not predictable
    assertTrue(metaDataRefreshCount_Customer != 0);
    regionMetaData.get(orderRegion.getFullPath());
    metaDataRefreshCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount();
    assertTrue(metaDataRefreshCount_Order == 0);
    regionMetaData.get(shipmentRegion.getFullPath());
    metaDataRefreshCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
    assertTrue(metaDataRefreshCount_Shipment == 0);
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CustId(org.apache.geode.internal.cache.execute.data.CustId) Region(org.apache.geode.cache.Region) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 14 with OrderId

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

the class MyTransactionFunction method verifyTransactionRollback.

private void verifyTransactionRollback(RegionFunctionContext ctx) {
    Region custPR = ctx.getDataSet();
    Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
    CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
    ArrayList args = (ArrayList) ctx.getArguments();
    CustId custId = (CustId) args.get(1);
    Customer newCus = (Customer) args.get(2);
    OrderId orderId = (OrderId) args.get(3);
    Order order = (Order) args.get(4);
    Customer oldCustomer = (Customer) custPR.get(custId);
    Order oldOrder = (Order) orderPR.get(orderId);
    mgr.begin();
    custPR.put(custId, newCus);
    Customer txCust = (Customer) custPR.get(custId);
    orderPR.put(orderId, order);
    Order txOrder = (Order) orderPR.get(orderId);
    Assert.assertTrue(newCus.equals(txCust), "Expected Customer to be:" + newCus + " but was:" + txCust);
    Assert.assertTrue(txOrder.equals(order), "Expected Order to be:" + order + " but was:" + txOrder);
    mgr.rollback();
    Customer commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected Customer to be:" + oldCustomer + " but was:" + commitedCust);
    Order commitedOrder = (Order) orderPR.get(orderId);
    Assert.assertTrue(oldOrder.equals(commitedOrder), "Expected Order to be:" + oldOrder + " but was:" + commitedOrder);
    mgr.begin();
    Assert.assertTrue(custPR.remove(custId, oldCustomer));
    orderPR.replace(orderId, order);
    mgr.rollback();
    Assert.assertTrue(oldCustomer.equals(custPR.get(custId)));
    Assert.assertTrue(oldOrder.equals(orderPR.get(orderId)));
    mgr.begin();
    Assert.assertTrue(custPR.replace(custId, oldCustomer, newCus));
    orderPR.remove(orderId, oldOrder);
    Assert.assertTrue(null == orderPR.putIfAbsent(orderId, order));
    mgr.rollback();
    Assert.assertTrue(oldCustomer.equals(custPR.get(custId)));
    Assert.assertTrue(oldOrder.equals(orderPR.get(orderId)));
}
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) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) 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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 15 with OrderId

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

the class MyTransactionFunction method verifyInvalidateOperation.

private void verifyInvalidateOperation(RegionFunctionContext ctx) {
    Region custPR = ctx.getDataSet();
    Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
    CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
    ArrayList args = (ArrayList) ctx.getArguments();
    CustId custId = (CustId) args.get(1);
    Customer newCus = (Customer) args.get(2);
    OrderId orderId = (OrderId) args.get(3);
    Order order = (Order) args.get(4);
    Customer oldCustomer = (Customer) custPR.get(custId);
    Customer commitedCust = null;
    // test destroy rollback
    mgr.begin();
    custPR.put(custId, newCus);
    custPR.invalidate(custId);
    orderPR.put(orderId, order);
    mgr.rollback();
    commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected customer to rollback to:" + oldCustomer + " but was:" + commitedCust);
    // test destroy rollback on unmodified entry
    mgr.begin();
    custPR.invalidate(custId);
    orderPR.put(orderId, order);
    mgr.rollback();
    commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(oldCustomer.equals(commitedCust), "Expected customer to rollback to:" + oldCustomer + " but was:" + commitedCust);
    // test remote destroy
    boolean caughtEx = false;
    try {
        mgr.begin();
        custPR.put(custId, new Customer("foo", "bar"));
        custPR.invalidate(custId);
        custPR.invalidate(new CustId(1));
        custPR.invalidate(new CustId(3));
        custPR.invalidate(new CustId(7));
        mgr.commit();
    } catch (Exception e) {
        mgr.rollback();
        if ((e instanceof TransactionDataNotColocatedException) || (e instanceof TransactionDataRebalancedException)) {
            caughtEx = true;
        } else if (e instanceof EntryNotFoundException && e.getMessage().matches("Entry not found for key.*1")) {
            caughtEx = true;
        } else {
            throw new TestException("Expected to catch PR remote destroy exception, but caught:" + e.getMessage(), e);
        }
    }
    if (!caughtEx) {
        throw new TestException("An Expected exception was not thrown");
    }
    // test destroy on unmodified entry
    mgr.begin();
    custPR.invalidate(custId);
    orderPR.put(orderId, order);
    mgr.commit();
    commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(commitedCust == null, "Expected Customer to be null but was:" + commitedCust);
    Order commitedOrder = (Order) orderPR.get(orderId);
    Assert.assertTrue(order.equals(commitedOrder), "Expected Order to be:" + order + " but was:" + commitedOrder);
// test destroy on new entry
// TODO: This throws EntryNotFound
/*
     * OrderId newOrderId = new OrderId(5000,custId); mgr.begin(); orderPR.put(newOrderId, new
     * Order("New Order to be destroyed")); orderPR.invalidate(newOrderId); mgr.commit();
     * Assert.assertTrue(orderPR.get(newOrderId)==null,"Did not expect orderId to be present");
     */
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) TestException(util.TestException) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) CommitConflictException(org.apache.geode.cache.CommitConflictException) PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) CustId(org.apache.geode.internal.cache.execute.data.CustId) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

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