Inheritance: ITransactionalStorage
コード例 #1
0
ファイル: Transactions.cs プロジェクト: markrendle/ravendb
		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)));
			}
		}
コード例 #2
0
ファイル: Storage.cs プロジェクト: jlundstocholm/ravendb
		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)));
			}
		}
コード例 #3
0
ファイル: Indexes.cs プロジェクト: jlundstocholm/ravendb
		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));
			}
		}
コード例 #4
0
ファイル: Transactions.cs プロジェクト: markrendle/ravendb
		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)));
			}
		}
コード例 #5
0
ファイル: DocEtag.cs プロジェクト: jlundstocholm/ravendb
		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);
				});
			}
		}
コード例 #6
0
ファイル: Indexes.cs プロジェクト: jlundstocholm/ravendb
		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));
			}
		}
コード例 #7
0
ファイル: Tasks.cs プロジェクト: jlundstocholm/ravendb
		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)));
			}
		}
コード例 #8
0
ファイル: Tasks.cs プロジェクト: jlundstocholm/ravendb
		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)));
			}
		}
コード例 #9
0
ファイル: Indexes.cs プロジェクト: jlundstocholm/ravendb
		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")));
			}
		}
コード例 #10
0
		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)));
			}
		}
コード例 #11
0
ファイル: Queues.cs プロジェクト: jlundstocholm/ravendb
		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));
			}
		}
コード例 #12
0
ファイル: Tasks.cs プロジェクト: jlundstocholm/ravendb
		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)));
			}
		}
コード例 #13
0
		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()));
			}
		}
コード例 #14
0
ファイル: Tasks.cs プロジェクト: jlundstocholm/ravendb
		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))));
			}
		}
コード例 #15
0
ファイル: Queues.cs プロジェクト: jlundstocholm/ravendb
		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());
				});
			}
		}
コード例 #16
0
ファイル: Attachments.cs プロジェクト: jlundstocholm/ravendb
		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")));
			}
		}
コード例 #17
0
ファイル: Tasks.cs プロジェクト: jlundstocholm/ravendb
		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)));
			}
		}
コード例 #18
0
ファイル: Documents.cs プロジェクト: jlundstocholm/ravendb
		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"));
			}
		}
コード例 #19
0
ファイル: Attachments.cs プロジェクト: jlundstocholm/ravendb
		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);
			}
		}
コード例 #20
0
		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()));
			}
		}
コード例 #21
0
ファイル: Documents.cs プロジェクト: jlundstocholm/ravendb
		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)));

			}
		}
コード例 #22
0
ファイル: Queues.cs プロジェクト: jlundstocholm/ravendb
		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());
				});
			}
		}
コード例 #23
0
ファイル: Transactions.cs プロジェクト: markrendle/ravendb
		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)));
			}
		}
コード例 #24
0
ファイル: DocumentIds.cs プロジェクト: markrendle/ravendb
		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);
				});
			}
		}
コード例 #25
0
ファイル: DocumentIds.cs プロジェクト: markrendle/ravendb
		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);
				});
			}
		}
コード例 #26
0
ファイル: DocEtag.cs プロジェクト: jlundstocholm/ravendb
		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());
				});
			}
		}
コード例 #27
0
ファイル: DocEtag.cs プロジェクト: jlundstocholm/ravendb
		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));

				});
			}

		}
コード例 #28
0
ファイル: General.cs プロジェクト: jlundstocholm/ravendb
		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"));
				});
			}
		}
コード例 #29
0
ファイル: Transactions.cs プロジェクト: markrendle/ravendb
		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()));
			}
		}
コード例 #30
0
ファイル: Transactions.cs プロジェクト: markrendle/ravendb
		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)));
			
			}
		}