コード例 #1
0
        public void TestForeignSetNotInOrder()
        {
            var coll    = new ReplicatedReactiveRecordCollection <SpecialRecord>("local");
            var ops     = new List <KSEQOperation <SpecialRecord> >();
            var record1 = coll.CreateRecord();

            record1.value = 10;
            coll.Add(record1);
            ops.Add(coll.lastOp.Value);
            var record2 = coll.CreateRecord();

            record2.value = 20;
            coll.Add(record2);
            ops.Add(coll.lastOp.Value);
            var record3 = record1;

            record3.value = 30;
            coll[0]       = record3;
            ops.Add(coll.lastOp.Value);

            var coll2 = new ReplicatedReactiveRecordCollection <SpecialRecord>("foreign");

            // Apply set first
            coll2.Apply(ops[2]);
            coll2.Apply(ops[1]);
            coll2.Apply(ops[0]);

            Assert.IsTrue(coll.SequenceEqual(coll2));
        }
コード例 #2
0
        public void TestRandomMultiReplica()
        {
            var random = new System.Random();
            var alice  = new ReplicatedReactiveRecordCollection <SpecialRecord>("alice");
            var bob    = new ReplicatedReactiveRecordCollection <SpecialRecord>("bob");

            KSEQOperation <SpecialRecord>?[] GenerateOps(ReplicatedReactiveRecordCollection <SpecialRecord> replica)
            {
                return(Enumerable.Range(0, 1000).Select(i =>
                {
                    var rec = replica.CreateRecord();
                    rec.value = i;
                    replica.Insert(random.Next(i), rec);
                    return replica.lastOp;
                }).Concat(Enumerable.Range(0, 100)
                          .Select(i =>
                {
                    replica.RemoveAt(random.Next(1000 - i));
                    return replica.lastOp;
                }))
                       .Concat(Enumerable.Range(0, 900)
                               .Select(i =>
                {
                    var index = random.Next(i);
                    var replacement = new SpecialRecord()
                    {
                        id = replica[index].id,
                        value = i
                    };
                    replica.Replace(replacement);
                    return replica.lastOp;
                })).ToArray());
            }

            var aliceOps = GenerateOps(alice);
            var bobOps   = GenerateOps(bob);

            KSEQTests.Shuffle(aliceOps, random);
            KSEQTests.Shuffle(bobOps, random);

            foreach (var op in aliceOps)
            {
                if (op != null)
                {
                    bob.Apply(op.Value);
                }
            }

            foreach (var op in bobOps)
            {
                if (op != null)
                {
                    alice.Apply(op.Value);
                }
            }


            Assert.AreEqual(alice.Count, bob.Count);
            Assert.IsTrue(alice.ToArray().SequenceEqual(bob.ToArray()));
        }
コード例 #3
0
        public void TestReplaceOtherReplicaRecord()
        {
            var coll1 = new ReplicatedReactiveRecordCollection <SpecialRecord>("local");
            var coll2 = new ReplicatedReactiveRecordCollection <SpecialRecord>("foreign");
            var rec1  = coll1.CreateRecord();

            rec1.value = 10;
            coll1.Add(rec1);
            var op1 = coll1.lastOp.Value;

            coll2.Apply(op1);
            var rec2 = coll2[0];

            rec2.value = 20;
            coll2.Replace(rec2);
            var op2 = coll2.lastOp.Value;

            coll1.Apply(op2);
            Assert.IsTrue(coll1.SequenceEqual(coll2));
        }