Example #1
0
        public void PNCounter_must_be_able_to_increment_and_decrement_each_nodes_record_by_arbitrary_delta()
        {
            var c1 = new PNCounter();

            var c2 = c1.Increment(_address1, 3);
            var c3 = c2.Decrement(_address1, 2);
            var c4 = c3.Increment(_address2, 5);
            var c5 = c4.Decrement(_address2, 2);
            var c6 = c5.Increment(_address2);

            Assert.Equal(9, (long)c6.Increments.Value);
            Assert.Equal(4, (long)c6.Decrements.Value);
        }
Example #2
0
        public void A_PNCounter_should_be_able_to_increment_each_nodes_record_by_arbitrary_delta()
        {
            var c1 = new PNCounter();

            var c2 = c1.Increment(_address1, 3);
            var c3 = c2.Increment(_address1, 4);
            var c4 = c3.Increment(_address2, 2);
            var c5 = c4.Increment(_address2, 7);
            var c6 = c5.Increment(_address2);

            Assert.Equal(7, c6.Increments.State[_address1]);
            Assert.Equal(10, c6.Increments.State[_address2]);
        }
Example #3
0
        public void PNCounter_must_be_able_to_decrement_each_nodes_record_by_arbitrary_delta()
        {
            var c1 = new PNCounter();

            var c2 = c1.Decrement(_address1, 3);
            var c3 = c2.Decrement(_address1, 4);
            var c4 = c3.Decrement(_address2, 2);
            var c5 = c4.Decrement(_address2, 7);
            var c6 = c5.Decrement(_address2);

            Assert.Equal(7UL, c6.Decrements.State[_address1]);
            Assert.Equal(10UL, c6.Decrements.State[_address2]);
        }
Example #4
0
        public void PNCounter_must_be_able_to_decrement_each_nodes_record_by_one()
        {
            var c1 = new PNCounter();

            var c2 = c1.Decrement(_address1);
            var c3 = c2.Decrement(_address1);

            var c4 = c3.Decrement(_address2);
            var c5 = c4.Decrement(_address2);
            var c6 = c5.Decrement(_address2);

            Assert.Equal(2UL, c6.Decrements.State[_address1]);
            Assert.Equal(3UL, c6.Decrements.State[_address2]);
        }
Example #5
0
        public void A_PNCounter_should_be_able_to_increment_each_nodes_record_by_one()
        {
            var c1 = new PNCounter();

            var c2 = c1.Increment(_address1);
            var c3 = c2.Increment(_address1);

            var c4 = c3.Increment(_address2);
            var c5 = c4.Increment(_address2);
            var c6 = c5.Increment(_address2);

            Assert.Equal(2, c6.Increments.State[_address1]);
            Assert.Equal(3, c6.Increments.State[_address2]);
        }
Example #6
0
        public void PNCounter_must_be_able_to_summarize_the_history_to_the_correct_aggregated_value_of_increments_and_decrements()
        {
            var c1 = new PNCounter();

            var c2 = c1.Increment(_address1, 3);
            var c3 = c2.Decrement(_address1, 2);
            var c4 = c3.Increment(_address2, 5);
            var c5 = c4.Decrement(_address2, 2);
            var c6 = c5.Increment(_address2);

            Assert.Equal(9, (long)c6.Increments.Value);
            Assert.Equal(4, (long)c6.Decrements.Value);

            Assert.Equal(5, (long)c6.Value);
        }
Example #7
0
        public void PNCounter_must_have_support_for_pruning()
        {
            var c1 = new PNCounter();
            var c2 = c1.Increment(_address1);
            var c3 = c2.Decrement(_address2);

            Assert.True(c2.NeedPruningFrom(_address1));
            Assert.False(c2.NeedPruningFrom(_address2));
            Assert.True(c3.NeedPruningFrom(_address1));
            Assert.True(c3.NeedPruningFrom(_address2));

            var c4 = c3.Prune(_address1, _address2);

            Assert.True(c4.NeedPruningFrom(_address2));
            Assert.False(c4.NeedPruningFrom(_address1));

            var c5 = (c4.Increment(_address1)).PruningCleanup(_address1);

            Assert.False(c5.NeedPruningFrom(_address1));
        }
