Ejemplo n.º 1
0
 public bool GraphIsTracked(InternalId internalId)
 {
     return
         GetCurrentPersistenceEvents()
             .Where(_ => _.InternalId == internalId)
             .Any();
 }
        protected override void Given()
        {
            stashedPost = new Post
                {
                    Title = "My Super Blog",
                    PostedAt = new DateTime(2010, 03, 19, 13, 33, 34),
                    Text = "This is my super blog. Check out my awesome post",
                    Comments = new List<Comment>
                        {
                            new Comment
                                {
                                    Author = "Andy Hitchman",
                                    AuthorsEmail = "*****@*****.**",
                                    CommentedAt = new DateTime(2010, 03, 19, 13, 36, 01),
                                    Text = "This blog is teh suck"
                                }
                        }
                };

            var internalId = new InternalId(Guid.NewGuid());
            var registeredGraph = Kernel.Registry.GetRegistrationFor<Post>();
            var serializedGraph = registeredGraph.Serialize(stashedPost, null);
            var projectedIndexes = registeredGraph.IndexersOnGraph.SelectMany(_ => _.GetUntypedProjections(stashedPost));
            var tracked = new TrackedGraph(new StoredGraph(internalId, registeredGraph.GraphType, serializedGraph), projectedIndexes, registeredGraph);

            Kernel.Registry.BackingStore.InTransactionDo(_ => _.InsertGraph(tracked));
        }
        public void it_should_return_the_internal_id_if_the_graph_is_tracked()
        {
            var mockPersistentEvent = MockRepository.GenerateStub<IPersistenceEvent>();
            var sut = new SerializationSession(() => new[] {mockPersistentEvent}, null, false);

            var expected = new InternalId(Guid.NewGuid());
            var graph = new object();
            mockPersistentEvent.Stub(_ => _.UntypedGraph).Return(graph);
            mockPersistentEvent.Stub(_ => _.InternalId).Return(expected);

            sut.InternalIdOfTrackedGraph(graph).ShouldEqual(expected);
        }
Ejemplo n.º 4
0
 public static byte[] ValueForKey(this HashDatabase store, InternalId key)
 {
     try
     {
         return store.Get(new DatabaseEntry(key.AsByteArray())).Value.Data;
     }
     catch(NotFoundException)
     {
         Assert.Fail("ValueForKey: Key not found");
     }
     return null;
 }
Ejemplo n.º 5
0
        protected override void Given()
        {
            lhs = MockRepository.GenerateStub<IBerkeleyQuery>();
            rhs = MockRepository.GenerateStub<IBerkeleyQuery>();

            var commonGuid = new InternalId(Guid.NewGuid());
            lhsSet = new[] {commonGuid, new InternalId(Guid.NewGuid())};
            rhsSet = new[] {new InternalId(Guid.NewGuid()), commonGuid};

            lhs.Stub(_ => _.Execute(null)).IgnoreArguments().Return(lhsSet);
            rhs.Stub(_ => _.Execute(null)).IgnoreArguments().Return(rhsSet);

            sut = new UnionOperator(new[] {lhs, rhs});
        }
        protected override void Given()
        {
            lhs = Substitute.For<IAzureQuery>();
            rhs = Substitute.For<IAzureQuery>();

            intersectingGuid1 = new InternalId(Guid.NewGuid());
            intersectingGuid2 = new InternalId(Guid.NewGuid());

            lhs.ExecuteInsideIntersect(null, null).ReturnsForAnyArgs(new[] {intersectingGuid1});
            rhs.ExecuteInsideIntersect(null, null).ReturnsForAnyArgs(new[] {intersectingGuid2});

            sut = new UnionOperator(new[] {lhs, rhs});

            joinConstraint = new[]
                {
                    intersectingGuid1, new InternalId(Guid.NewGuid()), intersectingGuid2
                };
        }
        protected override void Given()
        {
            lhs = MockRepository.GenerateStub<IBerkeleyQuery>();
            rhs = MockRepository.GenerateStub<IBerkeleyQuery>();

            commonGuid = new InternalId(Guid.NewGuid());
            lhsSet = new[] {commonGuid, new InternalId(Guid.NewGuid())};
            rhsSet = new[] {new InternalId(Guid.NewGuid()), commonGuid};

            //A bit weak. We're not sure which side will execute first: The second to execute
            //will call ExecuteInsideIntersect. Cheat by ignoring this and having the pair of methods
            //return the same result.
            lhs.Stub(_ => _.Execute(null)).IgnoreArguments().Return(lhsSet);
            lhs.Stub(_ => _.ExecuteInsideIntersect(null, null)).IgnoreArguments().Return(lhsSet);
            rhs.Stub(_ => _.Execute(null)).IgnoreArguments().Return(rhsSet);
            rhs.Stub(_ => _.ExecuteInsideIntersect(null, null)).IgnoreArguments().Return(rhsSet);

            sut = new IntersectOperator(new[] {lhs, rhs});
        }
Ejemplo n.º 8
0
 public static void ShouldNotHaveKey(this HashDatabase store, InternalId key)
 {
     store.Exists(new DatabaseEntry(key.AsByteArray())).ShouldBeFalse();
 }
