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); }
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> /// 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));