コード例 #1
0
        public void TestRemoveChangeListener()
        {
            var statuses         = new List <ReplicatorActivityLevel>();
            var listener         = new MessageEndpointListener(new MessageEndpointListenerConfiguration(_otherDB, ProtocolType.ByteStream));
            var awaiter          = new ListenerAwaiter(listener);
            var serverConnection = new MockServerConnection(listener, ProtocolType.ByteStream);
            var config           = new ReplicatorConfiguration(Db,
                                                               new MessageEndpoint("p2ptest1", serverConnection, ProtocolType.ByteStream,
                                                                                   new MockConnectionFactory(null)))
            {
                Continuous = true
            };
            var token = listener.AddChangeListener((sender, args) =>
            {
                statuses.Add(args.Status.Activity);
            });
            var connection = listener.Connections;

            listener.RemoveChangeListener(token);
            RunReplication(config, 0, 0);
            awaiter.WaitHandle.WaitOne(TimeSpan.FromSeconds(10)).Should().BeTrue();
            awaiter.Validate();

            statuses.Count.Should().Be(0);
        }
コード例 #2
0
        public void TestP2PPassiveClose()
        {
            var listener         = new MessageEndpointListener(new MessageEndpointListenerConfiguration(_otherDB, ProtocolType.MessageStream));
            var awaiter          = new ListenerAwaiter(listener);
            var serverConnection = new MockServerConnection(listener, ProtocolType.MessageStream);
            var errorLogic       = new ReconnectErrorLogic();
            var config           = new ReplicatorConfiguration(Db,
                                                               new MessageEndpoint("p2ptest1", serverConnection, ProtocolType.MessageStream,
                                                                                   new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            var replicator = new Replicator(config);

            replicator.Start();

            var count = 0;

            while (count++ < 10 && replicator.Status.Activity != ReplicatorActivityLevel.Idle)
            {
                Thread.Sleep(500);
                count.Should().BeLessThan(10, "because otherwise the replicator never went idle");
            }

            errorLogic.ErrorActive = true;
            listener.Close(serverConnection);
            count = 0;
            while (count++ < 10 && replicator.Status.Activity != ReplicatorActivityLevel.Stopped)
            {
                Thread.Sleep(500);
                count.Should().BeLessThan(10, "because otherwise the replicator never stopped");
            }


            awaiter.WaitHandle.WaitOne(TimeSpan.FromSeconds(10)).Should().BeTrue();
            awaiter.Validate();

            replicator.Status.Error.Should()
            .NotBeNull("because closing the passive side creates an error on the active one");
        }
コード例 #3
0
        //[Fact] uwp
        public void TestP2PChangeListener()
        {
            var statuses         = new List <ReplicatorActivityLevel>();
            var listener         = new MessageEndpointListener(new MessageEndpointListenerConfiguration(OtherDb, ProtocolType.ByteStream));
            var awaiter          = new ListenerAwaiter(listener);
            var serverConnection = new MockServerConnection(listener, ProtocolType.ByteStream);
            var config           = new ReplicatorConfiguration(Db,
                                                               new MessageEndpoint("p2ptest1", serverConnection, ProtocolType.ByteStream,
                                                                                   new MockConnectionFactory(null)))
            {
                Continuous = true
            };

            listener.AddChangeListener((sender, args) => {
                statuses.Add(args.Status.Activity);
            });
            var connection = listener.Connections;

            RunReplication(config, 0, 0);
            awaiter.WaitHandle.WaitOne(TimeSpan.FromSeconds(10)).Should().BeTrue();
            awaiter.Validate();
            statuses.Count.Should()
            .BeGreaterThan(1, "because otherwise there were no callbacks to the change listener");
        }