Search in sources :

Example 71 with OrderId

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

the class SingleHopStatsDUnitTest method getPR.

private void getPR(String FromClient, boolean colocated) {
    Cache cache = CacheFactory.getAnyInstance();
    Region region = cache.getRegion(Region_Name);
    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
    Region shipmentRegion = cache.getRegion("SHIPMENT");
    if (!colocated) {
        for (int i = 0; i < 226; i++) {
            region.get(i);
        }
        ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
        Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
        assertEquals(1, regionMetaData.size());
        regionMetaData.get(region.getFullPath());
        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
    } else {
        for (int i = 0; i <= 20; i++) {
            CustId custid = new CustId(i);
            customerRegion.get(custid);
            for (int j = 1; j <= 10; j++) {
                int oid = (i * 10) + j;
                OrderId orderId = new OrderId(oid, custid);
                orderRegion.get(orderId);
                for (int k = 1; k <= 10; k++) {
                    int sid = (oid * 10) + k;
                    ShipmentId shipmentId = new ShipmentId(sid, orderId);
                    shipmentRegion.get(shipmentId);
                }
            }
        }
        ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
        Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
        assertEquals(3, regionMetaData.size());
        assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
        regionMetaData.get(customerRegion.getFullPath());
        assertEquals(metaDataRefreshCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount());
        regionMetaData.get(orderRegion.getFullPath());
        assertEquals(metaDataRefreshCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount());
        regionMetaData.get(shipmentRegion.getFullPath());
        assertEquals(metaDataRefreshCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) Region(org.apache.geode.cache.Region) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) Cache(org.apache.geode.cache.Cache)

Example 72 with OrderId

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

the class PRTransactionDUnitTest method testPRTXPerformance.

@Test
public void testPRTXPerformance() throws Exception {
    defaultStringSize = 1024;
    createPopulateAndVerifyCoLocatedPRs(1);
    // register functions
    SerializableCallable registerPerfFunctions = new SerializableCallable("register Fn") {

        public Object call() throws Exception {
            Function perfFunction = new PerfFunction();
            FunctionService.registerFunction(perfFunction);
            Function perfTxFunction = new PerfTxFunction();
            FunctionService.registerFunction(perfTxFunction);
            return Boolean.TRUE;
        }
    };
    dataStore1.invoke(registerPerfFunctions);
    dataStore2.invoke(registerPerfFunctions);
    dataStore3.invoke(registerPerfFunctions);
    accessor.invoke(registerPerfFunctions);
    SerializableCallable runPerfFunction = new SerializableCallable("runPerfFunction") {

        public Object call() throws Exception {
            long perfTime = 0;
            Region customerPR = basicGetCache().getRegion(CustomerPartitionedRegionName);
            Execution e = FunctionService.onRegion(customerPR);
            // for each customer, update order and shipment
            for (int iterations = 1; iterations <= totalIterations; iterations++) {
                LogWriterUtils.getLogWriter().info("running perfFunction");
                long startTime = 0;
                ArrayList args = new ArrayList();
                CustId custId = new CustId(iterations % 10);
                for (int i = 1; i <= perfOrderShipmentPairs; i++) {
                    OrderId orderId = new OrderId(custId.getCustId().intValue() * 10 + i, custId);
                    Order order = new Order("NewOrder" + i + iterations);
                    ShipmentId shipmentId = new ShipmentId(orderId.getOrderId().intValue() * 10 + i, orderId);
                    Shipment shipment = new Shipment("newShipment" + i + iterations);
                    args.add(orderId);
                    args.add(order);
                    args.add(shipmentId);
                    args.add(shipment);
                }
                Set filter = new HashSet();
                filter.add(custId);
                if (iterations > warmupIterations) {
                    startTime = NanoTimer.getTime();
                }
                e.withFilter(filter).setArguments(args).execute("perfFunction").getResult();
                if (startTime > 0) {
                    perfTime += NanoTimer.getTime() - startTime;
                }
            }
            return new Long(perfTime);
        }
    };
    Long perfTime = (Long) accessor.invoke(runPerfFunction);
    SerializableCallable runPerfTxFunction = new SerializableCallable("runPerfTxFunction") {

        public Object call() throws Exception {
            long perfTime = 0;
            Region customerPR = basicGetCache().getRegion(CustomerPartitionedRegionName);
            Execution e = FunctionService.onRegion(customerPR);
            // for each customer, update order and shipment
            for (int iterations = 1; iterations <= totalIterations; iterations++) {
                LogWriterUtils.getLogWriter().info("Running perfFunction");
                long startTime = 0;
                ArrayList args = new ArrayList();
                CustId custId = new CustId(iterations % 10);
                for (int i = 1; i <= perfOrderShipmentPairs; i++) {
                    OrderId orderId = new OrderId(custId.getCustId().intValue() * 10 + i, custId);
                    Order order = new Order("NewOrder" + i + iterations);
                    ShipmentId shipmentId = new ShipmentId(orderId.getOrderId().intValue() * 10 + i, orderId);
                    Shipment shipment = new Shipment("newShipment" + i + iterations);
                    args.add(orderId);
                    args.add(order);
                    args.add(shipmentId);
                    args.add(shipment);
                }
                Set filter = new HashSet();
                filter.add(custId);
                if (iterations > warmupIterations) {
                    startTime = NanoTimer.getTime();
                }
                e.withFilter(filter).setArguments(args).execute("perfTxFunction").getResult();
                if (startTime > 0) {
                    perfTime += NanoTimer.getTime() - startTime;
                }
            }
            return new Long(perfTime);
        }
    };
    Long perfTxTime = (Long) accessor.invoke(runPerfTxFunction);
    double diff = (perfTime.longValue() - perfTxTime.longValue()) * 1.0;
    double percentDiff = (diff / perfTime.longValue()) * 100;
    LogWriterUtils.getLogWriter().info((totalIterations - warmupIterations) + " iterations of function took:" + +perfTime.longValue() + " Nanos, and transaction function took:" + perfTxTime.longValue() + " Nanos, difference :" + diff + " percentDifference:" + percentDiff);
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HashSet(java.util.HashSet) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 73 with OrderId

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

the class PRTransactionDUnitTest method testCacheListenerCallbacks.

@Ignore("BUG46661")
@Test
public void testCacheListenerCallbacks() {
    createPopulateAndVerifyCoLocatedPRs(1);
    SerializableCallable registerListeners = new SerializableCallable() {

        public Object call() throws Exception {
            Region custRegion = basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            custRegion.getAttributesMutator().addCacheListener(new TransactionListener2());
            return null;
        }
    };
    accessor.invoke(registerListeners);
    dataStore1.invoke(registerListeners);
    dataStore2.invoke(registerListeners);
    dataStore3.invoke(registerListeners);
    accessor.invoke(new SerializableCallable("run function") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
            PartitionedRegion orderpr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
            CustId custId = new CustId(2);
            Customer newCus = new Customer("foo", "bar");
            Order order = new Order("fooOrder");
            OrderId orderId = new OrderId(22, custId);
            ArrayList args = new ArrayList();
            Function txFunction = new MyTransactionFunction();
            FunctionService.registerFunction(txFunction);
            Execution e = FunctionService.onRegion(pr);
            Set filter = new HashSet();
            boolean caughtException = false;
            // test transaction non-coLocated operations
            filter.clear();
            args.clear();
            args.add(new Integer(VERIFY_LISTENER_CALLBACK));
            LogWriterUtils.getLogWriter().info("VERIFY_LISTENER_CALLBACK");
            args.add(custId);
            args.add(newCus);
            args.add(orderId);
            args.add(order);
            filter.add(custId);
            caughtException = false;
            e.withFilter(filter).setArguments(args).execute(txFunction.getId()).getResult();
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) HashSet(java.util.HashSet) Set(java.util.Set) Customer(org.apache.geode.internal.cache.execute.data.Customer) ArrayList(java.util.ArrayList) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TestException(util.TestException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 74 with OrderId

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

the class DistributedTransactionDUnitTest method testPutAllWithTransactions.

@Test
public void testPutAllWithTransactions() throws Exception {
    Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    createRegions(new VM[] { server1, server2, server3 });
    execute(new VM[] { server1, server2, server3 }, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            af.setPartitionAttributes(new PartitionAttributesFactory<CustId, Customer>().setTotalNumBuckets(4).setLocalMaxMemory(1).setPartitionResolver(new CustomerIDPartitionResolver("resolver1")).setRedundantCopies(0).create());
            getCache().createRegion("NONCOLOCATED_PR", af.create());
            return null;
        }
    });
    execute(server1, new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region custRegion = getCache().getRegion(CUSTOMER_PR);
            Region orderRegion = getCache().getRegion(ORDER_PR);
            Map custMap = new HashMap();
            Map orderMap = new HashMap();
            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);
                custMap.put(custId, customer);
                orderMap.put(orderId, order);
            }
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.setDistributed(true);
            mgr.begin();
            custRegion.putAll(custMap);
            orderRegion.putAll(orderMap);
            mgr.commit();
            mgr.begin();
            assertEquals(5, custRegion.size());
            assertEquals(5, orderRegion.size());
            custMap = new HashMap();
            orderMap = new HashMap();
            for (int i = 5; i < 10; 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);
                custMap.put(custId, customer);
                orderMap.put(orderId, order);
            }
            custRegion.putAll(custMap);
            orderRegion.putAll(orderMap);
            mgr.rollback();
            mgr.begin();
            assertEquals(5, custRegion.size());
            assertEquals(5, orderRegion.size());
            custRegion.putAll(custMap);
            orderRegion.putAll(orderMap);
            assertEquals(10, custRegion.size());
            assertEquals(10, orderRegion.size());
            // Verify operations involving non colocated PR
            Map map = new HashMap();
            custMap.clear();
            for (int i = 10; i < 15; 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);
                custMap.put(custId, customer);
                map.put(custId, customer);
            }
            custRegion.putAll(custMap);
            Region nonColocatedRegion = getCache().getRegion("NONCOLOCATED_PR");
            nonColocatedRegion.putAll(orderMap);
            mgr.commit();
            mgr.begin();
            assertEquals(15, custRegion.size());
            assertEquals(5, nonColocatedRegion.size());
            custMap.clear();
            map.clear();
            for (int i = 15; i < 20; 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);
                custMap.put(custId, customer);
                map.put(custId, customer);
            }
            custRegion.putAll(custMap);
            nonColocatedRegion.putAll(orderMap);
            mgr.rollback();
            assertEquals(15, custRegion.size());
            assertEquals(5, nonColocatedRegion.size());
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) Customer(org.apache.geode.internal.cache.execute.data.Customer) HashMap(java.util.HashMap) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver) Host(org.apache.geode.test.dunit.Host) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CommitConflictException(org.apache.geode.cache.CommitConflictException) CommitIncompleteException(org.apache.geode.cache.CommitIncompleteException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) 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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 75 with OrderId

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

the class DistributedTransactionDUnitTest method populateData.

void populateData() {
    Region custRegion = getCache().getRegion(CUSTOMER_PR);
    Region orderRegion = getCache().getRegion(ORDER_PR);
    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) 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)

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