Ejemplo n.º 1
0
        void RunDurableClient(int expectedPendingQSize)
        {
            Properties <string, string> pp = Properties <string, string> .Create <string, string>();

            pp.Insert("durable-client-id", "DurableClientId");
            pp.Insert("durable-timeout", "30");

            CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(pp);
            Cache        cache        = cacheFactory.SetSubscriptionEnabled(true)
                                        .SetSubscriptionAckInterval(5000)
                                        .SetSubscriptionMessageTrackingTimeout(5000)
                                        .Create();

            Util.Log("Created the Geode Cache Programmatically");

            RegionFactory            regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
            IRegion <object, object> region        = regionFactory.Create <object, object>("DistRegionAck");

            Util.Log("Created the DistRegionAck Region Programmatically");

            QueryService <object, object>        qService = cache.GetQueryService <object, object>();
            CqAttributesFactory <object, object> cqFac    = new CqAttributesFactory <object, object>();

            ICqListener <object, object> cqLstner = new MyCqListener1 <object, object>();

            cqFac.AddCqListener(cqLstner);
            CqAttributes <object, object> cqAttr = cqFac.Create();

            Util.Log("Attached CqListener");
            String query = "select * from /DistRegionAck";
            CqQuery <object, object> qry = qService.NewCq("MyCq", query, cqAttr, true);

            Util.Log("Created new CqQuery");

            qry.Execute();
            Util.Log("Executed new CqQuery");
            Thread.Sleep(10000);

            PendingEventCount(region, expectedPendingQSize, false);

            //Send ready for Event message to Server( only for Durable Clients ).
            //Server will send queued events to client after recieving this.
            cache.ReadyForEvents();

            Util.Log("Sent ReadyForEvents message to server");
            Thread.Sleep(10000);
            // Close the Geode Cache with keepalive = true.  Server will queue events for
            // durable registered keys and will deliver all events when client will reconnect
            // within timeout period and send "readyForEvents()"

            PendingEventCount(region, 0, true);

            cache.Close(true);

            Util.Log("Closed the Geode Cache with keepalive as true");
        }
        public void CheckCQStatusOnPutEvent(string poolName, string cqName, int onCreateCount)
        {
            var qs = CacheHelper.DCache.GetPoolManager().Find(poolName).GetQueryService();
            CqQuery <object, object>      query  = qs.GetCq <object, object>(cqName);
            CqAttributes <object, object> cqAttr = query.GetCqAttributes();

            ICqListener <object, object>[]      vl             = cqAttr.getCqListeners();
            MyCqStatusListener <object, object> myCqStatusLstr = (MyCqStatusListener <object, object>)vl[0];

            Util.Log("CheckCQStatusOnPutEvent = {0} ", myCqStatusLstr.getEventCountBefore());
            Assert.AreEqual(onCreateCount, myCqStatusLstr.getEventCountBefore());
        }
        public void CreateAndExecuteCQ_Listener(string poolName, string cqName, string cqQuery, int id)
        {
            var qs = CacheHelper.DCache.GetPoolManager().Find(poolName).GetQueryService();
            CqAttributesFactory <object, object> cqFac = new CqAttributesFactory <object, object>();

            cqFac.AddCqListener(new MyCqListener <object, object>(/*id*/));
            CqAttributes <object, object> cqAttr = cqFac.Create();
            CqQuery <object, object>      qry    = qs.NewCq(cqName, cqQuery, cqAttr, false);

            qry.Execute();
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
        }
Ejemplo n.º 4
0
        public void RegisterCqsClient1MultipleChunks()
        {
            Util.Log("Registering Cqs for client1 for multiple chunks.");
            CqAttributesFactory <object, object> cqAf       = new CqAttributesFactory <object, object>();
            CqAttributes <object, object>        attributes = cqAf.Create();
            QueryService <object, object>        qs         = Client.PoolManager.Find("__TESTPOOL1_").GetQueryService <object, object>();

            for (int i = 0; i < m_NumberOfCqs; i++)
            {
                qs.NewCq("MyCq_" + i.ToString(), "Select * From /" + QueryRegionNames[0] + " where id = 1", attributes, true).ExecuteWithInitialResults();
            }
        }
Ejemplo n.º 5
0
 void registerCq()
 {
   Pool thePool = CacheHelper.DCache.GetPoolManager().Find("__TEST_POOL1__");
   QueryService cqService = null;
   cqService = thePool.GetQueryService();
   CqAttributesFactory<object, DeltaTestImpl> attrFac = new CqAttributesFactory<object, DeltaTestImpl>();
   myCqListener = new CqDeltaListener<object, DeltaTestImpl>();
   attrFac.AddCqListener(myCqListener);
   CqAttributes<object, DeltaTestImpl> cqAttr = attrFac.Create();
   CqQuery<object, DeltaTestImpl> theQuery = cqService.NewCq("select * from /DistRegionAck d where d.intVar > 4", cqAttr, false);
   theQuery.Execute();
 }
Ejemplo n.º 6
0
        public void CheckCQStatusOnDisConnect(string poolName, string cqName, int onCqStatusDisConnect)
        {
            QueryService <object, object> qs = null;

            qs = PoolManager.Find(poolName).GetQueryService <object, object>();
            CqQuery <object, object>      query  = qs.GetCq(cqName);
            CqAttributes <object, object> cqAttr = query.GetCqAttributes();

            ICqListener <object, object>[]      vl             = cqAttr.getCqListeners();
            MyCqStatusListener <object, object> myCqStatusLstr = (MyCqStatusListener <object, object>)vl[0];

            Util.Log("CheckCQStatusOnDisConnect = {0} ", myCqStatusLstr.getCqDisConnectedCount());
            Assert.AreEqual(onCqStatusDisConnect, myCqStatusLstr.getCqDisConnectedCount());
        }
Ejemplo n.º 7
0
        public void CreateAndExecuteCQ_StatusListener(string poolName, string cqName, string cqQuery, int id)
        {
            QueryService <object, object> qs = null;

            qs = PoolManager.Find(poolName).GetQueryService <object, object>();
            CqAttributesFactory <object, object> cqFac = new CqAttributesFactory <object, object>();

            cqFac.AddCqListener(new MyCqStatusListener <object, object>(id));
            CqAttributes <object, object> cqAttr = cqFac.Create();
            CqQuery <object, object>      qry    = qs.NewCq(cqName, cqQuery, cqAttr, false);

            qry.Execute();
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
        }
