Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var cacheFactory = new CacheFactory()
                               .Set("log-level", "none");
            var cache = cacheFactory.Create();

            var poolFactory = cache.GetPoolFactory()
                              .AddLocator("localhost", 10334);

            poolFactory.Create("pool");

            var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY)
                                .SetPoolName("pool");
            var region = regionFactory.Create <object, object>("partition_region");

            Console.WriteLine("Storing id and username in the region");

            string rtimmonsKey   = "rtimmons";
            string rtimmonsValue = "Robert Timmons";
            string scharlesKey   = "scharles";
            string scharlesValue = "Sylvia Charles";

            region.Put(rtimmonsKey, rtimmonsValue, null);
            region.Put(scharlesKey, scharlesValue, null);

            Console.WriteLine("Getting the user info from the region");
            var user1 = region.Get(rtimmonsKey, null);
            var user2 = region.Get(scharlesKey, null);

            Console.WriteLine(rtimmonsKey + " = " + user1);
            Console.WriteLine(scharlesKey + " = " + user2);

            ArrayList keyArgs = new ArrayList();

            keyArgs.Add(rtimmonsKey);
            keyArgs.Add(scharlesKey);

            var exc = Client.FunctionService <object> .OnRegion <object, object>(region);

            Client.IResultCollector <object> rc = exc.WithArgs <object>(keyArgs).Execute("ExampleMultiGetFunction");

            ICollection <object> res = rc.GetResult();

            Console.WriteLine("Function Execution Results:");
            Console.WriteLine("   Count = {0}", res.Count);

            foreach (List <object> item in res)
            {
                foreach (object item2 in item)
                {
                    Console.WriteLine("   value = {0}", item2.ToString());
                }
            }

            cache.Close();
        }
