コード例 #1
0
        public void TestShortP2P()
        {
            var testNo = 1;

            foreach (var protocolType in new[] { ProtocolType.ByteStream, ProtocolType.MessageStream })
            {
                using (var mdoc = new MutableDocument("livesindb")) {
                    mdoc.SetString("name", "db");
                    Db.Save(mdoc);
                }

                using (var mdoc = new MutableDocument("livesinotherdb")) {
                    mdoc.SetString("name", "otherdb");
                    _otherDB.Save(mdoc);
                }


                // PUSH
                var listener = new MessageEndpointListener(new MessageEndpointListenerConfiguration(_otherDB, protocolType));
                var server   = new MockServerConnection(listener, protocolType);
                var config   = new ReplicatorConfiguration(Db,
                                                           new MessageEndpoint($"p2ptest{testNo++}", server, protocolType,
                                                                               new MockConnectionFactory(null)))
                {
                    ReplicatorType = ReplicatorType.Push,
                    Continuous     = false
                };
                RunReplication(config, 0, 0);
                _otherDB.Count.Should().Be(2UL, "because it contains the original and new");
                Db.Count.Should().Be(1UL, "because there is no pull, so the first db should only have the original");

                // PULL
                server = new MockServerConnection(listener, protocolType);
                config = new ReplicatorConfiguration(Db,
                                                     new MessageEndpoint($"p2ptest{testNo++}", server, protocolType,
                                                                         new MockConnectionFactory(null)))
                {
                    ReplicatorType = ReplicatorType.Pull,
                    Continuous     = false
                };

                RunReplication(config, 0, 0);
                Db.Count.Should().Be(2UL, "because the pull should add the document from otherDB");

                using (var savedDoc = Db.GetDocument("livesinotherdb"))
                    using (var mdoc = savedDoc.ToMutable()) {
                        mdoc.SetBoolean("modified", true);
                        Db.Save(mdoc);
                    }

                using (var savedDoc = _otherDB.GetDocument("livesindb"))
                    using (var mdoc = savedDoc.ToMutable()) {
                        mdoc.SetBoolean("modified", true);
                        _otherDB.Save(mdoc);
                    }

                // PUSH & PULL
                server = new MockServerConnection(listener, protocolType);
                config = new ReplicatorConfiguration(Db,
                                                     new MessageEndpoint($"p2ptest{testNo++}", server, protocolType,
                                                                         new MockConnectionFactory(null)))
                {
                    Continuous = false
                };

                RunReplication(config, 0, 0);
                Db.Count.Should().Be(2UL, "because no new documents were added");

                using (var savedDoc = Db.GetDocument("livesindb")) {
                    savedDoc.GetBoolean("modified").Should()
                    .BeTrue("because the property change should have come from the other DB");
                }

                using (var savedDoc = _otherDB.GetDocument("livesinotherdb")) {
                    savedDoc.GetBoolean("modified").Should()
                    .BeTrue("because the proeprty change should come from the original DB");
                }

                Db.Delete();
                ReopenDB();
                _otherDB.Delete();
                _otherDB.Dispose();
                _otherDB = OpenDB(_otherDB.Name);
            }
        }
コード例 #2
0
 public void TestDeleteTwice()
 {
     Db.Delete();
     Db.Invoking(d => d.Delete()).ShouldThrow <InvalidOperationException>();
 }