public void TestCloseWithActiveListener() { Listen(CreateListenerConfig()); OtherDb.Close(); _listener.Port.Should().Be(0); _listener.Urls.Should().BeEmpty(); }
private void WithActiveReplicatorAndURLEndpointListeners(bool isCloseNotDelete) { WaitAssert waitIdleAssert1 = new WaitAssert(); WaitAssert waitStoppedAssert1 = new WaitAssert(); _listener = CreateListener(); var _listener2 = CreateNewListener(); _listener.Config.Database.ActiveStoppables.Count.Should().Be(2); _listener2.Config.Database.ActiveStoppables.Count.Should().Be(2); using (var doc1 = new MutableDocument("doc1")) using (var doc2 = new MutableDocument("doc2")) { doc1.SetString("name", "Sam"); Db.Save(doc1); doc2.SetString("name", "Mary"); OtherDb.Save(doc2); } var target = new DatabaseEndpoint(Db); var config1 = CreateConfig(target, ReplicatorType.PushAndPull, true, sourceDb: OtherDb); var repl1 = new Replicator(config1); repl1.AddChangeListener((sender, args) => { waitIdleAssert1.RunConditionalAssert(() => { return(args.Status.Activity == ReplicatorActivityLevel.Idle); }); waitStoppedAssert1.RunConditionalAssert(() => { return(args.Status.Activity == ReplicatorActivityLevel.Stopped); }); }); repl1.Start(); waitIdleAssert1.WaitForResult(TimeSpan.FromSeconds(10)); OtherDb.ActiveStoppables.Count.Should().Be(3); if (isCloseNotDelete) { OtherDb.Close(); } else { OtherDb.Delete(); } OtherDb.ActiveStoppables.Count.Should().Be(0); OtherDb.IsClosedLocked.Should().Be(true); waitStoppedAssert1.WaitForResult(TimeSpan.FromSeconds(30)); }
private void WithActiveReplicationsAndURLEndpointListener(bool isCloseNotDelete) { var waitIdleAssert1 = new ManualResetEventSlim(); var waitIdleAssert2 = new ManualResetEventSlim(); var waitStoppedAssert1 = new ManualResetEventSlim(); var waitStoppedAssert2 = new ManualResetEventSlim(); using (var doc = new MutableDocument()) { OtherDb.Save(doc); } _listener = CreateListener(); _listener.Config.Database.ActiveStoppables.Count.Should().Be(1); using (var doc1 = new MutableDocument()) { Db.Save(doc1); } var target = new DatabaseEndpoint(Db); var config1 = CreateConfig(target, ReplicatorType.PushAndPull, true, sourceDb: OtherDb); var repl1 = new Replicator(config1); Database.Delete("urlepTestDb", Directory); var urlepTestDb = OpenDB("urlepTestDb"); using (var doc2 = new MutableDocument()) { urlepTestDb.Save(doc2); } var config2 = CreateConfig(_listener.LocalEndpoint(), ReplicatorType.PushAndPull, true, serverCert: _listener.TlsIdentity.Certs[0], sourceDb: urlepTestDb); var repl2 = new Replicator(config2); EventHandler <ReplicatorStatusChangedEventArgs> changeListener = (sender, args) => { if (args.Status.Activity == ReplicatorActivityLevel.Idle && args.Status.Progress.Completed == args.Status.Progress.Total) { if (sender == repl1) { waitIdleAssert1.Set(); } else { waitIdleAssert2.Set(); } } else if (args.Status.Activity == ReplicatorActivityLevel.Stopped) { if (sender == repl1) { waitStoppedAssert1.Set(); } else { waitStoppedAssert2.Set(); } } }; repl1.AddChangeListener(changeListener); repl2.AddChangeListener(changeListener); repl1.Start(); repl2.Start(); WaitHandle.WaitAll(new[] { waitIdleAssert1.WaitHandle, waitIdleAssert2.WaitHandle }, _timeout) .Should().BeTrue(); OtherDb.ActiveStoppables.Count.Should().Be(2); urlepTestDb.ActiveStoppables.Count.Should().Be(1); if (isCloseNotDelete) { urlepTestDb.Close(); OtherDb.Close(); } else { urlepTestDb.Delete(); OtherDb.Delete(); } OtherDb.ActiveStoppables.Count.Should().Be(0); urlepTestDb.ActiveStoppables.Count.Should().Be(0); OtherDb.IsClosedLocked.Should().Be(true); urlepTestDb.IsClosedLocked.Should().Be(true); WaitHandle.WaitAll(new[] { waitStoppedAssert1.WaitHandle, waitStoppedAssert2.WaitHandle }, TimeSpan.FromSeconds(20)) .Should().BeTrue(); waitIdleAssert1.Dispose(); waitIdleAssert2.Dispose(); waitStoppedAssert1.Dispose(); waitStoppedAssert2.Dispose(); Thread.Sleep(500); }