Esempio n. 1
0
        public void TestP2PPassiveCloseAll()
        {
            var listener          = new MessageEndpointListener(new MessageEndpointListenerConfiguration(_otherDB, ProtocolType.MessageStream));
            var serverConnection1 = new MockServerConnection(listener, ProtocolType.MessageStream);
            var serverConnection2 = new MockServerConnection(listener, ProtocolType.MessageStream);
            var errorLogic        = new ReconnectErrorLogic();
            var config            = new ReplicatorConfiguration(Db,
                                                                new MessageEndpoint("p2ptest1", serverConnection1, ProtocolType.MessageStream,
                                                                                    new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            var config2 = new ReplicatorConfiguration(Db,
                                                      new MessageEndpoint("p2ptest2", serverConnection2, ProtocolType.MessageStream,
                                                                          new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            var replicator = new Replicator(config);

            replicator.Start();
            var replicator2 = new Replicator(config2);

            replicator2.Start();

            var count = 0;

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

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

            replicator.Status.Error.Should()
            .NotBeNull("because closing the passive side creates an error on the active one");
            replicator2.Status.Error.Should()
            .NotBeNull("because closing the passive side creates an error on the active one");
            replicator.Dispose();
            replicator2.Dispose();
        }
Esempio n. 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");
        }
Esempio n. 3
0
//        Exception thrown at 0x00007FFE3090A799 in dotnet.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x000000C288E79D88.
//Exception thrown at 0x00007FFE3090A799 in dotnet.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
        //[Fact] uwp
        public void TestP2PPassiveCloseAll()
        {
            using (var doc = new MutableDocument("test")) {
                doc.SetString("name", "Smokey");
                Db.Save(doc);
            }

            var listener          = new MessageEndpointListener(new MessageEndpointListenerConfiguration(OtherDb, ProtocolType.MessageStream));
            var serverConnection1 = new MockServerConnection(listener, ProtocolType.MessageStream);
            var serverConnection2 = new MockServerConnection(listener, ProtocolType.MessageStream);
            var closeWait1        = new ManualResetEventSlim();
            var closeWait2        = new ManualResetEventSlim();
            var errorLogic        = new ReconnectErrorLogic();
            var config            = new ReplicatorConfiguration(Db,
                                                                new MessageEndpoint("p2ptest1", serverConnection1, ProtocolType.MessageStream,
                                                                                    new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            var config2 = new ReplicatorConfiguration(Db,
                                                      new MessageEndpoint("p2ptest2", serverConnection2, ProtocolType.MessageStream,
                                                                          new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            using (var replicator = new Replicator(config))
                using (var replicator2 = new Replicator(config2)) {
                    replicator.Start();
                    replicator2.Start();

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

                    errorLogic.ErrorActive = true;
                    listener.AddChangeListener((sender, args) => {
                        if (args.Status.Activity == ReplicatorActivityLevel.Stopped)
                        {
                            if (args.Connection == serverConnection1)
                            {
                                closeWait1.Set();
                            }
                            else
                            {
                                closeWait2.Set();
                            }
                        }
                    });
                    var connection = listener.Connections;
                    listener.CloseAll();
                    count = 0;
                    while (count++ < 10 && replicator.Status.Activity != ReplicatorActivityLevel.Stopped &&
                           replicator2.Status.Activity != ReplicatorActivityLevel.Stopped)
                    {
                        Thread.Sleep(500);
                        count.Should().BeLessThan(10, "because otherwise the replicator(s) never stopped");
                    }

                    closeWait1.Wait(TimeSpan.FromSeconds(5)).Should()
                    .BeTrue("because otherwise the first listener did not stop");
                    closeWait2.Wait(TimeSpan.FromSeconds(5)).Should()
                    .BeTrue("because otherwise the second listener did not stop");

                    replicator.Status.Error.Should()
                    .NotBeNull("because closing the passive side creates an error on the active one");
                    replicator2.Status.Error.Should()
                    .NotBeNull("because closing the passive side creates an error on the active one");
                }
        }
Esempio n. 4
0
        public void TestP2PPassiveCloseAll()
        {
            using (var doc = new MutableDocument("test"))
            {
                doc.SetString("name", "Smokey");
                Db.Save(doc);
            }

            var listener          = new MessageEndpointListener(new MessageEndpointListenerConfiguration(OtherDb, ProtocolType.MessageStream));
            var serverConnection1 = new MockServerConnection(listener, ProtocolType.MessageStream);
            var serverConnection2 = new MockServerConnection(listener, ProtocolType.MessageStream);
            var closeWait1        = new ManualResetEventSlim();
            var closeWait2        = new ManualResetEventSlim();
            var errorLogic        = new ReconnectErrorLogic();
            var config            = new ReplicatorConfiguration(Db,
                                                                new MessageEndpoint("p2ptest1", serverConnection1, ProtocolType.MessageStream,
                                                                                    new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            var config2 = new ReplicatorConfiguration(Db,
                                                      new MessageEndpoint("p2ptest2", serverConnection2, ProtocolType.MessageStream,
                                                                          new MockConnectionFactory(errorLogic)))
            {
                Continuous = true
            };

            using (var replicator = new Replicator(config))
                using (var replicator2 = new Replicator(config2))
                {
                    EventHandler <ReplicatorStatusChangedEventArgs> changeListener = (sender, args) =>
                    {
                        if (args.Status.Activity == ReplicatorActivityLevel.Stopped)
                        {
                            if (sender == replicator)
                            {
                                closeWait1.Set();
                            }
                            else
                            {
                                closeWait2.Set();
                            }
                        }
                    };

                    replicator.AddChangeListener(changeListener);
                    replicator2.AddChangeListener(changeListener);
                    replicator.Start();
                    replicator2.Start();

                    errorLogic.ErrorActive = true;
                    listener.CloseAll();

                    WaitHandle.WaitAll(new[] { closeWait1.WaitHandle, closeWait2.WaitHandle }, TimeSpan.FromSeconds(20)).Should().BeTrue();

                    replicator.Status.Error.Should()
                    .NotBeNull("because closing the passive side creates an error on the active one");
                    replicator2.Status.Error.Should()
                    .NotBeNull("because closing the passive side creates an error on the active one");
                }

            closeWait1.Dispose();
            closeWait2.Dispose();
        }