Michael Ossareh wrote:
I've uncovered what I believe to be a problem in the framework of
MINA. I'm using 2.0.0-m5. As it currently stands any classes that
subclass IoHandlerAdapter are crippled by the methods throwing
Exception and the framework catching it. In my case I cannot write
JUnit test cases because the Exception thrown by Assert.fail() is
caught up in the framework therefore not allowing me to verify
failures.

Dev's Is there a strong reason for this? Exceptions need to take place
in business logic, not just test cases, and right now they cannot.
These methods, I feel, shouldn't have Exception in their method def.
Perhaps a subclass of Exception such as BusinessException or something
which we can treat differently?

Perhaps I've missed something? Is there some part of the filter chain
that you can add an exception handler? That only unhandled exceptions
then result in bubbling to the top?

Thoughts? Depending what we come up with I'm happy to implement a fix.

Cheers,

mike

Can you elaborate (or give an example) of exactly what the problem is? I've written numerous junit tests for my MINA server, though I suppose I did have to do it in a somewhat roundabout way: I sent a simulated received message down the filter chain, and then verify that it triggers sending a particular response. Code attached.

HTH,

DR

----

public class TestTextProtocolHandler extends TestCase {
        protected void setUp() throws IOException {
...
                session = new DummySession();
                session.setHandler(new TextProtocolHandler(serverControl, 
cacheNode));
                filterChain = session.getFilterChain();
                outputListener = new OutputListener();
                filterChain.addLast("listener", outputListener);
        }
...
public void testQuery() throws IOException, InterruptedException, ExecutionException {
...
                filterChain.fireMessageReceived("query 1234/I");
                ProtocolResponse response = outputListener.getResponse();
                assertTrue(response.isSuccess());
AssertHelper.assertNotNullOrEmpty(TextProtocolHandler.argsToString(response.getArgs(), unsquasher));
        }
...
}

class OutputListener extends IoFilterAdapter {

public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) {
                String responseStr = (String) writeRequest.getMessage();
                response = 
TextProtocolHandler.protocolResponseFromString(responseStr);
                nextFilter.messageSent(session, writeRequest);
        }       

        public ProtocolResponse getResponse() {
                return response;
        }

        private ProtocolResponse response;
}

Reply via email to