public void TEST_no_caching() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(5); for (int i = 0; i < 100; i++) { StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); History.LoadAll(true).ToList().ForEach( x => { History.Delete(x.Id); History.DeleteForever(x.Id); }); IEnumerable <Finance <object> > allx = fin.LoadAll(true); Finance <object> data = fin.Create(new Finance <object>()); IEnumerable <Finance <object> > allk = fin.LoadAll(true); IEnumerable <Finance <object> > allhhjjw = fin.LoadAll(true); data.FileContent = "bla"; IEnumerable <Finance <object> > allhhw = fin.LoadAll(true); fin.Update(data); IEnumerable <Finance <object> > allw = fin.LoadAll(true); History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id); data = fin.Load(data.Id); IEnumerable <Finance <object> > ally = fin.LoadAll(true); TestHelperMethods.AssertAwait( () => { IEnumerable <Finance <object> > all = fin.LoadAll(true); Assert.AreEqual(1, all.Count()); }); fin.Delete(data.Id); h = History.Load(History.LoadAll(true).Last().Id); DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); fin.DeleteForever(data.Id); h = History.Load(History.LoadAll(true).LastOrDefault().Id); stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); } }
public void dynamic_test() { new List <bool> { true, false }.ForEach( cache => { var store = new PecanDocumentStore("PecanDBTest", new DatabaseOptions(cache)); ISession session = store.OpenSession(); foreach (int i1 in Enumerable.Range(0, 10)) { string orderId = session.Save( new { Id = "yo be", Name = i1 }); string orderId2 = session.Save( new object()); dynamic order = null; TestHelperMethods.AssertAwait( () => { order = session.Load <dynamic>(orderId); Assert.AreEqual(order.Name.ToString(), i1.ToString()); Order oo = session.LoadAs <dynamic, Order>(orderId); Assert.AreEqual(oo.Name, i1.ToString()); Order oo2 = session.LoadAs <dynamic, Order>(orderId2); var oo3 = session.LoadAs <Order>(orderId2); dynamic oo4 = session.Load(orderId2); }); order.Name = "sam"; session.SaveChanges(true); var o = session.Load <object>(orderId); dynamic order2 = o; Assert.AreEqual(order2.Name.ToString(), "sam"); order2.Name = "sowhat"; Assert.AreEqual(order2.Name.ToString(), order.Name.ToString()); List <dynamic> result = session.Query <object>(all => from every in all select every).ToList(); } }); }
public void load_test_with_nocaching() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(3); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach(x => fin.DeleteForever(x.Id)); History.LoadAll(true).ToList().ForEach(x => History.DeleteForever(x.Id)); int count = 1000; for (int i = 0; i < count; i++) { fin.Create(new Finance <object>()); } fin.Create(new Finance <object>(), true); TestHelperMethods.AssertAwait( () => { int ttt = fin.LoadAll(true).Count(); Assert.AreEqual(count + 1, ttt); }); List <Finance <object> > x1 = fin.LoadAll(true).Take(10).ToList(); List <Finance <object> > x2 = fin.LoadAll(true).Take(1000).ToList(); List <Finance <object> > x3 = fin.LoadAll(true).Take(1000).ToList(); IEnumerable <Finance <object> > tester = fin.LoadAll( finances => from finance in finances where finance.ETag != null select finance); fin.LoadAll(true).ToList().ForEach(x => fin.DeleteForever(x.Id)); History.LoadAll(true).ToList().ForEach(x => History.DeleteForever(x.Id)); //(3000); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); }
public void TEST_with_caching_inmemory() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); for (int i = 0; i < 100; i++) { DatabaseService.DataBaseSettings.EnableFasterCachingButWithLeakyUpdates = true; StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); History.LoadAll(true).ToList().ForEach( x => { History.Delete(x.Id); History.DeleteForever(x.Id); }); Finance <object> data = fin.Create(new Finance <object>()); data.FileContent = "bla"; fin.Update(data); History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id); data = fin.Load(data.Id); TestHelperMethods.AssertAwait(() => Assert.AreEqual(1, fin.LoadAll(true).Count())); fin.Delete(data.Id); h = History.Load(History.LoadAll(true).Last().Id); DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); fin.DeleteForever(data.Id); h = History.Load(History.LoadAll(true).LastOrDefault().Id); stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); } }
public void transaction() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(10); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); int total = 100; Task.Run( () => { DatabaseService.Transaction( handle => { for (int i = 0; i < total; i++) { Finance <object> ti = handle.GetDBRef <Finance <object>, object>().Create(new Finance <object>()); } return(true); }); }); IEnumerable <Finance <object> > t = fin.LoadAll(true); TestHelperMethods.AssertAwait(1000); fin.Create(new Finance <object>()); //(3000); Assert.AreEqual(total + 1, fin.LoadAll(true).Count()); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); Assert.AreEqual(0, fin.LoadAll(true).Count()); Task task = Task.Run( () => { for (int i = 0; i < total; i++) { Finance <object> ti = fin.Create(new Finance <object>()); } }); IEnumerable <Finance <object> > ttt = fin.LoadAll(true); TestHelperMethods.AssertAwait(1000); fin.Create(new Finance <object>()); // Assert.AreNotEqual(total + 1, fin.LoadAll(true).Count()); task.Wait(); //(3000); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); Assert.AreEqual(0, fin.LoadAll(true).Count()); StorageDatabase <History <object>, object> his = DatabaseService.Documents <History <object>, object>(); his.LoadAll(true).ToList().ForEach( x => { his.Delete(x.Id); his.DeleteForever(x.Id); }); }
public void test_saving_into_different_directories_with_query_document() { dynamic data1 = new { Data = Guid.NewGuid().ToString() }; dynamic data2 = new { Data = Guid.NewGuid().ToString() }; dynamic data3 = new { Data = Guid.NewGuid().ToString() }; string t1 = "t1t1t1"; string t2 = "t2t2t2"; using (var store = new DocumentStoreInMemory( new DatabaseOptions { //MaxResponseTime = TimeSpan.FromMinutes(3), // EnableCaching = false })) { //using (ISession session = store.OpenSession()) //{ // foreach (PecanDocument<dynamic> order in session.QueryDocument<dynamic>(orders => from order in orders select order)) // session.DeleteForever<dynamic>(order.Id); // foreach (PecanDocument<dynamic> order in session.QueryDocument<dynamic>(orders => from order in orders select order,t1)) // session.DeleteForever<dynamic>(order.Id); // foreach (PecanDocument<dynamic> order in session.QueryDocument<dynamic>(orders => from order in orders select order,t2)) // session.DeleteForever<dynamic>(order.Id); //} string h1; using (ISession session = store.OpenSession()) { h1 = session.Save(data1); } string h2; using (ISession session = store.OpenSession()) { h2 = session.Save(t1, data2); } string h3; using (ISession session = store.OpenSession()) { h3 = session.Save(t2, data3); } using (ISession session = store.OpenSession()) { TestHelperMethods.AssertAwait( () => { var h1data = session.Load <dynamic>(h1); var list1 = session.QueryDocument <dynamic>((docs) => docs.Select(doc => doc)).Select(x => JsonConvert.SerializeObject(x)).ToList(); Assert.AreEqual(data1.Data.ToString(), h1data.Data.ToString()); Assert.AreEqual(list1.Count, 1); }); } using (ISession session = store.OpenSession()) { TestHelperMethods.AssertAwait( () => { var h2data = session.Load <dynamic>(h2, t1); var list2 = session.QueryDocument <dynamic>((docs) => docs.Select(doc => doc), t1).Select(x => JsonConvert.SerializeObject(x)).ToList(); Assert.AreEqual(data2.Data.ToString(), h2data.Data.ToString()); Assert.AreEqual(list2.Count, 1); }); } using (ISession session = store.OpenSession()) { TestHelperMethods.AssertAwait( () => { var h3data = session.Load <dynamic>(h3, t2); var list3 = session.QueryDocument <dynamic>((docs) => docs.Select(doc => doc), t2).Select(x => JsonConvert.SerializeObject(x)).ToList(); Assert.AreEqual(data3.Data.ToString(), h3data.Data.ToString()); Assert.AreEqual(list3.Count, 1); }); } } }
public void RunPerformanceTest <T>(bool isParallel, string description, Func <int, ISession, Action> opearation) { new List <bool> { true, false }.ForEach( dontWaitForWritesOnCreate => { for (int j = 0; j < this.numberOfSamples; j++) { var store = new PecanDocumentStore( "PecanDB", false, new DatabaseOptions { EnableCaching = false, DontWaitForWritesOnCreate = dontWaitForWritesOnCreate }); ISession session = store.OpenSession(); try { foreach (PecanDocument <T> order in session.QueryDocument <T>(orders => from order in orders select order)) { session.DeleteForever <T>(order.Id); } } catch (Exception e) { } // Create new stopwatch var stopwatch = new Stopwatch(); var validationOperations = new ConcurrentQueue <Action>(); // Begin timing stopwatch.Start(); if (isParallel) { Parallel.For(1, this.total, i => validationOperations.Enqueue(opearation(i, session))); } else { foreach (int i in Enumerable.Range(0, this.total)) { validationOperations.Enqueue(opearation(i, session)); } } // Stop timing stopwatch.Stop(); Console.Write($"{j} {(dontWaitForWritesOnCreate ? "" : "DONT WAIT FOR CREATE")} - Time elapsed: {stopwatch.Elapsed.TotalMilliseconds}ms : {description} with {this.total} iteration - RATE {this.total / (stopwatch.Elapsed.TotalMilliseconds / 1000)} op/sec"); var validationStopwatch = new Stopwatch(); validationStopwatch.Start(); Action validationOperation; while (validationOperations.TryDequeue(out validationOperation)) { if (validationOperation != null) { TestHelperMethods.AssertAwait(validationOperation); } } validationStopwatch.Stop(); Console.WriteLine($"VALIDATION TIMING elapsed: {validationStopwatch.Elapsed.TotalMilliseconds}ms "); try { foreach (PecanDocument <T> order in session.QueryDocument <T>(orders => from order in orders select order)) { session.DeleteForever <T>(order.Id); } } catch (Exception) { } } }); }
public void dynamic_document_test() { var store = new PecanDocumentStore("PecanDBTest", new DatabaseOptions(true)); ISession session = store.OpenSession(); string orderId1 = session.Save( "doc1", new { Id = "yo be", Name = "doc1" }); string orderId2 = session.Save( "doc2", new { Id = "yo be", Name = "doc2" }); TestHelperMethods.AssertAwait( () => { var order1 = session.Load <dynamic>(orderId1, "doc1"); Assert.AreEqual(order1.Name.ToString(), "doc1"); var order2 = session.Load <dynamic>(orderId2, "doc2"); Assert.AreEqual(order2.Name.ToString(), "doc2"); dynamic order11 = session.Load(orderId1, "doc1"); Assert.AreEqual(order11.Name.ToString(), "doc1"); dynamic order22 = session.Load(orderId2, "doc2"); Assert.AreEqual(order22.Name.ToString(), "doc2"); try { var order5 = session.Load <dynamic>(orderId1); Assert.Fail(); } catch (Exception e) { } try { var order6 = session.Load <dynamic>(orderId2); Assert.Fail(); } catch (Exception e) { } try { dynamic order7 = session.Load(orderId1); Assert.Fail(); } catch (Exception e) { } try { dynamic order8 = session.Load(orderId2); Assert.Fail(); } catch (Exception e) { } try { var order3 = session.Load <dynamic>(orderId1, "doc2"); Assert.Fail(); } catch (Exception e) { } try { var order4 = session.Load <dynamic>(orderId2, "doc1"); Assert.Fail(); } catch (Exception e) { } } ); }