コード例 #1
0
        public void can_use_RavenDB_in_a_remote_process_for_batch_operations()
        {
            var documentConvention = new DocumentConvention();

            using (var driver = new RavenDBDriver("HelloShard", documentConvention))
            {
                driver.Start();

                using (var store = new DocumentStore
                {
                    Url = driver.Url,
                    Conventions = documentConvention
                })
                {
                    store.Initialize();

                    using (var session = store.OpenSession())
                    {
                        store.DatabaseCommands.Batch(new[] { GetPutCommand() });
                        session.SaveChanges();
                    }
                }

                using (var store = driver.GetDocumentStore())
                {
                    should_find_expected_value_in(store);
                }
            }
        }
コード例 #2
0
        public void can_use_RavenDB_in_a_remote_process()
        {
            var documentConvention = new DocumentConvention();

            using (var driver = new RavenDBDriver("HelloShard", documentConvention))
            {
                driver.Start();

                using (var store = new DocumentStore
                {
                    Url = driver.Url,
                    Conventions = documentConvention
                })
                {
                    store.Initialize();

                    using (var session = store.OpenSession())
                    {
                        session.Store(new Tuple <string, string>("hello", "world"));
                        session.SaveChanges();
                    }
                }

                using (var store = driver.GetDocumentStore())
                {
                    should_find_expected_value_in(store);
                }
            }
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
        public void can_use_RavenDB_in_a_remote_process_to_post_batch_operations()
        {
            var documentConvention = new DocumentConvention();

            using (var driver = new RavenDBDriver("HelloShard", documentConvention))
            {
                driver.Start();

                var httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(new Uri(driver.Url), "bulk_docs"));
                httpWebRequest.Method = "POST";
                using (var requestStream = new StreamWriter(httpWebRequest.GetRequestStream(), Encoding.UTF8))
                {
                    requestStream.Write("[");

                    requestStream.Write(GetPutCommand().ToJson().ToString());

                    requestStream.Write("]");
                }

                HttpWebResponse webResponse;

                try
                {
                    webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    webResponse.Close();
                }
                catch (WebException e)
                {
                    driver.Should_finish_without_error();
                    driver.TraceExistingOutput();

                    Console.WriteLine(new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
                    throw;
                }

                using (var store = driver.GetDocumentStore())
                {
                    should_find_expected_value_in(store);
                }
            }
        }