示例#1
0
        public void PruningState_must_merge_state_correctly()
        {
            var p1 = new PruningInitialized(_node1, ImmutableHashSet <Address> .Empty);
            var p2 = new PruningPerformed(DateTime.UtcNow.AddHours(1));

            p1.Merge(p2).Should().Be(p2);
            p2.Merge(p1).Should().Be(p2);

            var p3 = new PruningPerformed(p2.ObsoleteTime.AddMilliseconds(-1));

            p2.Merge(p3).Should().Be(p2); // keep greatest obsoleteTime
            p3.Merge(p2).Should().Be(p2);
        }
示例#2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="from">TBD</param>
        /// <param name="pruningPerformed"></param>
        /// <exception cref="ArgumentException">TBD</exception>
        /// <returns>TBD</returns>
        internal DataEnvelope Prune(UniqueAddress from, PruningPerformed pruningPerformed)
        {
            if (Data is IRemovedNodePruning dataWithRemovedNodePruning)
            {
                if (!Pruning.TryGetValue(from, out var state))
                {
                    throw new ArgumentException($"Can't prune {@from} since it's not found in DataEnvelope");
                }

                if (state is PruningInitialized initialized)
                {
                    var prunedData = dataWithRemovedNodePruning.Prune(from, initialized.Owner);
                    return(new DataEnvelope(data: prunedData, pruning: Pruning.SetItem(from, pruningPerformed), deltaVersions: CleanedDeltaVersions(from)));
                }
            }
            return(this);
        }
示例#3
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="from">TBD</param>
        /// <param name="pruningPerformed"></param>
        /// <exception cref="ArgumentException">TBD</exception>
        /// <returns>TBD</returns>
        internal DataEnvelope Prune(UniqueAddress from, PruningPerformed pruningPerformed)
        {
            var dataWithRemovedNodePruning = Data as IRemovedNodePruning;

            if (dataWithRemovedNodePruning != null)
            {
                IPruningState state;
                if (!Pruning.TryGetValue(from, out state))
                {
                    throw new ArgumentException($"Can't prune {@from} since it's not found in DataEnvelope");
                }

                var initialized = state as PruningInitialized;
                if (initialized != null)
                {
                    var prunedData = dataWithRemovedNodePruning.Prune(from, initialized.Owner);
                    return(new DataEnvelope(data: prunedData, pruning: Pruning.SetItem(from, pruningPerformed), deltaVersions: CleanedDeltaVersions(from)));
                }
            }
            return(this);
        }