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 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 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); } }