Ejemplo n.º 8
0
        public void RegisterCqsClient2(bool isRecycle)
        {
            Util.Log("Registering Cqs for client2.");
            CqAttributesFactory <object, object> cqAf       = new CqAttributesFactory <object, object>();
            CqAttributes <object, object>        attributes = cqAf.Create();
            QueryService <object, object>        qs         = Client.PoolManager.Find("__TESTPOOL1_").GetQueryService <object, object>();

            if (!isRecycle)
            {
                qs.NewCq(m_client2DurableCqNames[0], "Select * From /" + QueryRegionNames[0] + " where id = 1", attributes, true).ExecuteWithInitialResults();
                qs.NewCq(m_client2DurableCqNames[1], "Select * From /" + QueryRegionNames[0] + " where id = 10", attributes, true).ExecuteWithInitialResults();
                qs.NewCq(m_client2DurableCqNames[2], "Select * From /" + QueryRegionNames[0], attributes, true).ExecuteWithInitialResults();
                qs.NewCq(m_client2DurableCqNames[3], "Select * From /" + QueryRegionNames[0] + " where id = 3", attributes, true).ExecuteWithInitialResults();
            }
            else
            {
                qs.NewCq(m_client2DurableCqNames[4], "Select * From /" + QueryRegionNames[0] + " where id = 1", attributes, true).ExecuteWithInitialResults();
                qs.NewCq(m_client2DurableCqNames[5], "Select * From /" + QueryRegionNames[0] + " where id = 10", attributes, true).ExecuteWithInitialResults();
                qs.NewCq(m_client2DurableCqNames[6], "Select * From /" + QueryRegionNames[0], attributes, true).ExecuteWithInitialResults();
                qs.NewCq(m_client2DurableCqNames[7], "Select * From /" + QueryRegionNames[0] + " where id = 3", attributes, true).ExecuteWithInitialResults();
            }
        }
        static void Main(string[] args)
        {
            try
            {
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory().SetSubscriptionEnabled(true);
                Cache        cache        = cacheFactory.Create();
                Console.WriteLine("Created the Geode Cache");

                RegionFactory            regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                IRegion <string, string> region        = regionFactory.Create <string, string>("exampleRegion");
                region.GetSubscriptionService().RegisterAllKeys();
                Console.WriteLine("RegisterAllKeys to exampleRegion");

                QueryService <string, string>        qrySvc   = cache.GetQueryService <string, string>();
                CqAttributesFactory <string, string> cqFac    = new CqAttributesFactory <string, string>();
                ICqListener <string, string>         cqLstner = new MyCqListener <string, string>();
                cqFac.AddCqListener(cqLstner);
                CqAttributes <string, string> cqAttr  = cqFac.Create();
                CqQuery <string, string>      qry     = qrySvc.NewCq("MyCq", "select * from /exampleRegion p where p.toString = '1'", cqAttr, false);
                ICqResults <string>           results = qry.ExecuteWithInitialResults();
                Console.WriteLine("Execute CQ: Initial ResultSet returned {0} rows", results.Size);

                while (true)
                {
                    System.Threading.Thread.Sleep(5000);
                    string val1 = null;
                    string val2 = null;
                    region.TryGetValue("1", ref val1);
                    region.TryGetValue("2", ref val2);
                    Console.WriteLine("exampleRegion['1']: {0}", val1);
                    Console.WriteLine("exampleRegion['2']: {0}", val2);
                }
            }
            catch (GeodeException gfex)
            {
                Console.WriteLine("Geode Exception: {0}", gfex.Message);
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            bool verbose = false;

            if (args.Length == 1 && args[0] == "-v")
            {
                verbose = true;
            }
            try {
                // Connect to the GemFire Distributed System using the settings from the gfcpp.properties file by default.
                Properties prop = Properties.Create();
                prop.Insert("cache-xml-file", "clientCqQuery.xml");
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(prop);
                Cache        cache        = cacheFactory.SetSubscriptionEnabled(true)
                                            .Create();

                Console.WriteLine("Created the GemFire Cache");

                // Get the Portfolios Region from the Cache which is declared in the Cache XML file.
                Region region = cache.GetRegion("Portfolios");

                Console.WriteLine("Obtained the Region from the Cache");

                region.GetAttributesMutator().SetCacheListener(new MyCacheListener(verbose));

                // Register our Serializable/Cacheable Query objects, viz. Portfolio and Position.
                Serializable.RegisterType(Portfolio.CreateDeserializable);
                Serializable.RegisterType(Position.CreateDeserializable);

                //Register all keys
                region.RegisterAllKeys();

                Console.WriteLine("Registered Serializable Query Objects");

                // Populate the Region with some Portfolio objects.
                Portfolio port1 = new Portfolio(1 /*ID*/, 10 /*size*/);
                Portfolio port2 = new Portfolio(2 /*ID*/, 20 /*size*/);
                Portfolio port3 = new Portfolio(3 /*ID*/, 30 /*size*/);
                region.Put("Key1", port1);
                region.Put("Key2", port2);
                region.Put("Key3", port3);

                Console.WriteLine("Populated some Portfolio Objects");

                // Get the QueryService from the Cache.
                QueryService qrySvc = cache.GetQueryService();

                Console.WriteLine("Got the QueryService from the Cache");

                //create CqAttributes with listener
                CqAttributesFactory cqFac    = new CqAttributesFactory();
                ICqListener         cqLstner = new MyCqListener(0, verbose);
                cqFac.AddCqListener(cqLstner);
                CqAttributes cqAttr = cqFac.Create();

                //create a new cqQuery
                CqQuery qry = qrySvc.NewCq(cqNames[0], queryStrings[0], cqAttr, true);

                // Execute a CqQuery with Initial Results
                ICqResults results = qry.ExecuteWithInitialResults();

                Console.WriteLine("ResultSet Query returned {0} rows", results.Size);

                SelectResultsIterator iter = results.GetIterator();

                while (iter.HasNext)
                {
                    IGFSerializable item = iter.Next();

                    if (item != null)
                    {
                        Struct st = item as Struct;

                        CacheableString key = st["key"] as CacheableString;

                        Console.WriteLine("Got key " + key.Value);

                        Portfolio port = st["value"] as Portfolio;

                        if (port == null)
                        {
                            Position pos = st["value"] as Position;
                            if (pos == null)
                            {
                                CacheableString cs = st["value"] as CacheableString;
                                if (cs == null)
                                {
                                    Console.WriteLine("Query got other/unknown object.");
                                }
                                else
                                {
                                    Console.WriteLine("Query got string : {0}.", cs.Value);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid);
                        }
                    }
                }
                //Stop the cq
                qry.Stop();
                //Restart the cq
                qry.Execute();

                for (int i = 1; i < cqNames.Length; i++)
                {
                    ICqListener cqLstner1 = new MyCqListener(i, verbose);
                    cqFac.AddCqListener(cqLstner1);
                    cqAttr = cqFac.Create();
                    qry    = qrySvc.NewCq(cqNames[i], queryStrings[i], cqAttr, true);
                }

                qry    = qrySvc.GetCq(cqNames[6]);
                cqAttr = qry.GetCqAttributes();
                ICqListener[] vl = cqAttr.getCqListeners();
                Console.WriteLine("number of listeners for cq[{0}] is {1}", cqNames[6], vl.Length);
                qry = qrySvc.GetCq(cqNames[0]);
                CqAttributesMutator cqam = qry.GetCqAttributesMutator();
                for (int i = 0; i < vl.Length; i++)
                {
                    cqam.AddCqListener(vl[i]);
                }

                //Stop the cq
                qry.Stop();

                //Start all Cq Query
                qrySvc.ExecuteCqs();

                for (int i = 0; i < cqNames.Length; i++)
                {
                    Console.WriteLine("get info for cq[{0}]:", cqNames[i]);
                    CqQuery      cqy     = qrySvc.GetCq(cqNames[i]);
                    CqStatistics cqStats = cqy.GetStatistics();
                    Console.WriteLine("Cq[{0}]: CqStatistics: numInserts[{1}], numDeletes[{2}], numUpdates[{3}], numEvents[{4}]",
                                      cqNames[i], cqStats.numInserts(), cqStats.numDeletes(), cqStats.numUpdates(), cqStats.numEvents());
                }

                CqServiceStatistics serviceStats = qrySvc.GetCqStatistics();
                Console.WriteLine("numCqsActive={0}, numCqsCreated={1}, numCqsClosed={2}, numCqsStopped={3}, numCqsOnClient={4}",
                                  serviceStats.numCqsActive(), serviceStats.numCqsCreated(), serviceStats.numCqsClosed(),
                                  serviceStats.numCqsStopped(), serviceStats.numCqsOnClient());

                while (true)
                {
                    Console.WriteLine("*******Type \'q\' to quit !!!! ******");
                    ConsoleKeyInfo ckey;
                    ckey = Console.ReadKey(true);
                    if (ckey.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }

                //Stop all cqs
                qrySvc.StopCqs();

                for (int i = 0; i < cqNames.Length; i++)
                {
                    Console.WriteLine("get info for cq[{0}]:", cqNames[i]);
                    CqQuery cqy = qrySvc.GetCq(cqNames[i]);
                    cqAttr = qry.GetCqAttributes();
                    vl     = cqAttr.getCqListeners();
                    Console.WriteLine("number of listeners for cq[{0}] is {1}", cqNames[i], vl.Length);
                    CqStatistics cqStats = cqy.GetStatistics();
                    Console.WriteLine("Cq[{0}]: CqStatistics: numInserts[{1}], numDeletes[{2}], numUpdates[{3}], numEvents[{4}]",
                                      cqNames[i], cqStats.numInserts(), cqStats.numDeletes(), cqStats.numUpdates(), cqStats.numEvents());
                }

                //Close all cqs
                qrySvc.CloseCqs();

                Console.WriteLine("numCqsActive={0}, numCqsCreated={1}, numCqsClosed={2}, numCqsStopped={3}, numCqsOnClient={4}",
                                  serviceStats.numCqsActive(), serviceStats.numCqsCreated(), serviceStats.numCqsClosed(), serviceStats.numCqsStopped(),
                                  serviceStats.numCqsOnClient());

                // Close the GemFire Cache.
                cache.Close();

                Console.WriteLine("Closed the GemFire Cache");
            }
            // An exception should not occur
            catch (GemFireException gfex) {
                Console.WriteLine("CqQuery GemFire Exception: {0}", gfex.Message);
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache Programmatically.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
                Cache        cache        = cacheFactory.SetSubscriptionEnabled(true)
                                            .AddServer("localhost", 50505)
                                            .Create();

                Console.WriteLine("Created the Geode Cache");

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY);
                // Create the example Region programmatically.
                IRegion <string, Portfolio> region = regionFactory.Create <string, Portfolio>("Portfolios");

                Console.WriteLine("Created the Region Programmatically.");

                // Register our Serializable/Cacheable Query objects, viz. Portfolio and Position.
                Serializable.RegisterTypeGeneric(Portfolio.CreateDeserializable);
                Serializable.RegisterTypeGeneric(Position.CreateDeserializable);

                Console.WriteLine("Registered Serializable Query Objects");

                // Populate the Region with some Portfolio objects.
                Portfolio port1 = new Portfolio(1 /*ID*/, 10 /*size*/);
                Portfolio port2 = new Portfolio(2 /*ID*/, 20 /*size*/);
                Portfolio port3 = new Portfolio(3 /*ID*/, 30 /*size*/);
                region["Key1"] = port1;
                region["Key2"] = port2;
                region["Key3"] = port3;

                Console.WriteLine("Populated some Portfolio Objects");

                // Get the QueryService from the Cache.
                QueryService <string, object> qrySvc = cache.GetQueryService <string, object>();

                Console.WriteLine("Got the QueryService from the Cache");

                //create CqAttributes with listener
                CqAttributesFactory <string, object> cqFac    = new CqAttributesFactory <string, object>();
                ICqListener <string, object>         cqLstner = new MyCqListener <string, object>();
                cqFac.AddCqListener(cqLstner);
                CqAttributes <string, object> cqAttr = cqFac.Create();

                //create a new cqQuery
                CqQuery <string, object> qry = qrySvc.NewCq("MyCq", "select * from /Portfolios" + "  p where p.ID!=2", cqAttr, false);

                // Execute a CqQuery with Initial Results
                ICqResults <object> results = qry.ExecuteWithInitialResults();

                Console.WriteLine("ResultSet Query returned {0} rows", results.Size);
                //make changes to generate cq events
                region["Key2"] = port1;
                region["Key3"] = port2;
                region["Key1"] = port3;

                SelectResultsIterator <object> iter = results.GetIterator();

                while (iter.HasNext)
                {
                    object item = iter.Next();

                    if (item != null)
                    {
                        Struct st = item as Struct;

                        string key = st["key"] as string;

                        Console.WriteLine("Got key " + key);

                        Portfolio port = st["value"] as Portfolio;

                        if (port == null)
                        {
                            Position pos = st["value"] as Position;
                            if (pos == null)
                            {
                                string cs = st["value"] as string;
                                if (cs == null)
                                {
                                    Console.WriteLine("Query got other/unknown object.");
                                }
                                else
                                {
                                    Console.WriteLine("Query got string : {0}.", cs);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid);
                        }
                    }
                }
                //Stop the cq
                qry.Stop();

                //Close the cq
                qry.Close();

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("CqQuery Geode Exception: {0}", gfex.Message);
            }
        }
Ejemplo n.º 12
0
        /*
         * public void StepOneFailover()
         * {
         * // This is here so that Client1 registers information of the cacheserver
         * // that has been already started
         * CacheHelper.SetupJavaServers("remotequery.xml",
         *  "cqqueryfailover.xml");
         * CacheHelper.StartJavaServer(1, "GFECS1");
         * Util.Log("Cacheserver 1 started.");
         *
         * CacheHelper.CreateTCRegion(QueryRegionNames[0], true, true, null, true);
         *
         * Region region = CacheHelper.GetVerifyRegion(QueryRegionNames[0]);
         * Portfolio p1 = new Portfolio(1, 100);
         * Portfolio p2 = new Portfolio(2, 200);
         * Portfolio p3 = new Portfolio(3, 300);
         * Portfolio p4 = new Portfolio(4, 400);
         *
         * region.Put("1", p1);
         * region.Put("2", p2);
         * region.Put("3", p3);
         * region.Put("4", p4);
         * }
         */
        /*
         * public void StepTwoFailover()
         * {
         * CacheHelper.StartJavaServer(2, "GFECS2");
         * Util.Log("Cacheserver 2 started.");
         *
         * IAsyncResult killRes = null;
         * KillServerDelegate ksd = new KillServerDelegate(KillServer);
         * CacheHelper.CreateTCRegion(QueryRegionNames[0], true, true, null, true);
         *
         * IRegion<object, object> region = CacheHelper.GetVerifyRegion<object, object>(QueryRegionNames[0]);
         *
         * var qs = CacheHelper.DCache.GetQueryService();
         * CqAttributesFactory cqFac = new CqAttributesFactory();
         * ICqListener cqLstner = new MyCqListener();
         * cqFac.AddCqListener(cqLstner);
         * CqAttributes cqAttr = cqFac.Create();
         * CqQuery qry = qs.NewCq(CqName1, "select * from /" + QERegionName + "  p where p.ID!<4", cqAttr, true);
         * qry.Execute();
         * Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
         * qry = qs.GetCq(CqName1);
         * cqAttr = qry.GetCqAttributes();
         * ICqListener[] vl = cqAttr.getCqListeners();
         * Assert.IsNotNull(vl);
         * Assert.AreEqual(1, vl.Length);
         * cqLstner = vl[0];
         * Assert.IsNotNull(cqLstner);
         * MyCqListener myLisner = cqLstner as MyCqListener;
         * if (myLisner.getEventCountAfter() + myLisner.getErrorCountAfter() != 0)
         * {
         *  Assert.Fail("cq after count not zero");
         * }
         *
         * killRes = ksd.BeginInvoke(null, null);
         * Thread.Sleep(18000); // sleep 0.3min to allow failover complete
         * myLisner.failedOver();
         *
         * Portfolio p1 = new Portfolio(1, 100);
         * Portfolio p2 = new Portfolio(2, 200);
         * Portfolio p3 = new Portfolio(3, 300);
         * Portfolio p4 = new Portfolio(4, 400);
         *
         * region.Put("4", p1);
         * region.Put("3", p2);
         * region.Put("2", p3);
         * region.Put("1", p4);
         * Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
         *
         * qry = qs.GetCq(CqName1);
         * cqAttr = qry.GetCqAttributes();
         * vl = cqAttr.getCqListeners();
         * cqLstner = vl[0];
         * Assert.IsNotNull(vl);
         * Assert.AreEqual(1, vl.Length);
         * cqLstner = vl[0];
         * Assert.IsNotNull(cqLstner);
         * myLisner = cqLstner as MyCqListener;
         * if (myLisner.getEventCountAfter() + myLisner.getErrorCountAfter() == 0)
         * {
         *  Assert.Fail("no cq after failover");
         * }
         *
         * killRes.AsyncWaitHandle.WaitOne();
         * ksd.EndInvoke(killRes);
         * qry.Stop();
         * qry.Close();
         * }
         */

        public void ProcessCQ(string locators)
        {
            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);

            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);
            Portfolio p1 = new Portfolio(1, 100);
            Portfolio p2 = new Portfolio(2, 100);
            Portfolio p3 = new Portfolio(3, 100);
            Portfolio p4 = new Portfolio(4, 100);

            region["1"] = p1;
            region["2"] = p2;
            region["3"] = p3;
            region["4"] = p4;

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();

            CqAttributesFactory <object, object> cqFac          = new CqAttributesFactory <object, object>();
            ICqListener <object, object>         cqLstner       = new MyCqListener <object, object>();
            ICqStatusListener <object, object>   cqStatusLstner = new MyCqStatusListener <object, object>(1);

            ICqListener <object, object>[] v = new ICqListener <object, object> [2];
            cqFac.AddCqListener(cqLstner);
            v[0] = cqLstner;
            v[1] = cqStatusLstner;
            cqFac.InitCqListeners(v);
            Util.Log("InitCqListeners called");
            CqAttributes <object, object> cqAttr = cqFac.Create();
            CqQuery <object, object>      qry1   = qs.NewCq("CQ1", "select * from /" + QERegionName + "  p where p.ID >= 1", cqAttr, false);

            qry1.Execute();

            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete

            qry1   = qs.GetCq <object, object>("CQ1");
            cqAttr = qry1.GetCqAttributes();
            ICqListener <object, object>[] vl = cqAttr.getCqListeners();
            Assert.IsNotNull(vl);
            Assert.AreEqual(2, vl.Length);
            cqLstner = vl[0];
            Assert.IsNotNull(cqLstner);
            MyCqListener <object, object> myLisner = (MyCqListener <object, object>)cqLstner;// as MyCqListener<object, object>;

            Util.Log("event count:{0}, error count {1}.", myLisner.getEventCountBefore(), myLisner.getErrorCountBefore());
            Assert.AreEqual(4, myLisner.getEventCountBefore());

            cqStatusLstner = (ICqStatusListener <object, object>)vl[1];
            Assert.IsNotNull(cqStatusLstner);
            MyCqStatusListener <object, object> myStatLisner = (MyCqStatusListener <object, object>)cqStatusLstner;// as MyCqStatusListener<object, object>;

            Util.Log("event count:{0}, error count {1}.", myStatLisner.getEventCountBefore(), myStatLisner.getErrorCountBefore());
            Assert.AreEqual(1, myStatLisner.getCqConnectedCount());
            Assert.AreEqual(4, myStatLisner.getEventCountBefore());

            CqAttributesMutator <object, object> mutator = qry1.GetCqAttributesMutator();

            mutator.RemoveCqListener(cqLstner);
            cqAttr = qry1.GetCqAttributes();
            Util.Log("cqAttr.getCqListeners().Length = {0}", cqAttr.getCqListeners().Length);
            Assert.AreEqual(1, cqAttr.getCqListeners().Length);

            mutator.RemoveCqListener(cqStatusLstner);
            cqAttr = qry1.GetCqAttributes();
            Util.Log("1 cqAttr.getCqListeners().Length = {0}", cqAttr.getCqListeners().Length);
            Assert.AreEqual(0, cqAttr.getCqListeners().Length);

            ICqListener <object, object>[] v2 = new ICqListener <object, object> [2];
            v2[0] = cqLstner;
            v2[1] = cqStatusLstner;
            MyCqListener <object, object> myLisner2 = (MyCqListener <object, object>)cqLstner;

            myLisner2.Clear();
            MyCqStatusListener <object, object> myStatLisner2 = (MyCqStatusListener <object, object>)cqStatusLstner;

            myStatLisner2.Clear();
            mutator.SetCqListeners(v2);
            cqAttr = qry1.GetCqAttributes();
            Assert.AreEqual(2, cqAttr.getCqListeners().Length);

            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete

            qry1   = qs.GetCq <object, object>("CQ1");
            cqAttr = qry1.GetCqAttributes();
            ICqListener <object, object>[] v3 = cqAttr.getCqListeners();
            Assert.IsNotNull(v3);
            Assert.AreEqual(2, vl.Length);
            cqLstner = v3[0];
            Assert.IsNotNull(cqLstner);
            myLisner2 = (MyCqListener <object, object>)cqLstner;// as MyCqListener<object, object>;
            Util.Log("event count:{0}, error count {1}.", myLisner2.getEventCountBefore(), myLisner2.getErrorCountBefore());
            Assert.AreEqual(4, myLisner2.getEventCountBefore());

            cqStatusLstner = (ICqStatusListener <object, object>)v3[1];
            Assert.IsNotNull(cqStatusLstner);
            myStatLisner2 = (MyCqStatusListener <object, object>)cqStatusLstner;// as MyCqStatusListener<object, object>;
            Util.Log("event count:{0}, error count {1}.", myStatLisner2.getEventCountBefore(), myStatLisner2.getErrorCountBefore());
            Assert.AreEqual(0, myStatLisner2.getCqConnectedCount());
            Assert.AreEqual(4, myStatLisner2.getEventCountBefore());

            mutator = qry1.GetCqAttributesMutator();
            mutator.RemoveCqListener(cqLstner);
            cqAttr = qry1.GetCqAttributes();
            Util.Log("cqAttr.getCqListeners().Length = {0}", cqAttr.getCqListeners().Length);
            Assert.AreEqual(1, cqAttr.getCqListeners().Length);

            mutator.RemoveCqListener(cqStatusLstner);
            cqAttr = qry1.GetCqAttributes();
            Util.Log("1 cqAttr.getCqListeners().Length = {0}", cqAttr.getCqListeners().Length);
            Assert.AreEqual(0, cqAttr.getCqListeners().Length);

            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete

            qry1   = qs.GetCq <object, object>("CQ1");
            cqAttr = qry1.GetCqAttributes();
            ICqListener <object, object>[] v4 = cqAttr.getCqListeners();
            Assert.IsNotNull(v4);
            Assert.AreEqual(0, v4.Length);
            Util.Log("cqAttr.getCqListeners() done");
        }
Ejemplo n.º 13
0
        public void StepOnePdxQE(string locators)
        {
            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);
            PortfolioPdx             p1     = new PortfolioPdx(1, 100);
            PortfolioPdx             p2     = new PortfolioPdx(2, 100);
            PortfolioPdx             p3     = new PortfolioPdx(3, 100);
            PortfolioPdx             p4     = new PortfolioPdx(4, 100);

            region["1"] = p1;
            region["2"] = p2;
            region["3"] = p3;
            region["4"] = p4;

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();
            CqAttributesFactory <object, object> cqFac    = new CqAttributesFactory <object, object>();
            ICqListener <object, object>         cqLstner = new MyCqListener <object, object>();

            cqFac.AddCqListener(cqLstner);
            CqAttributes <object, object> cqAttr = cqFac.Create();
            CqQuery <object, object>      qry    = qs.NewCq(CqName, "select * from /" + QERegionName + "  p where p.ID!=2", cqAttr, false);

            qry.Execute();
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete

            qry = qs.GetCq <object, object>(CqName);

            CqServiceStatistics cqSvcStats = qs.GetCqStatistics();

            Assert.AreEqual(1, cqSvcStats.numCqsActive());
            Assert.AreEqual(1, cqSvcStats.numCqsCreated());
            Assert.AreEqual(1, cqSvcStats.numCqsOnClient());

            cqAttr = qry.GetCqAttributes();
            ICqListener <object, object>[] vl = cqAttr.getCqListeners();
            Assert.IsNotNull(vl);
            Assert.AreEqual(1, vl.Length);
            cqLstner = vl[0];
            Assert.IsNotNull(cqLstner);
            MyCqListener <object, object> myLisner = (MyCqListener <object, object>)cqLstner;// as MyCqListener<object, object>;

            Util.Log("event count:{0}, error count {1}.", myLisner.getEventCountBefore(), myLisner.getErrorCountBefore());

            CqStatistics cqStats = qry.GetStatistics();

            Assert.AreEqual(cqStats.numEvents(), myLisner.getEventCountBefore());
            if (myLisner.getEventCountBefore() + myLisner.getErrorCountBefore() == 0)
            {
                Assert.Fail("cq before count zero");
            }
            qry.Stop();
            Assert.AreEqual(1, cqSvcStats.numCqsStopped());
            qry.Close();
            Assert.AreEqual(1, cqSvcStats.numCqsClosed());
            // Bring down the region
            region.GetLocalView().DestroyRegion();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            try
            {
                //Create CacheFactory using the user specified properties or from the gfcpp.properties file by default.
                Properties <string, string> prp = Properties <string, string> .Create <string, string>();

                prp.Insert("cache-xml-file", "XMLs/clientPoolCqQuery.xml");
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(prp);

                Console.WriteLine("Created CacheFactory");

                // Create a Geode Cache with the "clientPoolCqQuery.xml" Cache XML file.
                Cache cache = cacheFactory.Create();

                Console.WriteLine("Created the Geode Cache");

                // Get the Portfolios Region from the Cache which is declared in the Cache XML file.
                IRegion <string, Portfolio> region = cache.GetRegion <string, Portfolio>("Portfolios");

                Console.WriteLine("Obtained the Region from the Cache");

                // Register our Serializable/Cacheable Query objects, viz. Portfolio and Position.
                Serializable.RegisterTypeGeneric(Portfolio.CreateDeserializable);
                Serializable.RegisterTypeGeneric(Position.CreateDeserializable);

                Console.WriteLine("Registered Serializable Query Objects");

                // Populate the Region with some Portfolio objects.
                Portfolio port1 = new Portfolio(1 /*ID*/, 10 /*size*/);
                Portfolio port2 = new Portfolio(2 /*ID*/, 20 /*size*/);
                Portfolio port3 = new Portfolio(3 /*ID*/, 30 /*size*/);
                region["Key1"] = port1;
                region["Key2"] = port2;
                region["Key3"] = port3;

                Console.WriteLine("Populated some Portfolio Objects");

                Pool pp = PoolManager.Find("examplePool");

                // Get the QueryService from the Pool
                QueryService <string, object> qrySvc = pp.GetQueryService <string, object>();

                Console.WriteLine("Got the QueryService from the Cache");

                //create CqAttributes with listener
                CqAttributesFactory <string, object> cqFac    = new CqAttributesFactory <string, object>();
                ICqListener <string, object>         cqLstner = new MyCqListener <string, object>();
                cqFac.AddCqListener(cqLstner);
                CqAttributes <string, object> cqAttr = cqFac.Create();

                //create a new cqQuery
                CqQuery <string, object> qry = qrySvc.NewCq("MyCq", "select * from /Portfolios" + "  p where p.ID!=2", cqAttr, false);

                // Execute a CqQuery with Initial Results
                ICqResults <object> results = qry.ExecuteWithInitialResults();

                Console.WriteLine("ResultSet Query returned {0} rows", results.Size);
                //make changes to generate cq events
                region["Key2"] = port1;
                region["Key3"] = port2;
                region["Key1"] = port3;

                SelectResultsIterator <object> iter = results.GetIterator();

                while (iter.HasNext)
                {
                    object item = iter.Next();

                    if (item != null)
                    {
                        Struct st  = item as Struct;
                        string key = st["key"] as string;;
                        Console.WriteLine("Got key " + key);
                        Portfolio port = st["value"] as Portfolio;
                        if (port == null)
                        {
                            Position pos = st["value"] as Position;
                            if (pos == null)
                            {
                                string cs = st["value"] as string;
                                if (cs == null)
                                {
                                    Console.WriteLine("Query got other/unknown object.");
                                }
                                else
                                {
                                    Console.WriteLine("Query got string : {0}.", cs);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid);
                        }
                    }
                }
                //Stop the cq
                qry.Stop();

                //Close the cq
                qry.Close();

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("PoolCqQuery Geode Exception: {0}", gfex.Message);
            }
        }
Ejemplo n.º 15
0
        protected void DoOp(OperationCode op, int[] indices,
                            OpFlags flags, ExpectedResult expectedResult, Properties <string, string> creds, bool isMultiuser)
        {
            IRegion <object, object> region;

            if (isMultiuser)
            {
                region = CacheHelper.GetRegion <object, object>(RegionName, creds);
            }
            else
            {
                region = CacheHelper.GetRegion <object, object>(RegionName);
            }

            if (CheckFlags(flags, OpFlags.UseSubRegion))
            {
                IRegion <object, object> subregion = null;
                if (CheckFlags(flags, OpFlags.NoCreateSubRegion))
                {
                    subregion = region.GetSubRegion(SubregionName);
                    if (CheckFlags(flags, OpFlags.CheckNoRegion))
                    {
                        Assert.IsNull(subregion);
                        return;
                    }
                    else
                    {
                        Assert.IsNotNull(subregion);
                    }
                }
                else
                {
                    subregion = CreateSubregion(region);
                    if (isMultiuser)
                    {
                        subregion = region.GetSubRegion(SubregionName);
                    }
                }
                Assert.IsNotNull(subregion);
                region = subregion;
            }
            else if (CheckFlags(flags, OpFlags.CheckNoRegion))
            {
                Assert.IsNull(region);
                return;
            }
            else
            {
                Assert.IsNotNull(region);
            }
            string valPrefix;

            if (CheckFlags(flags, OpFlags.UseNewVal))
            {
                valPrefix = NValuePrefix;
            }
            else
            {
                valPrefix = ValuePrefix;
            }
            int numOps = indices.Length;

            Util.Log("Got DoOp for op: " + op + ", numOps: " + numOps
                     + ", indices: " + IndicesToString(indices));
            bool exceptionOccured = false;
            bool breakLoop        = false;

            for (int indexIndex = 0; indexIndex < indices.Length; ++indexIndex)
            {
                if (breakLoop)
                {
                    break;
                }
                int    index         = indices[indexIndex];
                string key           = KeyPrefix + index;
                string expectedValue = (valPrefix + index);
                try
                {
                    switch (op)
                    {
                    case OperationCode.Get:
                        Object value = null;
                        if (CheckFlags(flags, OpFlags.LocalOp))
                        {
                            int  sleepMillis = 100;
                            int  numTries    = 30;
                            bool success     = false;
                            while (!success && numTries-- > 0)
                            {
                                if (!isMultiuser && region.ContainsValueForKey(key))
                                {
                                    value   = region[key];
                                    success = expectedValue.Equals(value.ToString());
                                    if (CheckFlags(flags, OpFlags.CheckFail))
                                    {
                                        success = !success;
                                    }
                                }
                                else
                                {
                                    value   = null;
                                    success = CheckFlags(flags, OpFlags.CheckFail);
                                }
                                if (!success)
                                {
                                    Thread.Sleep(sleepMillis);
                                }
                            }
                        }
                        else
                        {
                            if (!isMultiuser)
                            {
                                if (CheckFlags(flags, OpFlags.CheckNoKey))
                                {
                                    Assert.IsFalse(region.GetLocalView().ContainsKey(key));
                                }
                                else
                                {
                                    Assert.IsTrue(region.GetLocalView().ContainsKey(key));
                                    region.GetLocalView().Invalidate(key);
                                }
                            }
                            try
                            {
                                value = region[key];
                            }
                            catch (Client.KeyNotFoundException)
                            {
                                Util.Log("KeyNotFoundException while getting key. should be ok as we are just testing auth");
                            }
                        }
                        if (!isMultiuser && value != null)
                        {
                            if (CheckFlags(flags, OpFlags.CheckFail))
                            {
                                Assert.AreNotEqual(expectedValue, value.ToString());
                            }
                            else
                            {
                                Assert.AreEqual(expectedValue, value.ToString());
                            }
                        }
                        break;

                    case OperationCode.Put:
                        region[key] = expectedValue;
                        break;

                    case OperationCode.Destroy:
                        if (!isMultiuser && !region.GetLocalView().ContainsKey(key))
                        {
                            // Since DESTROY will fail unless the value is present
                            // in the local cache, this is a workaround for two cases:
                            // 1. When the operation is supposed to succeed then in
                            // the current AuthzCredentialGenerators the clients having
                            // DESTROY permission also has CREATE/UPDATE permission
                            // so that calling region.Put() will work for that case.
                            // 2. When the operation is supposed to fail with
                            // NotAuthorizedException then in the current
                            // AuthzCredentialGenerators the clients not
                            // having DESTROY permission are those with reader role that have
                            // GET permission.
                            //
                            // If either of these assumptions fails, then this has to be
                            // adjusted or reworked accordingly.
                            if (CheckFlags(flags, OpFlags.CheckNotAuthz))
                            {
                                value = region[key];
                                Assert.AreEqual(expectedValue, value.ToString());
                            }
                            else
                            {
                                region[key] = expectedValue;
                            }
                        }
                        if (!isMultiuser && CheckFlags(flags, OpFlags.LocalOp))
                        {
                            region.GetLocalView().Remove(key); //Destroyed replaced by Remove() API
                        }
                        else
                        {
                            region.Remove(key); //Destroyed replaced by Remove API
                        }
                        break;

                    //TODO: Need to fix Stack overflow exception..
                    case OperationCode.RegisterInterest:
                        if (CheckFlags(flags, OpFlags.UseList))
                        {
                            breakLoop = true;
                            // Register interest list in this case
                            List <CacheableKey> keyList = new List <CacheableKey>(numOps);
                            for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex)
                            {
                                int keyNum = indices[keyNumIndex];
                                keyList.Add(KeyPrefix + keyNum);
                            }
                            region.GetSubscriptionService().RegisterKeys(keyList.ToArray());
                        }
                        else if (CheckFlags(flags, OpFlags.UseRegex))
                        {
                            breakLoop = true;
                            region.GetSubscriptionService().RegisterRegex(KeyPrefix + "[0-" + (numOps - 1) + ']');
                        }
                        else if (CheckFlags(flags, OpFlags.UseAllKeys))
                        {
                            breakLoop = true;
                            region.GetSubscriptionService().RegisterAllKeys();
                        }
                        break;

                    //TODO: Need to fix Stack overflow exception..
                    case OperationCode.UnregisterInterest:
                        if (CheckFlags(flags, OpFlags.UseList))
                        {
                            breakLoop = true;
                            // Register interest list in this case
                            List <CacheableKey> keyList = new List <CacheableKey>(numOps);
                            for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex)
                            {
                                int keyNum = indices[keyNumIndex];
                                keyList.Add(KeyPrefix + keyNum);
                            }
                            region.GetSubscriptionService().UnregisterKeys(keyList.ToArray());
                        }
                        else if (CheckFlags(flags, OpFlags.UseRegex))
                        {
                            breakLoop = true;
                            region.GetSubscriptionService().UnregisterRegex(KeyPrefix + "[0-" + (numOps - 1) + ']');
                        }
                        else if (CheckFlags(flags, OpFlags.UseAllKeys))
                        {
                            breakLoop = true;
                            region.GetSubscriptionService().UnregisterAllKeys();
                        }
                        break;

                    case OperationCode.Query:
                        breakLoop = true;
                        ISelectResults <object> queryResults;

                        if (!isMultiuser)
                        {
                            queryResults = (ResultSet <object>)region.Query <object>(
                                "SELECT DISTINCT * FROM " + region.FullPath);
                        }
                        else
                        {
                            queryResults = CacheHelper.getMultiuserCache(creds).GetQueryService().NewQuery <object>("SELECT DISTINCT * FROM " + region.FullPath).Execute();
                        }
                        Assert.IsNotNull(queryResults);
                        if (!CheckFlags(flags, OpFlags.CheckFail))
                        {
                            Assert.AreEqual(numOps, queryResults.Size);
                        }
                        //CacheableHashSet querySet = new CacheableHashSet(queryResults.Size);
                        List <string>      querySet = new List <string>(queryResults.Size);
                        ResultSet <object> rs       = queryResults as ResultSet <object>;
                        foreach (object result in  rs)
                        {
                            querySet.Add(result.ToString());
                        }
                        for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex)
                        {
                            int    keyNum      = indices[keyNumIndex];
                            string expectedVal = valPrefix + keyNumIndex;
                            if (CheckFlags(flags, OpFlags.CheckFail))
                            {
                                Assert.IsFalse(querySet.Contains(expectedVal));
                            }
                            else
                            {
                                Assert.IsTrue(querySet.Contains(expectedVal));
                            }
                        }
                        break;

                    case OperationCode.RegionDestroy:
                        breakLoop = true;
                        if (!isMultiuser && CheckFlags(flags, OpFlags.LocalOp))
                        {
                            region.GetLocalView().DestroyRegion();
                        }
                        else
                        {
                            region.DestroyRegion();
                        }
                        break;

                    case OperationCode.GetServerKeys:
                        breakLoop = true;
                        ICollection <object> serverKeys = region.Keys;
                        break;

                    //TODO: Need to fix System.ArgumentOutOfRangeException: Index was out of range. Know issue with GetAll()
                    case OperationCode.GetAll:
                        //ICacheableKey[] keymap = new ICacheableKey[5];
                        List <object> keymap = new List <object>();
                        for (int i = 0; i < 5; i++)
                        {
                            keymap.Add(i);
                            //CacheableInt32 item = CacheableInt32.Create(i);
                            //Int32 item = i;
                            // NOTE: GetAll should operate right after PutAll
                            //keymap[i] = item;
                        }
                        Dictionary <Object, Object> entrymap = new Dictionary <Object, Object>();
                        //CacheableHashMap entrymap = CacheableHashMap.Create();
                        region.GetAll(keymap, entrymap, null, false);
                        if (entrymap.Count < 5)
                        {
                            Assert.Fail("DoOp: Got fewer entries for op " + op);
                        }
                        break;

                    case OperationCode.PutAll:
                        // NOTE: PutAll should operate right before GetAll
                        //CacheableHashMap entrymap2 = CacheableHashMap.Create();
                        Dictionary <Object, Object> entrymap2 = new Dictionary <object, object>();
                        for (int i = 0; i < 5; i++)
                        {
                            //CacheableInt32 item = CacheableInt32.Create(i);
                            Int32 item = i;
                            entrymap2.Add(item, item);
                        }
                        region.PutAll(entrymap2);
                        break;

                    case OperationCode.RemoveAll:
                        Dictionary <Object, Object> entrymap3 = new Dictionary <object, object>();
                        for (int i = 0; i < 5; i++)
                        {
                            //CacheableInt32 item = CacheableInt32.Create(i);
                            Int32 item = i;
                            entrymap3.Add(item, item);
                        }
                        region.PutAll(entrymap3);
                        ICollection <object> keys = new LinkedList <object>();
                        for (int i = 0; i < 5; i++)
                        {
                            Int32 item = i;
                            keys.Add(item);
                        }
                        region.RemoveAll(keys);
                        break;

                    case OperationCode.ExecuteCQ:
                        Pool /*<object, object>*/ pool = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_");
                        QueryService qs;
                        if (pool != null)
                        {
                            qs = pool.GetQueryService();
                        }
                        else
                        {
                            //qs = CacheHelper.DCache.GetQueryService();
                            qs = null;
                        }
                        CqAttributesFactory <object, object> cqattrsfact = new CqAttributesFactory <object, object>();
                        CqAttributes <object, object>        cqattrs     = cqattrsfact.Create();
                        CqQuery <object, object>             cq          = qs.NewCq("cq_security", "SELECT * FROM /" + region.Name, cqattrs, false);
                        qs.ExecuteCqs();
                        qs.StopCqs();
                        qs.CloseCqs();
                        break;

                    case OperationCode.ExecuteFunction:
                        if (!isMultiuser)
                        {
                            Pool /*<object, object>*/ pool2 = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_");
                            if (pool2 != null)
                            {
                                Client.FunctionService <object> .OnServer(pool2).Execute("securityTest");

                                Client.FunctionService <object> .OnRegion <object, object>(region).Execute("FireNForget");
                            }
                            else
                            {
                                expectedResult = ExpectedResult.Success;
                            }
                        }
                        else
                        {
                            //FunctionService fs = CacheHelper.getMultiuserCache(creds).GetFunctionService();
                            //Execution exe =  fs.OnServer();
                            IRegionService userCache = CacheHelper.getMultiuserCache(creds);
                            Apache.Geode.Client.Execution <object> exe = Client.FunctionService <object> .OnServer(userCache);

                            exe.Execute("securityTest");
                            exe = Client.FunctionService <object> .OnServers(userCache);

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

                            Client.FunctionService <object> .OnRegion <object, object>(userCache.GetRegion <object, object>(region.Name)).Execute("FireNForget");
                        }
                        break;

                    default:
                        Assert.Fail("DoOp: Unhandled operation " + op);
                        break;
                    }

                    if (expectedResult != ExpectedResult.Success)
                    {
                        Assert.Fail("Expected an exception while performing operation");
                    }
                }
                catch (AssertionException ex)
                {
                    Util.Log("DoOp: failed assertion: {0}", ex);
                    throw;
                }
                catch (NotAuthorizedException ex)
                {
                    exceptionOccured = true;
                    if (expectedResult == ExpectedResult.NotAuthorizedException)
                    {
                        Util.Log(
                            "DoOp: Got expected NotAuthorizedException when doing operation ["
                            + op + "] with flags [" + flags + "]: " + ex.Message);
                        continue;
                    }
                    else
                    {
                        Assert.Fail("DoOp: Got unexpected NotAuthorizedException when " +
                                    "doing operation: " + ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    exceptionOccured = true;
                    if (expectedResult == ExpectedResult.OtherException)
                    {
                        Util.Log("DoOp: Got expected exception when doing operation: " +
                                 ex.GetType() + "::" + ex.Message);
                        continue;
                    }
                    else
                    {
                        Assert.Fail("DoOp: Got unexpected exception when doing operation: " + ex);
                    }
                }
            }

            if (!exceptionOccured &&
                expectedResult != ExpectedResult.Success)
            {
                Assert.Fail("Expected an exception while performing operation");
            }
            Util.Log(" doop done");
        }