Example #8
0
        public void A_PNCounter_should_have_support_for_pruning()
        {
            var c1 = new PNCounter();
            var c2 = c1.Increment(_address1);
            var c3 = c2.Decrement(_address2);

            Assert.Equal(true, c2.NeedPruningFrom(_address1));
            Assert.Equal(false, c2.NeedPruningFrom(_address2));
            Assert.Equal(true, c3.NeedPruningFrom(_address1));
            Assert.Equal(true, c3.NeedPruningFrom(_address2));

            var c4 = c3.Prune(_address1, _address2);

            Assert.Equal(true, c4.NeedPruningFrom(_address2));
            Assert.Equal(false, c4.NeedPruningFrom(_address1));

            var c5 = (c4.Increment(_address1)).PruningCleanup(_address1);

            Assert.Equal(false, c5.NeedPruningFrom(_address1));
        }
Example #9
0
        public void PNCounter_must_be_able_to_have_its_history_correctly_merged_with_another_PNCounter()
        {
            var c11 = new PNCounter();
            var c12 = c11.Increment(_address1, 3);
            var c13 = c12.Decrement(_address1, 2);
            var c14 = c13.Increment(_address2, 5);
            var c15 = c14.Decrement(_address2, 2);
            var c16 = c15.Increment(_address2);

            Assert.Equal(9, (long)c16.Increments.Value);
            Assert.Equal(4, (long)c16.Decrements.Value);

            Assert.Equal(5, (long)c16.Value);

            var c21 = new PNCounter();
            var c22 = c21.Increment(_address1, 2);
            var c23 = c22.Decrement(_address1, 3);
            var c24 = c23.Increment(_address2, 3);
            var c25 = c24.Decrement(_address2, 2);
            var c26 = c25.Increment(_address2);

            Assert.Equal(6, (long)c26.Increments.Value);
            Assert.Equal(5, (long)c26.Decrements.Value);

            Assert.Equal(1, (long)c26.Value);

            var merged1 = c16.Merge(c26);

            Assert.Equal(9UL, merged1.Increments.Value);
            Assert.Equal(5UL, merged1.Decrements.Value);
            Assert.Equal(4UL, merged1.Value);

            var merged2 = c26.Merge(c16);

            Assert.Equal(9UL, merged2.Increments.Value);
            Assert.Equal(5UL, merged2.Decrements.Value);
            Assert.Equal(4UL, merged2.Value);
        }
Example #10
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="cluster">TBD</param>
 /// <param name="counter">TBD</param>
 public LocalPNCounter(Cluster.Cluster cluster, PNCounter counter) : this(cluster.SelfUniqueAddress, counter)
 {
 }
Example #11
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="currentNode">TBD</param>
 /// <param name="crdt">TBD</param>
 internal LocalPNCounter(UniqueAddress currentNode, PNCounter crdt) : this()
 {
     _currentNode = currentNode;
     _crdt        = crdt;
 }
Example #12
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="counter">TBD</param>
 public Surrogate(PNCounter counter)
 {
     _counter = counter;
 }
Example #13
0
 /// <summary>
 /// Merges data from provided <see cref="PNCounter"/> into current CRDT,
 /// creating new immutable instance in a result.
 /// </summary>
 /// <param name="counter">TBD</param>
 /// <returns>TBD</returns>
 public LocalPNCounter Merge(PNCounter counter) => new LocalPNCounter(_currentNode, _crdt.Merge(counter));
 /// <summary>
 /// Creates an instance of PNCounter scoped to a current cluster.
 /// </summary>
 /// <param name="cluster">TBD</param>
 /// <param name="counter">TBD</param>
 /// <returns>TBD</returns>
 public static LocalPNCounter PNCounter(this Cluster.Cluster cluster, PNCounter counter) =>
 new LocalPNCounter(cluster, counter);