public void TwoCursors() { using (var ds = makeDataStore()) { for (var i = 0; i < 10; i++) { var row = new TupleData { COUNTER = i, DATA = "Test" + i.ToString() }; ds.Insert(row); } ds.QueryResolver.ScriptAssembly = ASSEMBLY; var qry = new Query <TupleData>("CRUD.Tuple.LoadAll"); using (var cursor1 = ds.OpenCursor(qry)) using (var cursor2 = ds.OpenCursor(qry)) { Aver.IsFalse(cursor1.Disposed); Aver.IsFalse(cursor2.Disposed); var enumer1 = cursor1.GetEnumerator(); for (var j = 0; j < 3; j++) { enumer1.MoveNext(); } Aver.IsNotNull(enumer1.Current); Aver.AreEqual(2, enumer1.Current["COUNTER"].AsInt()); Aver.AreObjectsEqual("Test2", enumer1.Current["DATA"]); var enumer2 = cursor2.GetEnumerator(); Aver.IsNull(enumer2.Current); for (var j = 0; j < 6; j++) { enumer2.MoveNext(); } Aver.IsNotNull(enumer2.Current); Aver.AreEqual(5, enumer2.Current["COUNTER"].AsInt()); Aver.AreObjectsEqual("Test5", enumer2.Current["DATA"]); enumer1.MoveNext(); Aver.IsNotNull(enumer1.Current); Aver.AreEqual(3, enumer1.Current["COUNTER"].AsInt()); Aver.AreObjectsEqual("Test3", enumer1.Current["DATA"]); } } }
public static void Populate_ASYNC_OpenCursor(ICRUDDataStore store) { const int CNT = 1000; for (var i = 0; i < CNT; i++) { var patient = new TupleData { COUNTER = i, DATA = i.ToString() + "-DATA" }; store.Insert(patient); } var query = new Query <TupleData>("CRUD.Tuple.LoadAll"); var result = store.LoadOneRowset(query); Aver.AreEqual(CNT, result.Count); Aver.AreObjectsEqual(0, result[0]["COUNTER"].AsInt()); Aver.AreObjectsEqual(CNT - 1, result[result.Count - 1]["COUNTER"].AsInt()); var task = store.OpenCursorAsync(query) .ContinueWith(antecedent => { var cursor = antecedent.Result;; Aver.IsFalse(cursor.Disposed); var cnt = 0; foreach (var row in cursor.AsEnumerableOf <TupleData>()) { cnt++; } Aver.AreEqual(CNT, cnt); Aver.IsTrue(cursor.Disposed); //foreach must have closed the cursor }); task.Wait(); }
public static void Populate_OpenCursor(ICRUDDataStore store) { const int CNT = 1000; for (var i = 0; i < CNT; i++) { var patient = new TupleData { COUNTER = i, DATA = i.ToString() + "-DATA" }; store.Insert(patient); } var query = new Query <TupleData>("CRUD.Tuple.LoadAll"); var result = store.LoadOneRowset(query); Aver.AreEqual(CNT, result.Count); Aver.AreObjectsEqual(0, result[0]["COUNTER"].AsInt()); Aver.AreObjectsEqual(CNT - 1, result[result.Count - 1]["COUNTER"].AsInt()); { using (var cursor = store.OpenCursor(query)) { Aver.IsFalse(cursor.Disposed); var cnt = 0; foreach (var row in cursor.AsEnumerableOf <TupleData>()) { cnt++; } Aver.AreEqual(CNT, cnt); Aver.IsTrue(cursor.Disposed); //foreach must have closed the cursor } } { var cursor = store.OpenCursor(query); Aver.IsFalse(cursor.Disposed); var cen = cursor.GetEnumerator(); cen.MoveNext(); Aver.IsNotNull(cen.Current); Console.WriteLine(cen.Current.Schema.ToJSON(JSONWritingOptions.PrettyPrintRowsAsMap)); Aver.AreObjectsEqual(0, cen.Current["COUNTER"].AsInt()); Aver.AreObjectsEqual("0-DATA", cen.Current["DATA"]); cen.MoveNext(); Aver.IsNotNull(cen.Current); Aver.AreObjectsEqual(1, cen.Current["COUNTER"].AsInt()); Aver.AreObjectsEqual("1-DATA", cen.Current["DATA"]); cen.MoveNext(); Aver.IsNotNull(cen.Current); Aver.AreObjectsEqual(2, cen.Current["COUNTER"].AsInt()); Aver.AreObjectsEqual("2-DATA", cen.Current["DATA"]); cursor.Dispose(); Aver.IsTrue(cursor.Disposed); } { using (var cursor = store.OpenCursor(query)) { Aver.IsFalse(cursor.Disposed); var cnt = 0; foreach (var row in cursor.AsEnumerableOf <TupleData>()) { cnt++; } Aver.AreEqual(CNT, cnt); Aver.IsTrue(cursor.Disposed); //foreach must have closed the cursor try { foreach (var row in cursor.AsEnumerableOf <TupleData>()) { Aver.Fail("Must have failed"); } } catch { } } } { var cursor = store.OpenCursor(query); Aver.IsFalse(cursor.Disposed); var cen = cursor.GetEnumerator(); cen.MoveNext(); Aver.IsNotNull(cen.Current); Aver.AreObjectsEqual(0, cen.Current["COUNTER"].AsInt()); try { Aver.IsFalse(cursor.Disposed); var cen2 = cursor.GetEnumerator(); Aver.Fail("This should not have heppened as cant iterate cursor the second time"); } catch { } cursor.Dispose(); Aver.IsTrue(cursor.Disposed); } }