public void Can_promote_transactions()
		{
			var process = Process.Start(GetRavenServerPath(), "--ram --set=Raven/Port==8079");
			try
			{
				WaitForNetwork("http://localhost:8079");

				var documentStore = new DocumentStore { Url = "http://localhost:8079" };
				documentStore.Initialize();

				var company = new Company { Name = "Company Name" };
				var durableEnlistment = new ManyDocumentsViaDTC.DummyEnlistmentNotification();
				using (var tx = new TransactionScope())
				{
					var session = documentStore.OpenSession();
					session.Store(company);
					session.SaveChanges();

					Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);

					Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
													  durableEnlistment, EnlistmentOptions.None);

					Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);


					tx.Complete();
				}


				for (int i = 0; i < 15; i++)// wait for commit
				{
					using (var session2 = documentStore.OpenSession())
						if (session2.Load<Company>(company.Id) != null)
							break;
					Thread.Sleep(100);
				}
				using (var session2 = documentStore.OpenSession())
					Assert.NotNull((session2.Load<Company>(company.Id)));

				for (int i = 0; i < 15; i++) // we have to wait to be notified, too
				{
					if(durableEnlistment.WasCommitted == false)
						Thread.Sleep(100);
				}

				Assert.True(durableEnlistment.WasCommitted);

			}
			finally
			{
				process.Kill();
			}
		}
		public void Can_promote_transactions()
		{
			using (var driver = new RavenDBDriver("HelloShard", new DocumentConvention()))
			{
				driver.Start();

				WaitForNetwork(driver.Url);

				using (var documentStore = new DocumentStore { Url = driver.Url  }.Initialize())
				{
					var company = new Company {Name = "Company Name"};
					var durableEnlistment = new ManyDocumentsViaDTC.DummyEnlistmentNotification();
					using (var tx = new TransactionScope())
					{
						var session = documentStore.OpenSession();
						session.Store(company);
						session.SaveChanges();

						Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);

						Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
						                                  durableEnlistment, EnlistmentOptions.None);

						Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);


						tx.Complete();
					}


					for (int i = 0; i < 15; i++) // wait for commit
					{
						using (var session2 = documentStore.OpenSession())
							if (session2.Load<Company>(company.Id) != null)
								break;
						Thread.Sleep(100);
					}
					using (var session2 = documentStore.OpenSession())
						Assert.NotNull((session2.Load<Company>(company.Id)));

					for (int i = 0; i < 15; i++) // we have to wait to be notified, too
					{
						if (durableEnlistment.WasCommitted == false)
							Thread.Sleep(100);
					}

					Assert.True(durableEnlistment.WasCommitted);
				}
			}
		}
Example #3
0
        public void DocumentsNotCommitedIfTransactionIsPromotedToDistributedTx()
        {
            using (var documentStore = NewRemoteDocumentStore())
            {
                var enlistment = new ManyDocumentsViaDTC.DummyEnlistmentNotification();
                using (var tx = new TransactionScope())
                {
                    using (var session = documentStore.OpenSession())
                    {
                        session.Store(new TestObject { Value = 1 });
                        session.SaveChanges();
                    }

                    Transaction.Current.EnlistDurable(Guid.NewGuid(), enlistment, EnlistmentOptions.None);
                    tx.Complete();
                }

                using (var session = documentStore.OpenSession())
                {
                    session.Advanced.AllowNonAuthoritativeInformation = false;
                    Assert.NotNull(session.Load<TestObject>(1));
                }
            }
        }