Example #1
0
        public void LWWRegister_must_merge_by_picking_max_timestamp()
        {
            var            i     = From(100).GetEnumerator();
            Clock <string> clock = (timestamp, value) =>
            {
                i.MoveNext();
                return(i.Current);
            };

            var r1 = new LWWRegister <string>(_node1, "A", clock);

            Assert.Equal(100, r1.Timestamp);

            var r2 = new LWWRegister <string>(_node2, "B", clock);

            Assert.Equal(101, r2.Timestamp);

            var m1 = r1.Merge(r2);

            Assert.Equal("B", m1.Value);
            Assert.Equal(101, m1.Timestamp);

            var m2 = r2.Merge(r1);

            Assert.Equal("B", m2.Value);
            Assert.Equal(101, m2.Timestamp);
        }
Example #2
0
        public void LWWRegister_must_merge_by_picking_least_address_when_same_timestamp()
        {
            Clock <string> clock = (timestamp, value) => 100;

            var r1 = new LWWRegister <string>(_node1, "A", clock);
            var r2 = new LWWRegister <string>(_node2, "B", clock);

            var m1 = r1.Merge(r2);

            Assert.Equal("A", m1.Value);

            var m2 = r2.Merge(r1);

            Assert.Equal("A", m2.Value);
        }
 /// <summary>
 /// Creates an instance of an LWWRegister scoped to a current cluster.
 /// </summary>
 /// <typeparam name="TVal">TBD</typeparam>
 /// <param name="cluster">TBD</param>
 /// <param name="register">TBD</param>
 /// <returns>TBD</returns>
 public static LocalLWWRegister <TVal> LWWRegister <TVal>(this Cluster.Cluster cluster, LWWRegister <TVal> register) =>
 new LocalLWWRegister <TVal>(cluster, register);
Example #4
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="cluster">TBD</param>
 /// <param name="crdt">TBD</param>
 public LocalLWWRegister(Cluster.Cluster cluster, LWWRegister <T> crdt) : this(cluster.SelfUniqueAddress, crdt)
 {
 }
Example #5
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="currentNode">TBD</param>
 /// <param name="crdt">TBD</param>
 internal LocalLWWRegister(UniqueAddress currentNode, LWWRegister <T> crdt) : this()
 {
     _currentNode = currentNode;
     _crdt        = crdt;
 }
Example #6
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="register">TBD</param>
 public Surrogate(LWWRegister <T> register)
 {
     this.register = register;
 }
Example #7
0
 /// <summary>
 /// Merges data from provided <see cref="LWWRegister{T}"/> into current CRDT,
 /// creating new immutable instance in a result.
 /// </summary>
 /// <param name="register">TBD</param>
 /// <returns>TBD</returns>
 public LocalLWWRegister <T> Merge(LWWRegister <T> register) =>
 new LocalLWWRegister <T>(_currentNode, _crdt.Merge(register));