public void PrefetchViaReferenceToSelfTest() { Key key; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var referenceToSelf = new ReferenceToSelf { AuxField = 100 }; key = referenceToSelf.Key; referenceToSelf.Reference = referenceToSelf; tx.Complete(); } using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); var referenceField = Domain.Model.Types[typeof(ReferenceToSelf)].Fields["Reference"]; prefetchManager.InvokePrefetch(key, null, new PrefetchFieldDescriptor(referenceField, true, true)); prefetchManager.ExecuteTasks(true); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, key.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); PrefetchTestHelper.AssertReferencedEntityIsLoaded(key, session, referenceField); } }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); CustomerType = Domain.Model.Types[typeof(Customer)]; OrderType = Domain.Model.Types[typeof(Order)]; ProductType = Domain.Model.Types[typeof(Product)]; BookType = Domain.Model.Types[typeof(Book)]; TitleType = Domain.Model.Types[typeof(Title)]; ITitleType = Domain.Model.Types[typeof(ITitle)]; OfferContainerType = Domain.Model.Types[typeof(OfferContainer)]; PersonIdField = Domain.Model.Types[typeof(Person)].Fields["Id"]; OrderIdField = Domain.Model.Types[typeof(Order)].Fields["Id"]; CityField = CustomerType.Fields["City"]; AgeField = Domain.Model.Types[typeof(AdvancedPerson)].Fields["Age"]; CustomerField = OrderType.Fields["Customer"]; EmployeeField = OrderType.Fields["Employee"]; DetailsField = OrderType.Fields["Details"]; BooksField = Domain.Model.Types[typeof(Author)].Fields["Books"]; BookTitleField = BookType.Fields["Title"]; TitleBookField = TitleType.Fields["Book"]; LanguageField = TitleType.Fields["Language"]; TextField = TitleType.Fields["Text"]; GraphContainersField = typeof(PrefetchManager).GetField("graphContainers", BindingFlags.NonPublic | BindingFlags.Instance); PrefetchProcessorField = typeof(SqlSessionHandler).GetField("prefetchManager", BindingFlags.NonPublic | BindingFlags.Instance); PrefetchTestHelper.FillDataBase(Domain); }
public async Task PrefetchManySeveralBatchesAsyncTest() { using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var linesField = Domain.Model.Types[typeof(Invoice)].Fields["InvoiceLines"]; var trackField = Domain.Model.Types[typeof(InvoiceLine)].Fields["Track"]; var invoices = session.Query.All <Invoice>() .Take(90) .Prefetch(o => o.InvoiceLines.Prefetch(od => od.Track)).AsAsync(); int count1 = 0, count2 = 0; foreach (var invoice in await invoices) { count1++; var entitySetState = GetFullyLoadedEntitySet(session, invoice.Key, linesField); foreach (var line in entitySetState) { count2++; PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(line, line.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); PrefetchTestHelper.AssertReferencedEntityIsLoaded(line, session, trackField); } } Console.WriteLine(count1); Console.WriteLine(count2); Assert.AreEqual(11, session.Handler.PrefetchTaskExecutionCount); } }
public void NotFullPrefetchBatchTest() { var keys = GetKeys <Person>(120); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var count = 0; var enumerable = keys.Take(15); session.Query.Many <AdvancedPerson>(enumerable).Run(); foreach (var key in enumerable) { count++; var cachedKey = GetCachedKey(key, session); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(cachedKey, cachedKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } Assert.AreEqual(15, count); var prefetchCount = session.Handler.PrefetchTaskExecutionCount; session.Query.Many <AdvancedPerson>(keys).Run(); count = 0; foreach (var key in keys) { count++; var cachedKey = GetCachedKey(key, session); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(cachedKey, cachedKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } Assert.AreEqual(keys.Count, count); Assert.AreEqual(prefetchCount + 4, session.Handler.PrefetchTaskExecutionCount); } }
public void NotificationAboutUnknownForeignKeyWhenItsEntityHasBeenLoadedInAnotherTransactionTest() { Key book0Key; Key title0Key; Key book1Key; Key title1Key; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { CreateBookAndTitleInExistingSession(out title0Key, out book0Key); CreateBookAndTitleInExistingSession(out title1Key, out book1Key); tx.Complete(); } using (var session = Domain.OpenSession()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); using (var tx = session.OpenTransaction()) { prefetchManager.InvokePrefetch(title0Key, null, new PrefetchFieldDescriptor(title0Key.TypeInfo.Fields["Id"])); prefetchManager.InvokePrefetch(book1Key, null, new PrefetchFieldDescriptor(book1Key.TypeInfo.Fields["Id"])); prefetchManager.InvokePrefetch(title1Key, null, new PrefetchFieldDescriptor(title1Key.TypeInfo.Fields["Id"])); prefetchManager.ExecuteTasks(true); } using (var tx = session.OpenTransaction()) { prefetchManager.InvokePrefetch(book0Key, null, new PrefetchFieldDescriptor(BookTitleField, null, true, true, (ownerKey, field, key) => Assert.Fail())); prefetchManager.InvokePrefetch(book1Key, null, new PrefetchFieldDescriptor(BookTitleField, null, true, true, (ownerKey, field, key) => Assert.Fail())); prefetchManager.ExecuteTasks(true); PrefetchTestHelper.AssertOnlyDefaultColumnsAreLoaded(title0Key, ITitleType, session); } } }
public void ReferenceToSelfPrefetchTest() { TypeInfo referenceToSelfType; var keys = new List <Key>(); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { referenceToSelfType = Domain.Model.Types[typeof(ReferenceToSelf)]; var reference = new ReferenceToSelf { AuxField = 3 }; keys.Add(reference.Key); reference.Reference = reference; reference = new ReferenceToSelf { AuxField = 5 }; keys.Add(Key.Create(Domain, typeof(IReferenceToSelf), reference.Key.Value)); reference.Reference = reference; tx.Complete(); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { session.Query.Many <IReferenceToSelf>(keys) .Prefetch(r => r.Reference) .Run(); foreach (var key in keys) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, referenceToSelfType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } }
public void TasksAreExecutedAutomaticallyWhenCountLimitIsReachedTest() { const int entityCount = 120; var keys = new List <Key>(entityCount); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { for (int i = 0; i < entityCount; i++) { keys.Add(new Book().Key); } tx.Complete(); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); var graphContainers = (SetSlim <GraphContainer>)GraphContainersField.GetValue(prefetchManager); var idField = BookType.Fields["Id"]; for (var i = 1; i < keys.Count; i++) { prefetchManager.InvokePrefetch(keys[i - 1], null, new PrefetchFieldDescriptor(idField)); Assert.AreEqual(i % entityCount, graphContainers.Count); } prefetchManager.InvokePrefetch(keys[entityCount - 1], null, new PrefetchFieldDescriptor(idField)); Assert.AreEqual(0, graphContainers.Count); for (var i = 0; i < entityCount; i++) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(keys[i], BookType, session, IsFieldKeyOrSystem); } } }
public async Task EnumerableOfNonEntityAsyncTest() { List <Key> keys; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { keys = session.Query.All <Invoice>().Select(i => i.Key).ToList(); Assert.Greater(keys.Count, 0); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var invoices = session.Query.Many <Invoice>(keys) .Prefetch(o => o.DesignatedEmployee).AsAsync(); var orderType = Domain.Model.Types[typeof(Invoice)]; var employeeField = orderType.Fields["DesignatedEmployee"]; var employeeType = Domain.Model.Types[typeof(Employee)]; Func <FieldInfo, bool> fieldSelector = field => field.IsPrimaryKey || field.IsSystem || !field.IsLazyLoad && !field.IsEntitySet; foreach (var invoice in await invoices) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(invoice.Key, invoice.Key.TypeInfo, session, fieldSelector); var invoiceState = session.EntityStateCache[invoice.Key, true]; var employeeKey = Key.Create(Domain, WellKnown.DefaultNodeId, Domain.Model.Types[typeof(Employee)], TypeReferenceAccuracy.ExactType, employeeField.Associations.Last() .ExtractForeignKey(invoiceState.Type, invoiceState.Tuple)); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employeeKey, employeeType, session, fieldSelector); } } }
public async Task NestedPrefetchWhenChildElementIsNullAsyncTest() { RemoveAllBooks(); using (var session = Domain.OpenSession()) { using (var tx = session.OpenTransaction()) { var book0 = new Model.Book { Title = new Model.Title { Text = "T0" }, Category = "1" }; var book1 = new Model.Book { Category = "2" }; tx.Complete(); } using (var tx = session.OpenTransaction()) { var prefetcher = session.Query.All <Model.Book>() .Prefetch(b => b.Title.Book).AsAsync(); var titleField = Domain.Model.Types[typeof(Model.Book)].Fields["Title"]; var titleType = Domain.Model.Types[typeof(Model.Title)]; foreach (var book in await prefetcher) { var titleKey = book.GetReferenceKey(titleField); if (titleKey != null) { PrefetchTestHelper.AssertOnlyDefaultColumnsAreLoaded(titleKey, titleType, session); } } } } }
public void SimpleTest() { List <Key> keys; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { keys = session.Query.All <Person>().AsEnumerable().Select(p => Key.Create <Person>(Domain, p.Key.Value)).ToList(); Assert.IsTrue(keys.All(key => !key.HasExactType)); Assert.Greater(keys.Count, 0); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var persons = session.Query.Many <Person>(keys); var count = 0; foreach (var person in persons) { count++; Key cachedKey; Assert.IsTrue(Domain.KeyCache.TryGetItem(person.Key, true, out cachedKey)); Assert.IsTrue(cachedKey.HasExactType); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(person.Key, cachedKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } Assert.AreEqual(keys.Count, count); } }
public async Task NestedPrefetchWhenRootElementIsNullAsyncTest() { RemoveAllBooks(); using (var session = Domain.OpenSession()) { using (var tx = session.OpenTransaction()) { var book = new Model.Book { Title = new Model.Title { Text = "T0" }, Category = "1" }; tx.Complete(); } using (var tx = session.OpenTransaction()) { var books = session.Query.All <Model.Book>().AsEnumerable().Concat(EnumerableUtils.One <Model.Book>(null)) .Prefetch(b => b.Title.Book).AsAsync(); var titleField = Domain.Model.Types[typeof(Model.Book)].Fields["Title"]; var titleType = Domain.Model.Types[typeof(Model.Title)]; var count = 0; foreach (var book in await books) { count++; if (book != null) { var titleKey = book.GetReferenceKey(titleField); if (titleKey != null) { PrefetchTestHelper.AssertOnlyDefaultColumnsAreLoaded(titleKey, titleType, session); } } } Assert.AreEqual(2, count); } } }
public void SimpleTest() { List <Key> keys; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { keys = session.Query.All <Order>().Select(p => p.Key).ToList(); Assert.Greater(keys.Count, 0); } using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { var orders = session.Query.Many <Order>(keys) .Prefetch(o => o.Employee); var orderType = Domain.Model.Types[typeof(Order)]; var employeeType = Domain.Model.Types[typeof(Employee)]; var employeeField = orderType.Fields["Employee"]; foreach (var order in orders) { GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); var orderState = session.EntityStateCache[order.Key, true]; PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(order.Key, orderType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); var employeeKey = Key.Create <Person>(Domain, employeeField.Associations.Last() .ExtractForeignKey(orderState.Type, orderState.Tuple)); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employeeKey, employeeType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } }
private void TestFullLoadingOfReferencedEntities(IEnumerable <Key> keys) { using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { session.Query.Many <Book>(keys) .Prefetch(b => b.Title) .Run(); var bookType = Domain.Model.Types[typeof(Book)]; var titleField = bookType.Fields["Title"]; var titleType = Domain.Model.Types[typeof(Title)]; foreach (var key in keys) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, bookType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); var ownerState = session.EntityStateCache[key, true]; var titleKeyValue = titleField.Associations.Last().ExtractForeignKey(ownerState.Type, ownerState.Tuple); if ((titleKeyValue.GetFieldState(0) & TupleFieldState.Null) == TupleFieldState.Null) { continue; } var titleKey = Key.Create(Domain, typeof(Title), titleKeyValue); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(titleKey, titleType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } }
public void PrefetchEntitySetTest() { List <Key> keys; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { keys = session.Query.All <Order>().Take(221).AsEnumerable().Select(p => Key.Create <Order>(Domain, p.Key.Value)) .ToList(); Assert.Greater(keys.Count, 0); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var orders = session.Query.Many <Order>(keys) .Prefetch(o => o.Details); var orderType = Domain.Model.Types[typeof(Order)]; var detailsField = orderType.Fields["Details"]; foreach (var order in orders) { CollectGarbadge(); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(order.Key, orderType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); EntitySetState state; session.Handler.LookupState(order.Key, detailsField, out state); Assert.IsTrue(state.IsFullyLoaded); foreach (var detailKey in state) { Assert.IsTrue(detailKey.HasExactType); var detailState = session.EntityStateCache[detailKey, false]; PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(detailKey, detailKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } } }
public async Task PrefetchSingleAsyncTest() { Require.ProviderIsNot(StorageProvider.Firebird); List <Key> keys; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) keys = session.Query.All <Invoice>().Select(o => o.Key).ToList(); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var invoiceType = Domain.Model.Types[typeof(Invoice)]; var employeeType = Domain.Model.Types[typeof(Employee)]; var employeeField = Domain.Model.Types[typeof(Invoice)].Fields["DesignatedEmployee"]; var invoicesField = Domain.Model.Types[typeof(Employee)].Fields["Invoices"]; var invoices = session.Query.Many <Invoice>(keys) .Prefetch(o => o.DesignatedEmployee.Invoices).AsAsync(); var count = 0; foreach (var invoice in await invoices) { Assert.AreEqual(keys[count], invoice.Key); count++; PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(invoice.Key, invoiceType, session, field => PrefetchHelper.IsFieldToBeLoadedByDefault(field) || field.Equals(employeeField) || (field.Parent != null && field.Parent.Equals(employeeField))); var state = session.EntityStateCache[invoice.Key, true]; PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded( state.Entity.GetFieldValue <Employee>(employeeField).Key, employeeType, session, field => PrefetchHelper.IsFieldToBeLoadedByDefault(field) || field.Equals(invoicesField)); } Assert.AreEqual(keys.Count, count); Assert.AreEqual(12, session.Handler.PrefetchTaskExecutionCount); } }
public void FetchInstanceTest() { var orderKey = GetFirstKey <Order>(); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var fetchedEntityState = session.Handler.FetchEntityState(orderKey); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(orderKey, OrderType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); using (var session = Domain.OpenSession()) using (var transactionScope = session.OpenTransaction()) { for (int i = 0; i < 111; i++) { PrefetchTestHelper.FillDataBase(session); } transactionScope.Complete(); } }
public void PrefetchManyTest() { List <Key> keys; int actualEmployeeCount; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { keys = session.Query.All <Customer>().Where(c => c.Name == "Customer1").AsEnumerable() .Select(p => Key.Create <Person>(Domain, p.Key.Value)).ToList(); actualEmployeeCount = session.Query.All <Employee>().Where(e => e.Name == "Employee1").Count(); Assert.IsTrue(keys.All(key => !key.HasExactType)); Assert.Greater(keys.Count, 0); } using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var ordersField = customerType.Fields["Orders"]; var employeeField = orderType.Fields["Employee"]; var employeeType = Domain.Model.Types[typeof(Employee)]; session.Query.Many <Customer>(keys) .Prefetch(c => c.Orders.Prefetch(o => o.Employee)) .Run(); var customerCount = 0; var expectedEmployeeCount = 0; foreach (var key in keys) { customerCount++; var cachedKey = GetCachedKey(key, session); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, cachedKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); EntitySetState state; session.Handler.LookupState(key, ordersField, out state); Assert.IsTrue(state.IsFullyLoaded); Assert.Greater(state.TotalItemCount, 0); foreach (var orderKey in state) { expectedEmployeeCount++; var orderState = session.EntityStateCache[orderKey, true]; Assert.IsNotNull(orderState); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(orderKey, orderType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); var employeeKey = Key.Create <Person>(Domain, employeeField.Associations.Last() .ExtractForeignKey(orderState.Type, orderState.Tuple)); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employeeKey, employeeType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } Assert.AreEqual(keys.Count, customerCount); Assert.AreEqual(expectedEmployeeCount / 2, actualEmployeeCount); } }
public override void TestFixtureSetUp() { base.TestFixtureSetUp(); using (var session = Domain.OpenSession()) using (var transactionScope = session.OpenTransaction()) { for (int i = 0; i < 111; i++) { PrefetchTestHelper.FillDataBase(session); } orderType = Domain.Model.Types[typeof(Order)]; customerType = Domain.Model.Types[typeof(Customer)]; transactionScope.Complete(); } }
public void ReferencedEntityWhichOwnerHasAlreadyBeenFetchedInAnotherTransactionPrefetchTest() { var orderKey = GetFirstKey <Order>(); using (var session = Domain.OpenSession()) { using (session.OpenTransaction()) session.Query.Single <Order>(orderKey); using (session.OpenTransaction()) { session.Handler.InvokePrefetch(orderKey, null, new PrefetchFieldDescriptor(CustomerField)); session.Handler.ExecutePrefetchTasks(); PrefetchTestHelper.AssertReferencedEntityIsLoaded(orderKey, session, CustomerField); } } }
private static void AssertEntitySetItemsAreFullyLoaded(Key ownerKey, TypeInfo ownerType, FieldInfo referencingField, Session session, ref bool isOneItemPresentAtLeast) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(ownerKey, ownerType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); EntitySetState setState; session.Handler.LookupState(ownerKey, referencingField, out setState); Assert.IsTrue(setState.IsFullyLoaded); foreach (var itemKey in setState) { isOneItemPresentAtLeast = true; PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(itemKey, itemKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } }
public void EntitySetWhichOwnerHasAlreadyBeenFetchedInAnotherTransactionPrefetchTest() { var orderKey = GetFirstKey <Order>(); using (var session = Domain.OpenSession()) { using (session.OpenTransaction()) session.Query.Single <Order>(orderKey); using (session.OpenTransaction()) { session.Handler.InvokePrefetch(orderKey, null, new PrefetchFieldDescriptor(DetailsField)); session.Handler.ExecutePrefetchTasks(); PrefetchTestHelper.AssertEntitySetIsFullyLoaded(orderKey, DetailsField, 4, session); } } }
public void ReferencedEntityHasBeenFullyLoadedBeforeTaskActivationTest() { Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging); Key order0Key; Key employee0Key; Key order1Key; Key employee1Key; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var order0 = session.Query.All <Order>().OrderBy(o => o.Id).First(); var order1 = session.Query.All <Order>().OrderBy(o => o.Id).Skip(1).First(); order0Key = order0.Key; employee0Key = order0.Employee.Key; order1Key = order1.Key; employee1Key = order1.Employee.Key; } using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); var employeeNameField = Domain.Model.Types[typeof(Person)].Fields["Name"]; var employeeAgeField = employee1Key.TypeInfo.Fields["Age"]; prefetchManager.InvokePrefetch(employee0Key, null, new PrefetchFieldDescriptor(employeeNameField), new PrefetchFieldDescriptor(AgeField)); prefetchManager.InvokePrefetch(employee1Key, null, new PrefetchFieldDescriptor(AgeField)); prefetchManager.InvokePrefetch(order0Key, null, new PrefetchFieldDescriptor(OrderIdField)); prefetchManager.InvokePrefetch(order1Key, null, new PrefetchFieldDescriptor(OrderIdField)); prefetchManager.ExecuteTasks(true); prefetchManager.InvokePrefetch(order0Key, null, new PrefetchFieldDescriptor(EmployeeField, true, true)); prefetchManager.InvokePrefetch(order1Key, null, new PrefetchFieldDescriptor(EmployeeField, true, true)); var graphContainers = (SetSlim <GraphContainer>)GraphContainersField.GetValue(prefetchManager); Assert.AreEqual(2, graphContainers.Count); Func <Key, ReferencedEntityContainer> taskSelector = containerKey => graphContainers .Where(container => container.Key == containerKey) .SelectMany(container => container.ReferencedEntityContainers).Single(); var entityContainer0 = taskSelector.Invoke(order0Key); var entityContainer1 = taskSelector.Invoke(order1Key); prefetchManager.ExecuteTasks(true); Assert.IsNull(entityContainer0.Task); Assert.IsNotNull(entityContainer1.Task); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employee0Key, employee0Key.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employee1Key, employee1Key.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } }
public void EntityContainingOnlyIdFieldPrefetchTest() { Key key; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { key = new IdOnly().Key; tx.Complete(); } using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { Assert.IsNotNull(session.Query.Single <IdOnly>(key)); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, key.TypeInfo, session, IsFieldKeyOrSystem); } }
public void ThreeStepsFetchTest() { var keys = GetKeys <Person>(20); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var prefetchCount = session.Handler.PrefetchTaskExecutionCount; session.Query.Many <AdvancedPerson>(keys).Run(); foreach (var key in keys) { var cachedKey = GetCachedKey(key, session); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(cachedKey, cachedKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } Assert.AreEqual(prefetchCount + 2, session.Handler.PrefetchTaskExecutionCount); } }
public void EntityContainingOnlyLazyFieldsPrefetchTestTest() { Key key; using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { key = new LazyClass { LazyInt = 3, LazyString = "a" }.Key; tx.Complete(); } using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { Assert.IsNotNull(session.Query.Single <LazyClass>(key)); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(key, key.TypeInfo, session, IsFieldKeyOrSystem); } }
public void RepeatedRegistrationOfReferencingFieldTest() { var orderKey = GetFirstKey <Order>(); using (var session = Domain.OpenSession()) { using (var tx = session.OpenTransaction()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); prefetchManager.InvokePrefetch(orderKey, null, new PrefetchFieldDescriptor(CustomerField)); prefetchManager.InvokePrefetch(orderKey, null, new PrefetchFieldDescriptor(CustomerField, true, true)); prefetchManager.ExecuteTasks(true); var orderState = session.EntityStateCache[orderKey, true]; var customerKey = Key.Create(Domain, WellKnown.DefaultNodeId, Domain.Model.Types[typeof(Customer)], TypeReferenceAccuracy.ExactType, CustomerField.Associations.Last() .ExtractForeignKey(orderState.Type, orderState.Tuple)); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(customerKey, CustomerType, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } } }
public void BaseClassFieldsHaveBeenLoadedBeforeActivationOfReferencedEntityTaskTest() { Key titleKey; Key bookKey; CreateBookAndTitle(out titleKey, out bookKey); using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler); prefetchManager.InvokePrefetch(titleKey, null, new PrefetchFieldDescriptor(TextField, false, false), new PrefetchFieldDescriptor(TitleBookField, false, false)); prefetchManager.ExecuteTasks(true); prefetchManager.InvokePrefetch(bookKey, null, new PrefetchFieldDescriptor(BookTitleField)); prefetchManager.ExecuteTasks(true); PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(titleKey, titleKey.TypeInfo, session, PrefetchTestHelper.IsFieldToBeLoadedByDefault); } }
public void EntitySetWhenItsOwnerHasAlreadyBeenFetchedInAnotherTransactionPrefetchTest() { var orderKey = GetFirstKey <Order>(); using (var session = Domain.OpenSession()) { using (session.OpenTransaction()) session.Query.Single <Order>(orderKey); using (session.OpenTransaction()) { session.Handler.InvokePrefetch(orderKey, null, new PrefetchFieldDescriptor(DetailsField)); session.Handler.ExecutePrefetchTasks(); PrefetchTestHelper.AssertEntitySetIsFullyLoaded(orderKey, DetailsField, 4, session); /*EntitySetState setState; * session.Handler.TryGetEntitySetState(orderKey, DetailsField, out setState); * Assert.IsTrue(setState.IsFullyLoaded); * Assert.Less(0, setState.Count);*/ } } }
public async Task StructurePefetchAsyncTest() { Key containerKey; Key bookShop0Key; Key book0Key; Key bookShop1Key; Key book1Key; PrefetchTestHelper.CreateOfferContainer(Domain, out containerKey, out book0Key, out bookShop0Key, out book1Key, out bookShop1Key); using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var containers = session.Query.Many <Model.OfferContainer>(EnumerableUtils.One(containerKey)) .Prefetch(oc => oc.IntermediateOffer).AsAsync(); foreach (var key in await containers) { PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(containerKey, containerKey.TypeInfo, session, field => PrefetchTestHelper.IsFieldToBeLoadedByDefault(field) || field.Name.StartsWith("IntermediateOffer")); } } }