Barrie Treloar wrote:
I'm a bit worried about the comments in this method for
AbstractTrafficControlTest:

    public void testSuspendResumeReadWrite() throws Exception {
        ConnectFuture future = connect(port, new ClientIoHandler());
        future.awaitUninterruptibly();
        IoSession session = future.getSession();

        // We wait for the sessionCreated() event is fired because we
        // cannot guarantee that it is invoked already.
        while (session.getAttribute("lock") == null) {
            Thread.yield();
        }

Why can't this be used?
        while (!session.isConnected()) {
            Thread.yield();
        }

Or why isn't there a Future with an awaitUninterruptibly() on it to
ensure the connection has been created.

The lock attribute is created in the test client handler. If the test
code shows the correct behaviour for handling session creation then
that means all client handlers need to implement it and that feels
messy.

What's the correct way of doing this?
It's a bit tricky :

the session can be connected, but the sessionCreated event might not be called yet. As we need to get the 'lock' object which is injected into the session to run the test, we have to wait for the sessionCreated to be executed (because this is the place where this lock is added to the session).

Now, the session.isConnected() method is a bit crippled. It's set to false when the session is closed (and it can take some time, as many listeners may be called and we will wait for their completion), but there is no place where the session is set to connected. It's simply considered as connected unless it's closed. o there are some race condition where the session will be considered as connected, even if all the initialization is not done (typically, if we are waiting for this 'lock' to be stored into the session), which may make the test fail.

Sounds crazy, but trust me, this part of the code is more insane than I am :)

PS : I'm pretty sure that a better session state mechanism could be implemented. It sound totally crazy that a session is considered to be "connected" simply because it's not closed. At least two new states should be added ( "Initializing" and "connected").


--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to