Ejemplo n.º 9
0
 public void Insert(object key, InternalId internalId, TableServiceContext serviceContext)
 {
     serviceContext.AddObject(ForwardIndexName, new IndexEntity {PartitionKey = KeyAsString(key), RowKey = internalId.ToString(), OriginalValue = key.ToString()});
     serviceContext.AddObject(ReverseIndexName, new IndexEntity { PartitionKey = internalId.ToString(), RowKey = KeyAsString(key), OriginalValue = key.ToString() });
 }
Ejemplo n.º 10
0
        public void Delete(InternalId internalId, TableServiceContext serviceContext)
        {
            var allKeysInIndex =
                (from ri in ReverseIndex(serviceContext)
                 where ri.PartitionKey == internalId.ToString()
                 select ri);

            //In the forward index, get the corresponding forward index for each reverse index value and delete them both
            Parallel.ForEach(
                allKeysInIndex,
                reverseEntity =>
                    {
            //                        var forwardEntity = new IndexEntity {PartitionKey = reverseEntity.RowKey, RowKey = reverseEntity.PartitionKey};
            //                        serviceContext.AttachTo(ForwardIndexName, forwardEntity, "*");
                        var forwardEntity =
                            Queryable.Single<IndexEntity>((from fi in ForwardIndex(serviceContext)
                                                             where fi.PartitionKey == reverseEntity.RowKey
                                                             where fi.RowKey == reverseEntity.PartitionKey
                                                             select fi));
                        serviceContext.DeleteObject(forwardEntity);
                        serviceContext.DeleteObject(reverseEntity);
                    });
        }
Ejemplo n.º 11
0
        public IEnumerable<InternalId> Execute(TableServiceContext serviceContext)
        {
            var query = managedIndex.ReverseIndex(serviceContext);

            Func<InternalId, InternalId> nextInternalId =
                cid =>
                    {
                        var next =
                            (from ri in query
                             where ri.PartitionKey.CompareTo(cid.Value.ToString()) > 0
                             select ri)
                                .FirstOrDefault();
                        return next != null ? managedIndex.ConvertToInternalId(next.PartitionKey) : null;
                    };

            var currentInternalId = new InternalId(Guid.Empty);
            while ((currentInternalId = nextInternalId(currentInternalId)) != null)
                yield return currentInternalId;
        }
Ejemplo n.º 12
0
        /// <summary>
        ///   Get the graph by internal id. If the graph is not tracked, it is fetched from the 
        ///   backing store and tracked.
        /// </summary>
        /// <param name = "internalId"></param>
        /// <returns></returns>
        /// <exception cref = "GraphForKeyNotFoundException">If the graph is not persisted in the backing store.</exception>
        public object TrackedGraphForInternalId(InternalId internalId)
        {
            if(ActivelyDeserialising.ContainsKey(internalId))
                return ActivelyDeserialising[internalId];

            var tracked =
                GetCurrentPersistenceEvents()
                    .Where(_ => _.InternalId == internalId)
                    .Select(_ => _.UntypedGraph).FirstOrDefault();

            if(tracked != null)
                return tracked;

            var loading = InternalSession.LoadTrackedGraphForInternalId(internalId, this, untracked);

            return loading;
        }
Ejemplo n.º 13
0
 public void RecordActiveDeserialization(InternalId internalId, object graph)
 {
     ActivelyDeserialising.Add(internalId, graph);
 }
Ejemplo n.º 14
0
 public StoredGraph(InternalId internalId, Type graphType, Stream graph)
     : this(internalId, graphType)
 {
     SerialisedGraph = graph;
 }
Ejemplo n.º 15
0
 public StoredGraph(InternalId internalId, Type graphType)
 {
     InternalId = internalId;
     GraphType = graphType;
 }
Ejemplo n.º 16
0
 public void Insert(object untypedKey, InternalId internalId, Transaction transaction)
 {
     index
         .Put(
             new DatabaseEntry(KeyAsByteArray(untypedKey)),
             new DatabaseEntry(internalId.AsByteArray()),
             transaction);
     reverseIndex
         .Put(
             new DatabaseEntry(internalId.AsByteArray()),
             new DatabaseEntry(KeyAsByteArray(untypedKey)),
             transaction);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Create a stored graph based on an existing record
 /// </summary>
 /// <param name="internalId"></param>
 /// <param name="graphType"></param>
 /// <param name="accessCondition"> </param>
 /// <param name="graph"></param>
 public StoredGraph(InternalId internalId, Type graphType, AccessCondition accessCondition, Stream graph)
     : this(internalId, graphType, accessCondition)
 {
     SerialisedGraph = graph;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Create a stored graph based on an existing record
 /// </summary>
 /// <param name="internalId"></param>
 /// <param name="graphType"></param>
 /// <param name="accessCondition"> </param>
 public StoredGraph(InternalId internalId, Type graphType, AccessCondition accessCondition)
 {
     InternalId = internalId;
     GraphType = graphType;
     AccessCondition = accessCondition;
 }