示例#1
0
        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;
                });

            }
                


        }
示例#2
0
 /**
  * Return a new timing that is a multiple of the this timing
  *
  * @param n the multiple
  * @return this timing times the multiple
  */
 public Timing multiple(double n)
 {
     var v = new Timing(TimeSpan.FromSeconds((value.TotalSeconds * n)));
     return v;
 }