Search in sources :

Example 41 with OrderId

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

the class FixedPartitioningTestBase method putShipmentPartitionedRegion_Persistence2.

public static void putShipmentPartitionedRegion_Persistence2(String partitionedRegionName) {
    assertNotNull(cache);
    Region partitionedregion = cache.getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 1; i <= 20; i++) {
        if (i % 2 == 1) {
            CustId custid = new CustId(i);
            for (int j = 1; j <= 10; j++) {
                int oid = (i * 10) + j;
                OrderId orderId = new OrderId(oid, custid);
                for (int k = 1; k <= 10; k++) {
                    int sid = (oid * 10) + k;
                    ShipmentId shipmentId = new ShipmentId(sid, orderId);
                    Shipment shipment = new Shipment("Shipment" + sid);
                    try {
                        partitionedregion.put(shipmentId, shipment);
                    } catch (Exception e) {
                        org.apache.geode.test.dunit.Assert.fail("putShipmentPartitionedRegion : failed while doing put operation in ShipmentPartitionedRegion ", e);
                    }
                    LogWriterUtils.getLogWriter().info("Shipment :- { " + shipmentId + " : " + shipment + " }");
                }
            }
        }
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 42 with OrderId

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

the class PartitionedRegionSingleHopWithServerGroupDUnitTest method putIntoPartitionedRegions.

public static void putIntoPartitionedRegions() {
    for (int i = 0; i <= 800; i++) {
        CustId custid = new CustId(i);
        Customer customer = new Customer("name" + i, "Address" + i);
        customerRegion.put(custid, customer);
    }
    for (int j = 0; j <= 800; j++) {
        CustId custid = new CustId(j);
        OrderId orderId = new OrderId(j, custid);
        Order order = new Order("OREDR" + j);
        orderRegion.put(orderId, order);
    }
    for (int k = 0; k <= 800; k++) {
        CustId custid = new CustId(k);
        OrderId orderId = new OrderId(k, custid);
        ShipmentId shipmentId = new ShipmentId(k, orderId);
        Shipment shipment = new Shipment("Shipment" + k);
        shipmentRegion.put(shipmentId, shipment);
    }
    region.put(new Integer(0), "create0");
    region.put(new Integer(1), "create1");
    region.put(new Integer(2), "create2");
    region.put(new Integer(3), "create3");
    region.put(new Integer(4), "create0");
    region.put(new Integer(5), "create1");
    region.put(new Integer(6), "create2");
    region.put(new Integer(7), "create3");
    region.put(new Integer(0), "update0");
    region.put(new Integer(1), "update1");
    region.put(new Integer(2), "update2");
    region.put(new Integer(3), "update3");
    region.put(new Integer(4), "update0");
    region.put(new Integer(5), "update1");
    region.put(new Integer(6), "update2");
    region.put(new Integer(7), "update3");
    region.put(new Integer(0), "update00");
    region.put(new Integer(1), "update11");
    region.put(new Integer(2), "update22");
    region.put(new Integer(3), "update33");
    region.put(new Integer(4), "update00");
    region.put(new Integer(5), "update11");
    region.put(new Integer(6), "update22");
    region.put(new Integer(7), "update33");
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 43 with OrderId

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

the class Shipment method putIntoPartitionedRegions.

public static void putIntoPartitionedRegions() {
    for (int i = 0; i <= 3; 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("OREDR" + 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);
            }
        }
    }
    region.put(new Integer(0), "create0");
    region.put(new Integer(1), "create1");
    region.put(new Integer(2), "create2");
    region.put(new Integer(3), "create3");
    region.put(new Integer(0), "update0");
    region.put(new Integer(1), "update1");
    region.put(new Integer(2), "update2");
    region.put(new Integer(3), "update3");
    region.put(new Integer(0), "update00");
    region.put(new Integer(1), "update11");
    region.put(new Integer(2), "update22");
    region.put(new Integer(3), "update33");
    Map map = new HashMap();
    map.put(1, 1);
    replicatedRegion.putAll(map);
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 44 with OrderId

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

the class MyTransactionFunction method verifyTxStateAndConflicts.

private void verifyTxStateAndConflicts(RegionFunctionContext ctx) {
    Region custPR = ctx.getDataSet();
    Region orderPR = custPR.getCache().getRegion(PRTransactionDUnitTest.OrderPartitionedRegionName);
    ArrayList args = (ArrayList) ctx.getArguments();
    CustId custId = (CustId) args.get(1);
    CacheTransactionManager mgr = custPR.getCache().getCacheTransactionManager();
    OrderId vOrderId = new OrderId(3000, custId);
    Order vOrder = new Order("vOrder");
    TXManagerImpl mImp = (TXManagerImpl) mgr;
    mImp.begin();
    orderPR.put(vOrderId, vOrder);
    TXStateProxy txState = mImp.internalSuspend();
    Iterator it = txState.getRegions().iterator();
    Assert.assertTrue(txState.getRegions().size() == 1, "Expected 1 region; " + "found:" + txState.getRegions().size());
    LocalRegion lr = (LocalRegion) it.next();
    Assert.assertTrue(lr instanceof BucketRegion);
    TXRegionState txRegion = txState.readRegion(lr);
    TXEntryState txEntry = txRegion.readEntry(txRegion.getEntryKeys().iterator().next());
    mImp.internalResume(txState);
    orderPR.put(vOrderId, new Order("foo"));
    txState = mImp.internalSuspend();
    // since both puts were on same key, verify that
    // TxRegionState and TXEntryState are same
    LocalRegion lr1 = (LocalRegion) txState.getRegions().iterator().next();
    Assert.assertTrue(lr == lr1);
    TXRegionState txRegion1 = txState.readRegion(lr);
    TXEntryState txEntry1 = txRegion1.readEntry(txRegion.getEntryKeys().iterator().next());
    Assert.assertTrue(txEntry == txEntry1);
    // to check for conflicts, start a new transaction, operate on same key,
    // commit the second and expect the first to fail
    mImp.begin();
    orderPR.put(vOrderId, new Order("foobar"));
    mImp.commit();
    // now begin the first
    mImp.internalResume(txState);
    boolean caughtException = false;
    try {
        mImp.commit();
    } catch (CommitConflictException e) {
        caughtException = true;
    }
    if (!caughtException) {
        throw new TestException("An expected exception was not thrown");
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) TestException(util.TestException) TXRegionState(org.apache.geode.internal.cache.TXRegionState) ArrayList(java.util.ArrayList) TXEntryState(org.apache.geode.internal.cache.TXEntryState) LocalRegion(org.apache.geode.internal.cache.LocalRegion) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) CommitConflictException(org.apache.geode.cache.CommitConflictException) BucketRegion(org.apache.geode.internal.cache.BucketRegion) CustId(org.apache.geode.internal.cache.execute.data.CustId) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) Iterator(java.util.Iterator) 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)

