Patch requests in unit tests not reflected until Session is re-opened (Unit Test is included)

16 views
Skip to first unread message

Roman

unread,
Oct 25, 2016, 1:46:18 AM10/25/16
to RavenDB - 2nd generation document database

Doing a patch and then Loading the patched document loads the document that is not patched. Subsequently disposing and re-opening the session and loading the same document loads it with patched results.
See this unit test for details:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Raven.Tests.Helpers;
using Raven.Abstractions.Data;
using Raven.Json.Linq;

namespace BriefBox.UnitTest.RavenTests
{
    [TestClass]
    public class RavenDbGenericTests : RavenTestBase
    {
        public class TestEntity
        {
            public TestEntity()
            {
                Children = new TestEntity[0];
            }

            public string Id { get; set; }
            public string Value { get; set; }
            public TestEntity[] Children { get; set; }
        }

        [TestMethod]
        public void Test()
        {
            TestEntity testEntity;

            using (var store = NewDocumentStore(configureStore: ds=> ds.Configuration.Storage.Voron.AllowOn32Bits = true))
            {
                using (var session = store.OpenSession())
                {
                    testEntity = new TestEntity() { Value = "Roman1" };
                    session.Store(testEntity);
                    session.SaveChanges();

                    session.Advanced.DocumentStore.DatabaseCommands.Patch(testEntity.Id,
                        new PatchRequest[]
                        {
                            new PatchRequest()
                            {
                                 Name = "Children",
                                 Value = RavenJObject.FromObject(new TestEntity() { Value = "Added Child" }),
                                 Type = PatchCommandType.Add,
                            }
                        });

                    var result = session.Load<TestEntity>(testEntity.Id);
                    Assert.AreEqual(1, result.Children.Length); //BLOWS UP HERE
                }

                using (var session = store.OpenSession())
                {
                    var result = session.Load<TestEntity>(testEntity.Id);
                    Assert.AreEqual(1, result.Children.Length); //Does not fail if above is commented out
                }
            }
        }
    }
}

Thank you for your help

Oren Eini (Ayende Rahien)

unread,
Oct 25, 2016, 2:18:31 AM10/25/16
to ravendb
Yes, that is by design.
It isn't just for patch, it is for any change.

The session implements Unit of Work, and that means that the first time you load an entity, that is what you'll get for the duration of the session, to avoid concurrency issues inside the same session.

You can call session.Advanced.Evict() to force us to re-load the entity

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages