public void SQLite__Insert_Rows__InSingleTransaction_Stress() { // Prepare SignalRepository signalRepo = new SignalRepository(this.GetService <CacheContext>()); int countBefore = signalRepo.QueryAll.Count(); CancellationTokenSource tokenSource = new CancellationTokenSource(); int testSize = 100000; // Pre-validate // Perform List <Signal> signals = new List <Signal>(); List <object[]> rows = new List <object[]>(); for (int i = 0; i < testSize; i++) { signals.Add(Signal.New(deviceId: "fooDevice", data: Guid.NewGuid().ToString(), timestamp: DateTime.Now)); } Stopwatch sw = new Stopwatch(); sw.Start(); signalRepo.Add(signals); sw.Stop(); // Post-validate int countAfter = signalRepo.QueryAll.Count(); Assert.Equal(countBefore + testSize, countAfter); // signal inserted correctly double averageInsertSpeed = testSize / sw.Elapsed.TotalSeconds; Assert.True(averageInsertSpeed > 5000); }
public void SQLite_Delete_Rows_Created_Before_Date() { // Prepare SignalRepository signalRepo = new SignalRepository(this.GetService <CacheContext>()); int count = signalRepo.QueryAll.Count(); // Pre-validate signalRepo.Truncate(); Assert.Empty(signalRepo.QueryAll); DateTime border = DateTime.Now.AddMinutes(-1); string topGuid = Guid.NewGuid().ToString(); signalRepo.Add(new Signal[] { Signal.New(deviceId: "fooDevice", data: Guid.NewGuid().ToString(), timestamp: DateTime.Now.AddMinutes(-3)), Signal.New(deviceId: "fooDevice", data: Guid.NewGuid().ToString(), timestamp: DateTime.Now.AddMinutes(-2)), Signal.New(deviceId: "fooDevice", data: topGuid, timestamp: border) }); Assert.Equal(3, signalRepo.QueryAll.Count()); // Perform List <Signal> toDelete = signalRepo.QueryAll.Where(x => x.Timestamp < border).ToList(); signalRepo.Delete(toDelete); // Truncate(); // Post-validate Assert.Equal(1, signalRepo.QueryAll.Count()); Assert.Equal(topGuid, signalRepo.QueryAll.First().Data); }
public void SQLite__Truncate_Table() { // Prepare SignalRepository signalRepo = new SignalRepository(this.GetService <CacheContext>()); int count = signalRepo.QueryAll.Count(); if (count == 0) { signalRepo.Add(Signal.New(deviceId: "fooDevice", data: "foo", timestamp: DateTime.Now)); } // Pre-validate Assert.NotEmpty(signalRepo.QueryAll); // Perform signalRepo.Truncate(); // Post-validate Assert.Empty(signalRepo.QueryAll); //adapter.Disconnect(); }