Example 45 with OrderId

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

the class MyTransactionFunction method verifyTransactionExecution.

private void verifyTransactionExecution(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);
    mgr.begin();
    custPR.put(custId, newCus);
    Assert.assertTrue(custPR.containsKey(custId));
    Assert.assertTrue(custPR.containsValueForKey(custId));
    orderPR.put(orderId, order);
    Assert.assertTrue(orderPR.containsKey(orderId));
    Assert.assertTrue(orderPR.containsValueForKey(orderId));
    mgr.commit();
    Customer commitedCust = (Customer) custPR.get(custId);
    Assert.assertTrue(newCus.equals(commitedCust), "Expected Customer to be:" + newCus + " but was:" + commitedCust);
    Order commitedOrder = (Order) orderPR.get(orderId);
    Assert.assertTrue(order.equals(commitedOrder), "Expected Order to be:" + order + " but was:" + commitedOrder);
    // put a never before put key
    OrderId newOrderId = new OrderId(4000, custId);
    Order newOrder = new Order("NewOrder");
    mgr.begin();
    custPR.put(custId, newCus);
    orderPR.put(newOrderId, newOrder);
    mgr.commit();
    commitedOrder = (Order) orderPR.get(newOrderId);
    Assert.assertTrue(newOrder.equals(commitedOrder), "Expected Order to be:" + order + " but was:" + commitedOrder);
}
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)

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