public void StepOneQE(string locators, bool isPdx) { m_isPdx = isPdx; try { var poolFail = CacheHelper.DCache.GetPoolManager().CreateFactory().Create("_TESTFAILPOOL_"); var qsFail = poolFail.GetQueryService(); var qryFail = qsFail.NewQuery <object>("select distinct * from /" + QERegionName); var resultsFail = qryFail.Execute(); Assert.Fail("Since no endpoints defined, so exception expected"); } catch (IllegalStateException ex) { Util.Log("Got expected exception: {0}", ex); } catch (Exception e) { Util.Log("Caught unexpected exception: {0}", e); throw e; } CacheHelper.CreateTCRegion_Pool <object, object>(QERegionName, true, true, null, locators, "__TESTPOOL1_", true); IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QERegionName); if (!m_isPdx) { 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; } else { 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(); Query <object> qry = qs.NewQuery <object>("select distinct * from /" + QERegionName); ISelectResults <object> results = qry.Execute(); var count = results.Size; Assert.AreEqual(4, count, "Expected 4 as number of portfolio objects."); // Bring down the region region.GetLocalView().DestroyRegion(); }
public void StepOneFailover(bool isPdx) { m_isPdx = isPdx; // This is here so that Client1 registers information of the cacheserver // that has been already started CacheHelper.SetupJavaServers(true, "cacheserver_remoteoqlN.xml", "cacheserver_remoteoql2N.xml"); CacheHelper.StartJavaLocator(1, "GFELOC"); Util.Log("Locator started"); CacheHelper.StartJavaServerWithLocators(1, "GFECS1", 1); Util.Log("Cacheserver 1 started."); CacheHelper.CreateTCRegion_Pool <object, object>(QueryRegionNames[0], true, true, null, CacheHelper.Locators, "__TESTPOOL1_", true); IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(QueryRegionNames[0]); if (!m_isPdx) { 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["1"] = p1; region["2"] = p2; region["3"] = p3; region["4"] = p4; } else { PortfolioPdx p1 = new PortfolioPdx(1, 100); PortfolioPdx p2 = new PortfolioPdx(2, 200); PortfolioPdx p3 = new PortfolioPdx(3, 300); PortfolioPdx p4 = new PortfolioPdx(4, 400); region["1"] = p1; region["2"] = p2; region["3"] = p3; region["4"] = p4; } }
public virtual void OnEvent(CqEvent <TKey, TResult> ev) { Util.Log("MyCqListener::OnEvent called"); if (m_failedOver == true) { m_eventCountAfter++; } else { m_eventCountBefore++; } //IGeodeSerializable val = ev.getNewValue(); //ICacheableKey key = ev.getKey(); TResult val = (TResult)ev.getNewValue(); /*ICacheableKey*/ TKey key = ev.getKey(); CqOperation opType = ev.getQueryOperation(); //CacheableString keyS = key as CacheableString; string keyS = key.ToString(); //as string; Portfolio pval = val as Portfolio; PortfolioPdx pPdxVal = val as PortfolioPdx; Assert.IsTrue((pPdxVal != null) || (pval != null)); //string opStr = "DESTROY"; /*if (opType == CqOperation.OP_TYPE_CREATE) * opStr = "CREATE"; * else if (opType == CqOperation.OP_TYPE_UPDATE) * opStr = "UPDATE";*/ //Util.Log("key {0}, value ({1},{2}), op {3}.", keyS, // pval.ID, pval.Pkid, opStr); }
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(); }
public void StepThreeRS() { bool ErrorOccurred = false; QueryHelper<object, object> qh = QueryHelper<object, object>.GetHelper(CacheHelper.DCache); var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService(); int qryIdx = 0; foreach (QueryStrings qrystr in QueryStatics.ResultSetQueries) { if (qrystr.Category == QueryCategory.Unsupported) { Util.Log("Skipping query index {0} because it is unsupported.", qryIdx); qryIdx++; continue; } if (m_isPdx == true) { if (qryIdx == 2 || qryIdx == 3 || qryIdx == 4) { Util.Log("Skipping query index {0} for Pdx because it is function type.", qryIdx); qryIdx++; continue; } } Util.Log("Evaluating query index {0}. Query string {1}", qryIdx, qrystr.Query); Query<object> query = qs.NewQuery<object>(qrystr.Query); ISelectResults<object> results = query.Execute(); int expectedRowCount = qh.IsExpectedRowsConstantRS(qryIdx) ? QueryStatics.ResultSetRowCounts[qryIdx] : QueryStatics.ResultSetRowCounts[qryIdx] * qh.PortfolioNumSets; if (!qh.VerifyRS(results, expectedRowCount)) { ErrorOccurred = true; Util.Log("Query verify failed for query index {0}.", qryIdx); qryIdx++; continue; } ResultSet<object> rs = results as ResultSet<object>; foreach (object item in rs) { if (!m_isPdx) { Portfolio port = item as Portfolio; if (port == null) { Position pos = item as Position; if (pos == null) { string cs = item.ToString(); if (cs == 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); } } else { PortfolioPdx port = item as PortfolioPdx; if (port == null) { PositionPdx pos = item as PositionPdx; if (pos == null) { string cs = item.ToString(); if (cs == 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.getSharesOutstanding); } } else { Util.Log("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid); } } } qryIdx++; } Assert.IsFalse(ErrorOccurred, "One or more query validation errors occurred."); }
public void StepThreePQRS() { bool ErrorOccurred = false; QueryHelper <object, object> qh = QueryHelper <object, object> .GetHelper(CacheHelper.DCache); var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService(); int qryIdx = 0; foreach (QueryStrings paramqrystr in QueryStatics.ResultSetParamQueries) { if (paramqrystr.Category == QueryCategory.Unsupported) { Util.Log("Skipping query index {0} because it is unsupported.", qryIdx); qryIdx++; continue; } Util.Log("Evaluating query index {0}. {1}", qryIdx, paramqrystr.Query); Query <object> query = qs.NewQuery <object>(paramqrystr.Query); //Populate the parameter list (paramList) for the query. object[] paramList = new object[QueryStatics.NoOfQueryParam[qryIdx]]; int numVal = 0; for (int ind = 0; ind < QueryStatics.NoOfQueryParam[qryIdx]; ind++) { //Util.Log("NIL::PQRS:: QueryStatics.QueryParamSet[{0},{1}] = {2}", qryIdx, ind, QueryStatics.QueryParamSet[qryIdx][ind]); try { numVal = Convert.ToInt32(QueryStatics.QueryParamSet[qryIdx][ind]); paramList[ind] = numVal; //Util.Log("NIL::PQRS::361 Interger Args:: paramList[0] = {1}", ind, paramList[ind]); } catch (FormatException) { //Console.WriteLine("Param string is not a sequence of digits."); paramList[ind] = (System.String)QueryStatics.QueryParamSet[qryIdx][ind]; //Util.Log("NIL::PQRS:: Interger Args:: routingObj[0] = {1}", ind, routingObj[ind].ToString()); } } ISelectResults <object> results = query.Execute(paramList); //Varify the result int expectedRowCount = qh.IsExpectedRowsConstantPQRS(qryIdx) ? QueryStatics.ResultSetPQRowCounts[qryIdx] : QueryStatics.ResultSetPQRowCounts[qryIdx] * qh.PortfolioNumSets; if (!qh.VerifyRS(results, expectedRowCount)) { ErrorOccurred = true; Util.Log("Query verify failed for query index {0}.", qryIdx); qryIdx++; continue; } ResultSet <object> rs = results as ResultSet <object>; foreach (object item in rs) { if (!m_isPdx) { Portfolio port = item as Portfolio; if (port == null) { Position pos = item as Position; if (pos == null) { string cs = item as string; if (cs == 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); } } else { PortfolioPdx port = item as PortfolioPdx; if (port == null) { PositionPdx pos = item as PositionPdx; if (pos == null) { string cs = item as string; if (cs == null) { Util.Log("Query got other/unknown object."); } else { Util.Log("Query got string : {0}.", cs); } } else { Util.Log("Query got PositionPdx object with secId {0}, shares {1}.", pos.secId, pos.getSharesOutstanding); } } else { Util.Log("Query got PortfolioPdx object with ID {0}, pkid {1}.", port.ID, port.Pkid); } } } qryIdx++; } Assert.IsFalse(ErrorOccurred, "One or more query validation errors occurred."); }
static void Main(string[] args) { try { CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(); Console.WriteLine("Connected to the Geode Distributed System"); // Create a Geode Cache with the "clientPdxRemoteQuery.xml" Cache XML file. Cache cache = cacheFactory.Set("cache-xml-file", "XMLs/clientPdxRemoteQuery.xml").Create(); Console.WriteLine("Created the Geode Cache"); // Get the example Region from the Cache which is declared in the Cache XML file. IRegion <string, PortfolioPdx> region = cache.GetRegion <string, PortfolioPdx>("Portfolios"); Console.WriteLine("Obtained the Region from the Cache"); // Register our Serializable/Cacheable Query objects, viz. Portfolio and Position. Serializable.RegisterPdxType(PortfolioPdx.CreateDeserializable); Serializable.RegisterPdxType(PositionPdx.CreateDeserializable); Console.WriteLine("Registered Serializable Query Objects"); // Populate the Region with some PortfolioPdx objects. PortfolioPdx port1 = new PortfolioPdx(1 /*ID*/, 10 /*size*/); PortfolioPdx port2 = new PortfolioPdx(2 /*ID*/, 20 /*size*/); PortfolioPdx port3 = new PortfolioPdx(3 /*ID*/, 30 /*size*/); region["Key1"] = port1; region["Key2"] = port2; region["Key3"] = port3; Console.WriteLine("Populated some PortfolioPdx Objects"); //find the pool Pool pool = PoolManager.Find("examplePool"); // Get the QueryService from the pool QueryService <string, PortfolioPdx> qrySvc = pool.GetQueryService <string, PortfolioPdx>(); Console.WriteLine("Got the QueryService from the Pool"); // Execute a Query which returns a ResultSet. Query <PortfolioPdx> qry = qrySvc.NewQuery("SELECT DISTINCT * FROM /Portfolios"); ISelectResults <PortfolioPdx> results = qry.Execute(); Console.WriteLine("ResultSet Query returned {0} rows", results.Size); // Execute a Query which returns a StructSet. QueryService <string, Struct> qrySvc1 = pool.GetQueryService <string, Struct>(); Query <Struct> qry1 = qrySvc1.NewQuery("SELECT DISTINCT id, status FROM /Portfolios WHERE id > 1"); ISelectResults <Struct> results1 = qry1.Execute(); Console.WriteLine("StructSet Query returned {0} rows", results1.Size); // Iterate through the rows of the query result. int rowCount = 0; foreach (Struct si in results1) { rowCount++; Console.WriteLine("Row {0} Column 1 is named {1}, value is {2}", rowCount, si.Set.GetFieldName(0), si[0].ToString()); Console.WriteLine("Row {0} Column 2 is named {1}, value is {2}", rowCount, si.Set.GetFieldName(1), si[1].ToString()); } // Execute a Region Shortcut Query (convenience method). results = region.Query <PortfolioPdx>("id = 2"); Console.WriteLine("Region Query returned {0} rows", results.Size); // Execute the Region selectValue() API. object result = region.SelectValue("id = 3"); Console.WriteLine("Region selectValue() returned an item:\n {0}", result.ToString()); // Execute the Region existsValue() API. bool existsValue = region.ExistsValue("id = 4"); Console.WriteLine("Region existsValue() returned {0}", existsValue ? "true" : "false"); // Close the Geode Cache. cache.Close(); Console.WriteLine("Closed the Geode Cache"); } // An exception should not occur catch (GeodeException gfex) { Console.WriteLine("PdxRemoteQuery Geode Exception: {0}", gfex.Message); } }