I was just about to ask about the JMX route since it seems to work but i do observe the 1->4 behavior you mentioned. I ended up doing my best code wise and then did some basic testing with iptables but it's not what i would consider robust testing and far from automated. Anything that can be done to allow end users to test their client code in real world-ish situation would be a huge help since handling these error cases seems to be so critical to a correctly operating zookeeper application.
- will On Wed, Jul 27, 2011 at 1:20 PM, Patrick Hunt <[email protected]> wrote: > On second thought there is one other way - JMX allows you to close a > session, this could be used similarly. See tests using > src/java/test/org/apache/zookeeper/test/JMXEnv.java > > I think there's an issue with each of these mechanisms though. In a > real situation you typically see: > > 1) client connected successfully to server with session A > 2) client gets disconnected from server > 3) time passes (ie the session is expired) > 4) client regains connectivity to server, gets notified that session is > expired > > In these other cases step 2 is skipped - we go from 1 directly to 4 > (client notified session is expired). Seems like we should have some > way to simulate this that more closely replicates what the code will > see in a real situation. I suspect this would be hard w/o a mock > ZooKeeper though. The more I think about it the more I feel we should > add such, to enable more/better client side unit testing/verification. > > Patrick > > On Wed, Jul 27, 2011 at 10:11 AM, Patrick Hunt <[email protected]> wrote: > > At this point I'm not sure you can reliably do so without > > https://issues.apache.org/jira/browse/ZOOKEEPER-829 > > > > Anyone? > > > > Patrick > > > > On Fri, Jul 22, 2011 at 6:17 AM, Will Johnson > > <[email protected]> wrote: > >> So give the ticket I created and ZOOKEEPER-710 how do i go about testing > >> session timeouts programmatically? > >> > >> On Fri, Jul 22, 2011 at 8:57 AM, Will Johnson > >> <[email protected]>wrote: > >> > >>> Created: https://issues.apache.org/jira/browse/ZOOKEEPER-1132 > >>> > >>> > >>> On Thu, Jul 21, 2011 at 6:25 PM, Patrick Hunt <[email protected]> > wrote: > >>> > >>>> I think the FAQ is out of date, iirc it's probably due to this change > >>>> https://issues.apache.org/jira/browse/ZOOKEEPER-710 > >>>> specifically > >>>> "the leader needs to drop the connection when it sees the MOVED error > >>>> so that the client can reestablish the session properly with another > >>>> machine" > >>>> which I believe you are seeing here. > >>>> > >>>> Also see this thread, there are other issues: > >>>> http://markmail.org/message/wqj347dlrsd74qya > >>>> > >>>> I would think though that zoo1 should eventually see the session > >>>> expiration - it will get disconnected but will then re-attempt to > >>>> connect to the server, at which point it will be notice the session is > >>>> expired. > >>>> > >>>> Would you mind entering a JIRA for this (to update the FAQ). Thanks! > >>>> > >>>> Patrick > >>>> > >>>> On Thu, Jul 21, 2011 at 1:36 PM, Will Johnson > >>>> <[email protected]> wrote: > >>>> > i'm trying to test SessionExpired based on the FAQ ( > >>>> > http://wiki.apache.org/hadoop/ZooKeeper/FAQ) can anyone point out > why > >>>> i'm > >>>> > getting ConnectionLoss exceptions instead of > SessionExpiredExceptions > >>>> based > >>>> > on the unit test below: > >>>> > > >>>> > @Test > >>>> > public void testSimpleConnection() throws Exception { > >>>> > String hostPort = "localhost:9999"; > >>>> > ZooKeeper zoo1 = new ZooKeeper(hostPort, 1000, null); > >>>> > > >>>> > // just make sure we can talk to zookeeper > >>>> > Assert.assertNull(zoo1.exists("/foo", false)); > >>>> > zoo1.create("/foo", null, Ids.OPEN_ACL_UNSAFE, > CreateMode.EPHEMERAL); > >>>> > Assert.assertNotNull(zoo1.exists("/foo", false)); > >>>> > > >>>> > // construct another client with the same id > >>>> > ZooKeeper zoo2 = new ZooKeeper(hostPort, > zoo1.getSessionTimeout(), > >>>> null, > >>>> > zoo1.getSessionId(), null); > >>>> > // closing this session should invalidate the first: > >>>> > http://wiki.apache.org/hadoop/ZooKeeper/FAQ > >>>> > zoo2.close(); > >>>> > > >>>> > // sleep just to make sure everything gets evicted > >>>> > Thread.sleep(zoo1.getSessionTimeout() * 2); > >>>> > > >>>> > // closing this session should invalidate the first: > >>>> > http://wiki.apache.org/hadoop/ZooKeeper/FAQ > >>>> > // this is where i always get ConnectionLoss instead of > >>>> SessionExpired > >>>> > Assert.assertNull(zoo1.exists("/foo", false)); > >>>> > > >>>> > } > >>>> > > >>>> > >>> > >>> > >> > > >
