/// <summary> /// Writes the scan query. /// </summary> private void WriteScanQuery(BinaryWriter writer, ScanQuery <TK, TV> qry) { Debug.Assert(qry != null); if (qry.Filter == null) { writer.WriteByte(BinaryUtils.HdrNull); } else { var holder = new CacheEntryFilterHolder(qry.Filter, (key, val) => qry.Filter.Invoke( new CacheEntry <TK, TV>((TK)key, (TV)val)), writer.Marshaller, _keepBinary); writer.WriteObject(holder); writer.WriteByte(FilterPlatformDotnet); } writer.WriteInt(qry.PageSize); writer.WriteInt(qry.Partition ?? -1); writer.WriteBoolean(qry.Local); }
/// <summary> /// Check scan query. /// </summary> /// <param name="loc">Local query flag.</param> /// <param name="keepBinary">Keep binary flag.</param> private static void CheckScanQuery <TV>(bool loc, bool keepBinary) { var cache = Cache(); int cnt = MaxItemCnt; // No predicate var exp = PopulateCache(cache, loc, cnt, x => true); var qry = new ScanQuery <int, TV>(); ValidateQueryResults(cache, qry, exp, keepBinary); // Serializable exp = PopulateCache(cache, loc, cnt, x => x < 50); qry = new ScanQuery <int, TV>(new ScanQueryFilter <TV>()); ValidateQueryResults(cache, qry, exp, keepBinary); // Binarizable exp = PopulateCache(cache, loc, cnt, x => x < 50); qry = new ScanQuery <int, TV>(new BinarizableScanQueryFilter <TV>()); ValidateQueryResults(cache, qry, exp, keepBinary); // Invalid exp = PopulateCache(cache, loc, cnt, x => x < 50); qry = new ScanQuery <int, TV>(new InvalidScanQueryFilter <TV>()); Assert.Throws <BinaryObjectException>(() => ValidateQueryResults(cache, qry, exp, keepBinary)); // Exception exp = PopulateCache(cache, loc, cnt, x => x < 50); qry = new ScanQuery <int, TV>(new ScanQueryFilter <TV> { ThrowErr = true }); var ex = Assert.Throws <IgniteException>(() => ValidateQueryResults(cache, qry, exp, keepBinary)); Assert.AreEqual(ScanQueryFilter <TV> .ErrMessage, ex.Message); }
public void TestScanQueryDisposedFromAnotherThreadThrowsObjectDisposedException() { var cache = GetIgnite().GetOrCreateCache <int, int>(TestUtils.TestName); const int totalCount = 10000; cache.PutAll(Enumerable.Range(1, totalCount).ToDictionary(x => x, x => x)); var scanQuery = new ScanQuery <int, int> { Filter = new ScanQueryFilter <int> { AcceptAll = true } }; var cursor = cache.Query(scanQuery); long count = 0; Task.Factory.StartNew(() => { // ReSharper disable once AccessToModifiedClosure while (Interlocked.Read(ref count) < totalCount / 10) { } cursor.Dispose(); }); Assert.Throws <ObjectDisposedException>(() => { foreach (var unused in cursor) { Interlocked.Increment(ref count); } }); }
public IQueryCursor <ICacheEntry <TK, TV> > Query(ScanQuery <TK, TV> scanQuery) { return(_cache.Query(scanQuery)); }
public void TestMultipleCursors() { var cache = GetPersonCache(); using (var client = GetClient()) { var clientCache = client.GetCache <int, Person>(CacheName); var qry = new ScanQuery <int, Person>(); var cur1 = clientCache.Query(qry).GetEnumerator(); var cur2 = clientCache.Query(qry).GetEnumerator(); var cur3 = clientCache.Query(qry).GetEnumerator(); // MaxCursors = 3 var ex = Assert.Throws <IgniteClientException>(() => clientCache.Query(qry)); Assert.AreEqual("Too many open cursors", ex.Message.Substring(0, 21)); #if !NETCOREAPP2_0 Assert.AreEqual((int)Impl.Client.ClientStatus.TooManyCursors, ex.ErrorCode); #endif var count = 0; while (cur1.MoveNext()) { count++; Assert.IsTrue(cur2.MoveNext()); Assert.IsTrue(cur3.MoveNext()); Assert.IsNotNull(cur1.Current); Assert.IsNotNull(cur2.Current); Assert.IsNotNull(cur3.Current); Assert.AreEqual(cur1.Current.Key, cur2.Current.Key); Assert.AreEqual(cur1.Current.Key, cur3.Current.Key); } Assert.AreEqual(cache.GetSize(), count); // Old cursors were auto-closed on last page, we can open new cursors now. var c1 = clientCache.Query(qry); var c2 = clientCache.Query(qry); var c3 = clientCache.Query(qry); Assert.Throws <IgniteClientException>(() => clientCache.Query(qry)); // Close one of the cursors. c1.Dispose(); c1 = clientCache.Query(qry); Assert.Throws <IgniteClientException>(() => clientCache.Query(qry)); // Close cursor via GetAll. c1.GetAll(); c1 = clientCache.Query(qry); Assert.Throws <IgniteClientException>(() => clientCache.Query(qry)); c1.Dispose(); c2.Dispose(); c3.Dispose(); } }
//load from cache private void button6_Click(object sender, EventArgs e) { try { List <Person> lstData = new List <Person>(); var ccfg = new CacheConfiguration { Name = "SCAN_DATA", CacheMode = CacheMode.Replicated }; var cfg = new IgniteConfiguration { BinaryConfiguration = new BinaryConfiguration(typeof(Person), typeof(PersonFilter)), }; Ignition.ClientMode = true; using (var ignite = Ignition.StartFromApplicationConfiguration("igniteConfiguration")) { ICache <int, Person> persons = ignite.GetOrCreateCache <int, Person>(ccfg); //getting single record-- working //lstData.Add(persons.Get(1)); //all record coming - working List <ICacheEntry <int, Person> > lst1 = persons.ToList <ICacheEntry <int, Person> >(); foreach (ICacheEntry <int, Person> p in lst1) { lstData.Add(new Person() { Age = p.Value.Age, Designation = p.Value.Designation, Id = p.Value.Id, Name = p.Value.Name, Salary = p.Value.Salary }); } dgCacheData.DataSource = lstData; lstData.Clear(); //filter records var scanQuery = new ScanQuery <int, Person>(new PersonFilter(Convert.ToInt32(txtAge.Text))); IQueryCursor <ICacheEntry <int, Person> > queryCursor = persons.Query(scanQuery); int j = 0; foreach (ICacheEntry <int, Person> p in queryCursor) { j++; lstData.Add(new Person() { Age = p.Value.Age, Designation = p.Value.Designation, Id = p.Value.Id, Name = p.Value.Name, Salary = p.Value.Salary }); } txtMsg.Text = j.ToString() + " records found"; } dgFilter.DataSource = lstData; } catch (Exception ex) { txtMsg.Text = ex.ToString(); } }