Ejemplo n.º 16
0
        public void StepOneQE(string locators)
        {
            CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true,
                                                             null, locators, "__TESTPOOL1_", true);

            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName);
            Portfolio p1 = new Portfolio(1, 100);
            Portfolio p2 = new Portfolio(2, 100);
            Portfolio p3 = new Portfolio(3, 100);
            Portfolio p4 = new Portfolio(4, 100);

            region["1"] = p1;
            region["2"] = p2;
            region["3"] = p3;
            region["4"] = p4;

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();
            CqAttributesFactory <object, object> cqFac    = new CqAttributesFactory <object, object>();
            ICqListener <object, object>         cqLstner = new MyCqListener <object, object>();

            cqFac.AddCqListener(cqLstner);
            CqAttributes <object, object> cqAttr  = cqFac.Create();
            CqQuery <object, object>      qry     = qs.NewCq(CqName, "select * from /" + QERegionName + "  p where p.ID!=2", cqAttr, false);
            ICqResults <object>           results = qry.ExecuteWithInitialResults();

            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            region["4"] = p1;
            region["3"] = p2;
            region["2"] = p3;
            region["1"] = p4;
            Thread.Sleep(18000); // sleep 0.3min to allow server c query to complete
            Util.Log("Results size {0}.", results.Size);

            foreach (var item in results)
            {
                if (item != null)
                {
                    Struct st = item as Struct;

                    string key = st["key"] as string;

                    Assert.IsNotNull(key, "key is null");

                    Portfolio port = st["value"] as Portfolio;

                    if (port == null)
                    {
                        Position pos = st["value"] as Position;
                        if (pos == null)
                        {
                            string cs = item as string;

                            if (cs == null)
                            {
                                Assert.Fail("value is null");
                                Util.Log("Query got other/unknown object.");
                            }
                            else
                            {
                                Util.Log("Query got string : {0}.", cs);
                            }
                        }
                        else
                        {
                            Util.Log("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding);
                        }
                    }
                    else
                    {
                        Util.Log("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid);
                    }
                }
            }
            qry = qs.GetCq <object, object>(CqName);
            qry.Stop();
            qry.Close();
            // Bring down the region
            region.GetLocalView().DestroyRegion();
        }