Search in sources :

Example 41 with PartitionedRegion

use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.

the class FixedPartitioningTestBase method putOrderPartitionedRegion_Persistence2.

public static void putOrderPartitionedRegion_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);
                Order order = new Order("OREDR" + oid);
                try {
                    partitionedregion.put(orderId, order);
                } catch (Exception e) {
                    org.apache.geode.test.dunit.Assert.fail("putOrderPartitionedRegion : failed while doing put operation in OrderPartitionedRegion ", e);
                }
                LogWriterUtils.getLogWriter().info("Order :- { " + orderId + " : " + order + " }");
            }
        }
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) 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) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 42 with PartitionedRegion

use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.

the class FixedPartitioningTestBase method putCustomerPartitionedRegion_Persistence.

public static void putCustomerPartitionedRegion_Persistence(String partitionedRegionName) {
    assertNotNull(cache);
    Region partitionedregion = cache.getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 1; i <= 20; i++) {
        CustId custid = new CustId(i);
        Customer customer = new Customer("name" + i, "Address" + i);
        try {
            partitionedregion.put(custid, customer);
        } catch (Exception e) {
            org.apache.geode.test.dunit.Assert.fail("putCustomerPartitionedRegion : failed while doing put operation in CustomerPartitionedRegion ", e);
        }
        LogWriterUtils.getLogWriter().info("Customer :- { " + custid + " : " + customer + " }");
    }
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 43 with PartitionedRegion

use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.

the class FixedPartitioningTestBase method putCustomerPartitionedRegion_Persistence1.

public static void putCustomerPartitionedRegion_Persistence1(String partitionedRegionName) {
    assertNotNull(cache);
    Region partitionedregion = cache.getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 1; i <= 20; i++) {
        if (i % 2 == 0) {
            CustId custid = new CustId(i);
            Customer customer = new Customer("name" + i, "Address" + i);
            try {
                partitionedregion.put(custid, customer);
            } catch (Exception e) {
                org.apache.geode.test.dunit.Assert.fail("putCustomerPartitionedRegion : failed while doing put operation in CustomerPartitionedRegion ", e);
            }
            LogWriterUtils.getLogWriter().info("Customer :- { " + custid + " : " + customer + " }");
        }
    }
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 44 with PartitionedRegion

use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.

the class FixedPartitioningTestBase method putOrderPartitionedRegion.

public static void putOrderPartitionedRegion(String partitionedRegionName) {
    assertNotNull(cache);
    Region partitionedregion = cache.getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 1; i <= 40; i++) {
        CustId custid = new CustId(i);
        for (int j = 1; j <= 10; j++) {
            int oid = (i * 10) + j;
            OrderId orderId = new OrderId(oid, custid);
            Order order = new Order("OREDR" + oid);
            try {
                partitionedregion.put(orderId, order);
            } catch (Exception e) {
                org.apache.geode.test.dunit.Assert.fail("putOrderPartitionedRegion : failed while doing put operation in OrderPartitionedRegion ", e);
            }
            LogWriterUtils.getLogWriter().info("Order :- { " + orderId + " : " + order + " }");
        }
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) 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) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 45 with PartitionedRegion

use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.

the class FixedPartitioningTestBase method validateAfterPutPartitionedRegion.

public static void validateAfterPutPartitionedRegion(String customerPartitionedRegionName, String orderPartitionedRegionName, String shipmentPartitionedRegionName) throws ClassNotFoundException {
    assertNotNull(cache);
    PartitionedRegion customerPartitionedregion = null;
    PartitionedRegion orderPartitionedregion = null;
    PartitionedRegion shipmentPartitionedregion = null;
    try {
        customerPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + customerPartitionedRegionName);
        orderPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + orderPartitionedRegionName);
        shipmentPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + shipmentPartitionedRegionName);
    } catch (Exception e) {
        org.apache.geode.test.dunit.Assert.fail("validateAfterPutPartitionedRegion : failed while getting the region", e);
    }
    assertNotNull(customerPartitionedregion);
    for (int i = 0; i < 10; i++) {
        InternalDistributedMember idmForCustomer = customerPartitionedregion.getBucketPrimary(i);
        InternalDistributedMember idmForOrder = orderPartitionedregion.getBucketPrimary(i);
        InternalDistributedMember idmForShipment = shipmentPartitionedregion.getBucketPrimary(i);
        // take all the keys from the shipment for each bucket
        Set customerKey = customerPartitionedregion.getBucketKeys(i);
        assertNotNull(customerKey);
        Iterator customerIterator = customerKey.iterator();
        while (customerIterator.hasNext()) {
            CustId custId = (CustId) customerIterator.next();
            assertNotNull(customerPartitionedregion.get(custId));
            Set orderKey = orderPartitionedregion.getBucketKeys(i);
            assertNotNull(orderKey);
            Iterator orderIterator = orderKey.iterator();
            while (orderIterator.hasNext()) {
                OrderId orderId = (OrderId) orderIterator.next();
                if (custId.equals(orderId.getCustId())) {
                    LogWriterUtils.getLogWriter().info(orderId + "belongs to node " + idmForCustomer + " " + idmForOrder);
                    assertEquals(idmForCustomer, idmForOrder);
                }
                Set shipmentKey = shipmentPartitionedregion.getBucketKeys(i);
                assertNotNull(shipmentKey);
                Iterator shipmentIterator = shipmentKey.iterator();
                while (shipmentIterator.hasNext()) {
                    ShipmentId shipmentId = (ShipmentId) shipmentIterator.next();
                    // assertNotNull(shipmentPartitionedregion.get(shipmentId));
                    if (orderId.equals(shipmentId.getOrderId())) {
                        LogWriterUtils.getLogWriter().info(shipmentId + "belongs to node " + idmForOrder + " " + idmForShipment);
                    }
                }
            }
        }
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)367 Test (org.junit.Test)135 Region (org.apache.geode.cache.Region)115 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)112 HashSet (java.util.HashSet)105 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)104 AttributesFactory (org.apache.geode.cache.AttributesFactory)86 VM (org.apache.geode.test.dunit.VM)86 Host (org.apache.geode.test.dunit.Host)85 ArrayList (java.util.ArrayList)77 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)75 Set (java.util.Set)69 IOException (java.io.IOException)66 Function (org.apache.geode.cache.execute.Function)66 FunctionException (org.apache.geode.cache.execute.FunctionException)63 List (java.util.List)62 RegionAttributes (org.apache.geode.cache.RegionAttributes)61 Iterator (java.util.Iterator)60 IgnoredException (org.apache.geode.test.dunit.IgnoredException)59 Cache (org.apache.geode.cache.Cache)56