public void TestExpiredSession() { var timing = new Timing(); var latch = new AutoResetEvent(false); var watcher = new CuratorWatcher ((e) => { if (e.State == KeeperState.Expired) latch.Set (); }); using (var client = new CuratorZookeeperClient(server.GetConnectionString(), timing.session(), timing.connection(), watcher, new RetryOneTime(TimeSpan.FromMilliseconds(2)))) { client.Start(); bool firstTime = true; RetryLoop.CallWithRetry<bool>(client,() => { if (firstTime) { try { var stat = client.GetZooKeeper().Exists("/foo", false); if(stat == null){ client.GetZooKeeper().Create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent); } } catch (KeeperException.NodeExistsException ignore) { } KillSession.kill(client.GetZooKeeper(), server.GetConnectionString()); Assert.IsFalse(timing.awaitLatch(latch)); } IZooKeeper zooKeeper = client.GetZooKeeper(); client.BlockUntilConnectedOrTimedOut(); Assert.IsNotNull(zooKeeper.Exists("/foo", false)); return true; }); } }
public void testSimple() { using (CuratorZookeeperClient client = new CuratorZookeeperClient(server.GetConnectionString(), 10000, 10000, null, new RetryOneTime(TimeSpan.FromSeconds(1)))) { client.Start(); client.BlockUntilConnectedOrTimedOut(); var stat = client.GetZooKeeper ().Exists ("/test",false); if (stat != null) { client.GetZooKeeper ().Delete ("/test", -1); } String path = client.GetZooKeeper().Create("/test", new byte[] { 1, 2, 3 }, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent); Assert.AreEqual(path, "/test"); } }
public void testBackgroundConnect() { int CONNECTION_TIMEOUT_MS = 4000; using (CuratorZookeeperClient client = new CuratorZookeeperClient(server.GetConnectionString(), 10000, CONNECTION_TIMEOUT_MS, null, new RetryOneTime(TimeSpan.FromSeconds(1)))) { Assert.False(client.IsConnected()); client.Start(); outer: do { for (int i = 0; i < (CONNECTION_TIMEOUT_MS / 1000); ++i) { if (client.IsConnected()) { goto outer; } Thread.Sleep(CONNECTION_TIMEOUT_MS); } Assert.Fail(); } while (false); } }
public void testReconnect() { using (CuratorZookeeperClient client = new CuratorZookeeperClient(server.GetConnectionString(), 10000, 10000, null, new RetryOneTime(TimeSpan.FromSeconds(1)))) { client.Start(); client.BlockUntilConnectedOrTimedOut(); byte[] writtenData = { 1, 2, 3 }; var stat = client.GetZooKeeper ().Exists ("/test", false); if (stat == null) { client.GetZooKeeper ().Create ("/test", writtenData, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent); } Assert.IsTrue(client.BlockUntilConnectedOrTimedOut()); byte[] readData = client.GetZooKeeper().GetData("/test", false, null); Assert.AreEqual(readData, writtenData); } }