Return-Path: X-Original-To: apmail-zookeeper-user-archive@www.apache.org Delivered-To: apmail-zookeeper-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8F2086E60 for ; Wed, 27 Jul 2011 18:05:42 +0000 (UTC) Received: (qmail 36488 invoked by uid 500); 27 Jul 2011 18:05:42 -0000 Delivered-To: apmail-zookeeper-user-archive@zookeeper.apache.org Received: (qmail 36446 invoked by uid 500); 27 Jul 2011 18:05:41 -0000 Mailing-List: contact user-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@zookeeper.apache.org Delivered-To: mailing list user@zookeeper.apache.org Received: (qmail 36430 invoked by uid 99); 27 Jul 2011 18:05:41 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jul 2011 18:05:41 +0000 Received: from localhost (HELO mail-qw0-f42.google.com) (127.0.0.1) (smtp-auth username phunt, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jul 2011 18:05:41 +0000 Received: by qwi4 with SMTP id 4so1012212qwi.15 for ; Wed, 27 Jul 2011 11:05:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.101.148 with SMTP id c20mr77769qco.195.1311789940013; Wed, 27 Jul 2011 11:05:40 -0700 (PDT) Received: by 10.229.17.74 with HTTP; Wed, 27 Jul 2011 11:05:39 -0700 (PDT) In-Reply-To: References: Date: Wed, 27 Jul 2011 11:05:39 -0700 Message-ID: Subject: Re: Testing SessionExipred based on FAQ From: Patrick Hunt To: user@zookeeper.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Jul 27, 2011 at 10:58 AM, Will Johnson wrote: > 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. =A0I 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. =A0Anything that can be d= one > 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. I agree. There are many corner cases (1->4 is actually possible, but unlikely) that would be good to verify a client, or clients, can handle. We probably need some combination of mock ZK client as well as a mock server in order to be able to cover more of these during client testing. Patrick > > On Wed, Jul 27, 2011 at 1:20 PM, Patrick Hunt 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 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 >> > wrote: >> >> So give the ticket I created and ZOOKEEPER-710 how do i go about test= ing >> >> session timeouts programmatically? >> >> >> >> On Fri, Jul 22, 2011 at 8:57 AM, Will Johnson >> >> wrote: >> >> >> >>> Created: https://issues.apache.org/jira/browse/ZOOKEEPER-1132 >> >>> >> >>> >> >>> On Thu, Jul 21, 2011 at 6:25 PM, Patrick Hunt >> wrote: >> >>> >> >>>> I think the FAQ is out of date, iirc it's probably due to this chan= ge >> >>>> https://issues.apache.org/jira/browse/ZOOKEEPER-710 >> >>>> specifically >> >>>> "the leader needs to drop the connection when it sees the MOVED err= or >> >>>> so that the client can reestablish the session properly with anothe= r >> >>>> 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 >> >>>> wrote: >> >>>> > i'm trying to test SessionExpired based on the FAQ ( >> >>>> > http://wiki.apache.org/hadoop/ZooKeeper/FAQ) =A0can anyone point = out >> why >> >>>> i'm >> >>>> > getting ConnectionLoss exceptions instead of >> SessionExpiredExceptions >> >>>> based >> >>>> > on the unit test below: >> >>>> > >> >>>> > @Test >> >>>> > =A0public void testSimpleConnection() throws Exception { >> >>>> > =A0 =A0String hostPort =3D "localhost:9999"; >> >>>> > =A0 =A0ZooKeeper zoo1 =3D new ZooKeeper(hostPort, 1000, null); >> >>>> > >> >>>> > =A0 =A0// just make sure we can talk to zookeeper >> >>>> > =A0 =A0Assert.assertNull(zoo1.exists("/foo", false)); >> >>>> > =A0 =A0zoo1.create("/foo", null, Ids.OPEN_ACL_UNSAFE, >> CreateMode.EPHEMERAL); >> >>>> > =A0 =A0Assert.assertNotNull(zoo1.exists("/foo", false)); >> >>>> > >> >>>> > =A0 =A0// construct another client with the same id >> >>>> > =A0 =A0ZooKeeper zoo2 =3D new ZooKeeper(hostPort, >> zoo1.getSessionTimeout(), >> >>>> null, >> >>>> > zoo1.getSessionId(), null); >> >>>> > =A0 =A0// closing this session should invalidate the first: >> >>>> > http://wiki.apache.org/hadoop/ZooKeeper/FAQ >> >>>> > =A0 =A0zoo2.close(); >> >>>> > >> >>>> > =A0 =A0// sleep just to make sure everything gets evicted >> >>>> > =A0 =A0Thread.sleep(zoo1.getSessionTimeout() * 2); >> >>>> > >> >>>> > =A0 =A0// closing this session should invalidate the first: >> >>>> > http://wiki.apache.org/hadoop/ZooKeeper/FAQ >> >>>> > =A0 =A0// this is where i always get ConnectionLoss instead of >> >>>> SessionExpired >> >>>> > =A0 =A0Assert.assertNull(zoo1.exists("/foo", false)); >> >>>> > >> >>>> > =A0} >> >>>> > >> >>>> >> >>> >> >>> >> >> >> > >> >