Ejemplo n.º 2
0
        public void DoPRSHTradeResolverTasks(string rname)
        {
            Util.Log("DoPRSHTradeResolverTasks rname = {0} ", rname);
            IRegion <TradeKey, Object> region = CacheHelper.GetRegion <TradeKey, Object>(rname);
            int nonSingleHopCount = 0, metadatarefreshCount = 0;
            int nonSingleHopCount1 = 0, metadatarefreshCount1 = 0;

            Assert.IsNotNull(region, "DoPRSHTradeResolverTasks: null region.");
            for (int i = 0; i < 1000; i++)
            {
                try
                {
                    region[new TradeKey(i)] = "Value" + i;
                    Util.Log("Put inside DoPRSHTradeResolverTasks successfull ");
                }
                catch (CacheServerException ex)
                {
                    Util.Log("CPPTEST: Put caused networkhop");
                    Assert.Fail("Got CacheServerException (0}", ex.Message);
                }
                catch (CacheWriterException ex)
                {
                    Util.Log("CPPTEST: Put caused networkhop");
                    Assert.Fail("Got CacheWriterException (0}", ex.Message);
                }
                catch (Exception ex)
                {
                    Util.Log("CPPTEST: Put caused networkhop");
                    Assert.Fail("Got Exception (0}", ex.Message);
                }
            }
            StatisticsFactory factory = StatisticsFactory.GetExistingInstance();
            StatisticsType    type    = factory.FindType("RegionStatistics");

            if (type != null)
            {
                Statistics rStats = factory.FindFirstStatisticsByType(type);
                if (rStats != null)
                {
                    nonSingleHopCount    = rStats.GetInt((string)"nonSingleHopCount");
                    metadatarefreshCount = rStats.GetInt((string)"metaDataRefreshCount");
                }
            }
            Util.Log("nonSingleHopCount = {0} & metadatarefreshCount = {1} ", nonSingleHopCount, metadatarefreshCount);
            Assert.GreaterOrEqual(nonSingleHopCount, 1, "nonSingleHopCount should be GreaterOrEqual to 1");
            Assert.GreaterOrEqual(metadatarefreshCount, 1, "metadatarefreshCount should be equal to 1");

            Util.Log("DoPRSHTradeResolverTasks WarmUp Task completed.");

            for (int i = 1000; i < 2000; i++)
            {
                try
                {
                    region[new TradeKey(i)] = "Value" + i;
                    Util.Log("Put inside DoPRSHTradeResolverTasks successfull");
                }
                catch (CacheServerException ex)
                {
                    Util.Log("CPPTEST: Put caused networkhop");
                    Assert.Fail("Got CacheServerException (0}", ex.Message);
                }
                catch (CacheWriterException ex)
                {
                    Util.Log("CPPTEST: Put caused networkhop");
                    Assert.Fail("Got CacheWriterException (0}", ex.Message);
                }
                catch (Exception ex)
                {
                    Util.Log("CPPTEST: Put caused networkhop");
                    Assert.Fail("Got Exception (0}", ex.Message);
                }

                try
                {
                    Object val = region[new TradeKey(i)];
                    Util.Log("Get inside DoPRSHTradeResolverTasks successfull ");
                }
                catch (CacheServerException ex)
                {
                    Util.Log("CPPTEST: Get caused networkhop");
                    Assert.Fail("Got CacheServerException (0}", ex.Message);
                }
                catch (CacheWriterException ex)
                {
                    Util.Log("CPPTEST: Get caused networkhop");
                    Assert.Fail("Got CacheWriterException (0}", ex.Message);
                }
                catch (Exception ex)
                {
                    Util.Log("CPPTEST: Get caused networkhop");
                    Assert.Fail("Got Exception (0}", ex.Message);
                }

                try
                {
                    region.Remove(new TradeKey(i)); //Destroy() replaced by Remove
                    Util.Log("Destroy inside DoPRSHTradeResolverTasks successfull ");
                }
                catch (CacheServerException ex)
                {
                    Util.Log("CPPTEST: Destroy caused networkhop");
                    Assert.Fail("Got CacheServerException (0}", ex.Message);
                }
                catch (CacheWriterException ex)
                {
                    Util.Log("CPPTEST: Destroy caused networkhop");
                    Assert.Fail("Got CacheWriterException (0}", ex.Message);
                }
                catch (Exception ex)
                {
                    Util.Log("CPPTEST: Destroy caused networkhop");
                    Assert.Fail("Got Exception (0}", ex.Message);
                }
            }
            if (type != null)
            {
                Statistics rStats = factory.FindFirstStatisticsByType(type);
                if (rStats != null)
                {
                    nonSingleHopCount1    = rStats.GetInt((string)"nonSingleHopCount");
                    metadatarefreshCount1 = rStats.GetInt((string)"metaDataRefreshCount");
                    Util.Log("nonSingleHopCount1 = {0} & metadatarefreshCount1 = {1} ", nonSingleHopCount1, metadatarefreshCount1);
                    //Assert.AreEqual(nonSingleHopCount1, nonSingleHopCount, "nonSingleHopCount1 should be equal to nonSingleHopCount");
                    Assert.AreEqual(metadatarefreshCount1, metadatarefreshCount, "metadatarefreshCount1 should be equal to metadatarefreshCount");
                }
            }

            Util.Log("Executing onRegion FE with custom key and custom partitionResolver");
            Apache.Geode.Client.Execution <object> exc = Client.FunctionService <object> .OnRegion <TradeKey, object>(region);

            Assert.IsTrue(exc != null, "onRegion Returned NULL");

            TradeKey[] filter = new TradeKey[901];
            int        j      = 0;

            for (int i = 100; i < 1001; i++)
            {
                filter[j] = new TradeKey(i);
                j++;
            }
            Util.Log("filter count= {0}.", filter.Length);

            Client.IResultCollector <object> rc = exc.WithFilter <TradeKey>(filter).Execute(FEOnRegionPrSHOP_OptimizeForWrite, 15);
            Util.Log("FEOnRegionPrSHOP_OptimizeForWrite executed");
            ICollection <object> executeFunctionResult = rc.GetResult();

            Util.Log("OnRegionPrSHOP for filter executeFunctionResult.Count = {0} ", executeFunctionResult.Count);
            Assert.AreEqual(3, executeFunctionResult.Count, "executeFunctionResult count check failed");
            foreach (Boolean item in executeFunctionResult)
            {
                Util.Log("on region:FEOnRegionPrSHOP:= {0}.", item);
                Assert.AreEqual(true, item, "FEOnRegionPrSHOP item not true");
            }
            Util.Log("FEOnRegionPrSHOP_OptimizeForWrite done");

            rc = exc.WithFilter <TradeKey>(filter).Execute(FEOnRegionPrSHOP, 15);
            Util.Log("FEOnRegionPrSHOP executed");
            executeFunctionResult = rc.GetResult();
            Util.Log("OnRegionPrSHOP for filter executeFunctionResult.Count = {0} ", executeFunctionResult.Count);
            Assert.AreEqual(3, executeFunctionResult.Count, "executeFunctionResult count check failed");
            foreach (Boolean item in executeFunctionResult)
            {
                Util.Log("on region:FEOnRegionPrSHOP:= {0}.", item);
                Assert.AreEqual(true, item, "FEOnRegionPrSHOP item not true");
            }
            Util.Log("FEOnRegionPrSHOP done");

            object args = true;

            rc = exc.WithFilter <TradeKey>(filter).Execute(getFuncName);
            executeFunctionResult = rc.GetResult();

            Util.Log("ExecuteFunctionOnRegion for filter executeFunctionResult.Count = {0} ", executeFunctionResult.Count);

            List <object> resultList = new List <object>();

            foreach (List <object> item in executeFunctionResult)
            {
                foreach (object item2 in item)
                {
                    resultList.Add(item2);
                }
            }

            Util.Log("on region: result count= {0}.", resultList.Count);
            Assert.AreEqual(1802, resultList.Count, "result count check failed");
            for (int i = 0; i < resultList.Count; i++)
            {
                Util.Log("on region:get:= {0}.", resultList[i]);
            }
        }