public void CanModifyTxId() { var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromDays(7) }; using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject(), transactionInformation)); var txInfo2 = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromDays(1) }; tx.Write(mutator => mutator.Transactions.ModifyTransactionId(transactionInformation.Id, txInfo2.Id, txInfo2.Timeout)); tx.Read(viewer => Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", txInfo2))); } }
public void CanHandleTruncatedFile() { var fileName = Path.Combine("test", "storage.raven"); long lengthAfterFirstTransaction; using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject())); lengthAfterFirstTransaction = new FileInfo(fileName).Length; tx.Write(mutator => mutator.Documents.AddDocument("Oren", null, JObject.FromObject(new { Name = "Eini" }), new JObject())); } using (var fileStream = File.Open(fileName, FileMode.Open))//simulate crash in the middle of a transaction write { fileStream.SetLength(lengthAfterFirstTransaction + (fileStream.Length - lengthAfterFirstTransaction) / 2); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", null))); tx.Read(viewer => Assert.Null(viewer.Documents.DocumentByKey("Oren", null))); } }
public void CanRecordAttemptsDecrements() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Indexing.AddIndex("def")); tx.Write(mutator => { mutator.Indexing.SetCurrentIndexStatsTo("def"); mutator.Indexing.IncrementIndexingAttempt(); mutator.Indexing.FlushIndexStats(); }); tx.Read(viewer => Assert.Equal(1, viewer.Indexing.GetFailureRate("def").Attempts)); tx.Write(mutator => { mutator.Indexing.SetCurrentIndexStatsTo("def"); mutator.Indexing.DecrementIndexingAttempt(); mutator.Indexing.FlushIndexStats(); }); tx.Read(viewer => Assert.Equal(0, viewer.Indexing.GetFailureRate("def").Attempts)); } }
public void AfterCommittingCanSeeChangesWithoutTx() { var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromDays(7) }; using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject(), transactionInformation)); tx.Write(mutator => mutator.Transactions.CompleteTransaction(transactionInformation.Id, data => { if (data.Delete) { JObject metadata; mutator.Documents.DeleteDocument(data.Key, null, out metadata); } else mutator.Documents.AddDocument(data.Key, null, data.Data, data.Metadata); })); tx.Read(viewer => Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", null))); } }
public void CanGetDocumentByUpdateOrder() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject()); mutator.Documents.AddDocument("Oren", null, JObject.FromObject(new { Name = "Eini" }), new JObject()); }); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => { Assert.Equal(2, viewer.Documents.GetDocumentsByReverseUpdateOrder(0).Count()); var tuples = viewer.Documents.GetDocumentsByReverseUpdateOrder(0).ToArray(); Assert.Equal(2, tuples.Length); Assert.Equal("Oren", tuples[0].Key); Assert.Equal("Ayende", tuples[1].Key); Assert.Equal(1, viewer.Documents.GetDocumentsByReverseUpdateOrder(1).Count()); tuples = viewer.Documents.GetDocumentsByReverseUpdateOrder(1).ToArray(); Assert.Equal("Ayende", tuples[0].Key); }); } }
public void CanAddAndReadIndexFailureRate() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Indexing.AddIndex("def")); tx.Read(viewer => Assert.Equal("def", viewer.Indexing.GetFailureRate("def").Name)); } }
public void CanCheckForExistanceOfTasks() { using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => Assert.False(viewer.Tasks.DoesTasksExistsForIndex("test", null))); tx.Write(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" })); tx.Read(viewer => Assert.True(viewer.Tasks.DoesTasksExistsForIndex("test", null))); } }
public void CanGetTask() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" })); int tasks; tx.Write(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask(out tasks))); } }
public void CanAddAndReadIndex() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Indexing.AddIndex("def")); tx.Read(viewer => Assert.True(viewer.Indexing.GetIndexesStats().Any(x => x.Name == "def"))); } }
public void CanStoreAndGetMappedResult() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.MappedResults.PutMappedResult("test", "users/ayende","ayende", JObject.FromObject(new { Name = "Rahien" }), null)); tx.Read(viewer => Assert.NotEmpty(viewer.MappedResults.GetMappedResults("test", "ayende", null))); } }
public void CanEnqueueAndPeek() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Queue.EnqueueToQueue("ayende", new byte[] {1, 2})); tx.Write( mutator => Assert.Equal(new byte[] {1, 2}, mutator.Queue.PeekFromQueue("ayende").First().Item1)); } }
public void AfterGettingTaskOnceWillNotGetItAgain() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" })); int tasks; tx.Write(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask(out tasks))); tx.Write(mutator => Assert.Null(mutator.Tasks.GetMergedTask(out tasks))); } }
public void CanHaveTwoResultsForSameDoc() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.MappedResults.PutMappedResult("test", "users/ayende", "ayende", JObject.FromObject(new { Name = "Rahien" }), null)); tx.Write(mutator => mutator.MappedResults.PutMappedResult("test", "users/ayende", "ayende", JObject.FromObject(new { Name = "Rahien" }), null)); tx.Read(viewer => Assert.Equal(2, viewer.MappedResults.GetMappedResults("test", "ayende", null).Count())); } }
public void CanCheckForExistanceOfTasksWithCutOffs() { using (var tx = new TransactionalStorage("test")) { var cutoff = DateTime.UtcNow; tx.Write(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" })); tx.Read(viewer => Assert.True(viewer.Tasks.DoesTasksExistsForIndex("test", null))); tx.Read(viewer => Assert.True(viewer.Tasks.DoesTasksExistsForIndex("test", cutoff.AddMinutes(1)))); tx.Read(viewer => Assert.False(viewer.Tasks.DoesTasksExistsForIndex("test", cutoff.AddMinutes(-1)))); } }
public void CanDeleteQueuedData() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Queue.EnqueueToQueue("ayende", new byte[] { 1, 2 })); tx.Write(mutator => { mutator.Queue.DeleteFromQueue("ayende", mutator.Queue.PeekFromQueue("ayende").First().Item2); Assert.Equal(null, mutator.Queue.PeekFromQueue("ayende").FirstOrDefault()); }); } }
public void CanDeleteAttachment() { using (var tx = new TransactionalStorage("test")) { tx.Write(accessor => accessor.Attachments.AddAttachment("Ayende", null, new byte[] { 1, 2, 3 }, new JObject())); tx.Write(accessor => accessor.Attachments.DeleteAttachment("Ayende", null)); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => Assert.Null(viewer.Attachments.GetAttachment("Ayende"))); } }
public void CanCheckForExistanceOfTasksAfterTaskWasRemoved() { using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => Assert.False(viewer.Tasks.DoesTasksExistsForIndex("test", null))); tx.Write(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" })); tx.Read(viewer => Assert.True(viewer.Tasks.DoesTasksExistsForIndex("test", null))); int tasks = 0; tx.Write(mutator => mutator.Tasks.GetMergedTask(out tasks)); Assert.Equal(1, tasks); tx.Read(viewer => Assert.False(viewer.Tasks.DoesTasksExistsForIndex("test", null))); } }
public void CanAddAndRead() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject())); JObject document = null; tx.Read(viewer => { document = viewer.Documents.DocumentByKey("Ayende", null).DataAsJson; }); Assert.Equal("Rahien", document.Value<string>("Name")); } }
public void CanAddAndReadAttachments() { using (var tx = new TransactionalStorage("test")) { tx.Write(accessor => accessor.Attachments.AddAttachment("Ayende", null, new byte[] { 1, 2, 3 }, new JObject())); Attachment attachment = null; tx.Read(viewer => { attachment = viewer.Attachments.GetAttachment("Ayende"); }); Assert.Equal(new byte[] { 1, 2, 3 }, attachment.Data); } }
public void CanStoreAndGetMappedResultWithSeveralResultsForSameReduceKey() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { mutator.MappedResults.PutMappedResult("test", "users/ayende", "ayende", JObject.FromObject(new {Name = "Rahien"}), null); mutator.MappedResults.PutMappedResult("test", "users/rahien", "ayende", JObject.FromObject(new { Name = "Rahien" }), null); }); tx.Read(viewer => Assert.Equal(2, viewer.MappedResults.GetMappedResults("test", "ayende", null).Count())); } }
public void CanDeleteFile() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject())); JObject metadata; tx.Write(mutator => mutator.Documents.DeleteDocument("Ayende", null, out metadata)); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => Assert.Null(viewer.Documents.DocumentByKey("Ayende", null))); } }
public void PoisonMessagesWillBeDeleted() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Queue.EnqueueToQueue("ayende", new byte[] {1, 2})); tx.Write(mutator => { for (int i = 0; i < 5; i++) { mutator.Queue.PeekFromQueue("ayende").First(); } Assert.Equal(null, mutator.Queue.PeekFromQueue("ayende").FirstOrDefault()); }); } }
public void AddingDocInTxCannotBeReadOutside() { var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromDays(7) }; using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject(), transactionInformation)); tx.Read(viewer => Assert.Null(viewer.Documents.DocumentByKey("Ayende", null))); } }
public void CanGetDocumentIds() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject()); mutator.Documents.AddDocument("Oren", null, JObject.FromObject(new { Name = "Eini" }), new JObject()); }); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => { var firstAndLastDocumentIds = viewer.Documents.FirstAndLastDocumentIds(); Assert.Equal(1, firstAndLastDocumentIds.Item1); Assert.Equal(2, firstAndLastDocumentIds.Item2); }); } }
public void CanGetDocumentByDocIds() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject()); mutator.Documents.AddDocument("Oren", null, JObject.FromObject(new { Name = "Eini" }), new JObject()); }); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => { var tuples = viewer.Documents.DocumentsById(1, 2).ToArray(); Assert.Equal(2, tuples.Length); Assert.Equal("Ayende", tuples[0].Item1.Key); Assert.Equal("Oren", tuples[1].Item1.Key); }); } }
public void CanGetDocumentByEtag() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject()); mutator.Documents.AddDocument("Oren", null, JObject.FromObject(new { Name = "Eini" }), new JObject()); }); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => { Assert.Equal(2, viewer.Documents.GetDocumentsAfter(Guid.Empty).Count()); var doc1 = viewer.Documents.DocumentByKey("Ayende", null); Assert.Equal(1, viewer.Documents.GetDocumentsAfter(doc1.Etag).Count()); }); } }
public void EtagsAreAlwaysIncreasing() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { mutator.Documents.AddDocument("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject()); mutator.Documents.AddDocument("Oren", null, JObject.FromObject(new { Name = "Eini" }), new JObject()); }); } using (var tx = new TransactionalStorage("test")) { tx.Read(viewer => { var doc1 = viewer.Documents.DocumentByKey("Ayende", null); var doc2 = viewer.Documents.DocumentByKey("Oren", null); Assert.Equal(1, doc2.Etag.CompareTo(doc1.Etag)); }); } }
public void CanGetNewIdentityValue() { using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => { Assert.Equal(1, mutator.General.GetNextIdentityValue("ayende")); Assert.Equal(1, mutator.General.GetNextIdentityValue("rahien")); Assert.Equal(2, mutator.General.GetNextIdentityValue("ayende")); Assert.Equal(2, mutator.General.GetNextIdentityValue("rahien")); }); tx.Write(mutator => { Assert.Equal(3, mutator.General.GetNextIdentityValue("ayende")); Assert.Equal(3, mutator.General.GetNextIdentityValue("rahien")); Assert.Equal(4, mutator.General.GetNextIdentityValue("ayende")); Assert.Equal(4, mutator.General.GetNextIdentityValue("rahien")); }); } }
public void CanGetTxIdValues() { using (var tx = new TransactionalStorage("test")) { var txId = Guid.NewGuid(); tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, new JObject(), new JObject(), new TransactionInformation { Id = txId, Timeout = TimeSpan.FromDays(7) })); tx.Read(viewer => Assert.Equal(new[] { txId }, viewer.Transactions.GetTransactionIds().ToArray())); } }
public void AfterRollbackCannotSeeChangesEvenInSameTxId() { var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromDays(7) }; using (var tx = new TransactionalStorage("test")) { tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject(), transactionInformation)); tx.Read(viewer => Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", transactionInformation))); tx.Write(mutator => mutator.Transactions.RollbackTransaction(transactionInformation.Id)); tx.Read(viewer => Assert.Null(viewer.Documents.DocumentByKey("Ayende", transactionInformation))); } }