Skip to content

Netty concurrent.ExecutionException #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
survivant opened this issue May 14, 2012 · 2 comments
Closed

Netty concurrent.ExecutionException #107

survivant opened this issue May 14, 2012 · 2 comments

Comments

@survivant
Copy link

FAILED: loginDuplicateUsernameXHRPollingTest
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: invalid version format: 6B
at com.ning.http.client.providers.netty.NettyResponseFuture.abort(NettyResponseFuture.java:297)
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.abort(NettyAsyncHttpProvider.java:1315)
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.exceptionCaught(NettyAsyncHttpProvider.java:1531)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:117)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:777)
at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleUpstream(ChunkedWriteHandler.java:143)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:777)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:117)
at org.jboss.netty.handler.codec.http.HttpClientCodec.handleUpstream(HttpClientCodec.java:72)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:553)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.DefaultChannelPipeline.notifyHandlerException(DefaultChannelPipeline.java:645)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:560)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:553)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

@survivant
Copy link
Author

here my use case (client side.)  (same usecase for issue 107 108 109)

@Test(groups = {"standalone", "default_provider"})
    public void loginDuplicateUsernameXHRPollingTest() throws Throwable {
        final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());

        final String sessionid1 = getSessionID(client, GET_SESSION_URL);

        final String username = "test_" + System.currentTimeMillis();

        // maintenant on fait login
        login("clientXHRPolling1", client, GET_SESSION_URL+"xhr-polling/" + sessionid1, username, true);

        final AsyncHttpClient client2 = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());

        final String sessionid2 = getSessionID(client, GET_SESSION_URL);

        // maintenant on fait login
        login("clientXHRPolling2", client2, GET_SESSION_URL+"xhr-polling/" + sessionid2, username, false);

        client.close();
        client2.close();
    }


public static AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) {
        if (config == null) {
            config = new AsyncHttpClientConfig.Builder().build();
        }
        //return new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config);
        return new AsyncHttpClient(new NettyAsyncHttpProvider(config), config);
    }

public static String getSessionID(AsyncHttpClient client, String url) throws Throwable {

        final CountDownLatch l = new CountDownLatch(1);
        final AtomicReference<String> sessionid = new AtomicReference<String>();

        // on va chercher une sessionID
        client.prepareGet(url).execute(new AsyncCompletionHandlerAdapter() {

            @Override
            public Response onCompleted(Response response) throws Exception {
                try {
                    String body = response.getResponseBody();
                    String array[] = body.split(":");
                    sessionid.set(array[0]);
                } finally {
                    l.countDown();
                }
                return response;
            }
        }).get();

        if (!l.await(TIMEOUT, TimeUnit.SECONDS)) {
            throw new RuntimeException("Timeout out");
        }

        return sessionid.get();
    }

protected void login(final String name, final AsyncHttpClient client, final String url, final String username, final boolean usernameUnique) throws Throwable{
        final CountDownLatch latchGet = new CountDownLatch(2);
        //final CountDownLatch latchGet2 = new CountDownLatch(1);
        final CountDownLatch latchPost = new CountDownLatch(1);

        // fait un connect
        connect(name, client, url);

        //suspend une connection
        suspend(name, client, url, new ResponseListener() {
            @Override
            public void notify(String message) {
                log.info("GET login message received = " + message);

                Assert.assertNotNull(message);

                if(!message.equals("2::")){
                    latchGet.countDown();

                    if(message.charAt(0)==(byte)SocketIOPacketImpl.SOCKETIO_MSG_DELIMITER){
                        System.err.println("Multi-message");
                    }

                    // LOGIN
                    if(latchGet.getCount()==1){
                        if(usernameUnique){
                            //Assert.assertEquals(message, "6:::1+[false]");
                            Assert.assertTrue(message.contains("6:::1+[false]"));
                        } else {
                            //Assert.assertEquals(message, "6:::1+[true]");
                            Assert.assertTrue(message.contains("6:::1+[true]"));
                        }

                    } else {
                        // la liste des users connectes
                        Assert.assertTrue(message.contains("5:::{\"name\":\"nicknames\",\"args\":[{"));
                        //Assert.assertTrue(message.contains("\"" + username + "\":\"" + username + "\""));
                        Assert.assertTrue(message.contains("\"" + username + "\""));
                    }
                }

            } 
        });

        // maintenant on fait login
        sendMessage(name, client, url, "5:1+::{\"name\":\"nickname\",\"args\":[\"" + username + "\"]}", new ResponseListener() {

            boolean found = false;

            @Override
            public void notify(String message) {
                log.info("POST login message received = " + message);
                latchPost.countDown();
                Assert.assertNotNull(message);
                Assert.assertEquals(message, "1");
            }
        });

        if (!latchGet.await(30, TimeUnit.SECONDS)) {
            throw new RuntimeException("Timeout out 1");
        }
        /*
        if (!latchGet2.await(30, TimeUnit.SECONDS)) {

            throw new RuntimeException("Timeout out 2");
        }
        */

        if (!latchPost.await(30, TimeUnit.SECONDS)) {
            throw new RuntimeException("Timeout out 3");
        }
    }

protected void connect(String name, final AsyncHttpClient client, final String url) throws Throwable {
        final CountDownLatch l = new CountDownLatch(1);

        // fait un connect
        suspend(name, client, url, new ResponseListener() {

            @Override
            public void notify(String message) {
                log.info("Connect message received = " + message);
                l.countDown();
                Assert.assertNotNull(message);
                Assert.assertEquals(message, "1::");
            }
        });

        if (!l.await(30, TimeUnit.SECONDS)) {
            throw new RuntimeException("Timeout out");
        }

    }

public static void suspend(final String name, final AsyncHttpClient client, final String url, final ResponseListener listener) throws Throwable {

        System.err.println("Name = " + name + " go in suspend mode");

        Thread t = new Thread() {
            public void run() {
                try {
                    // 
                    client.prepareGet(url).execute(new AsyncCompletionHandlerAdapter() {

                        @Override
                        public com.ning.http.client.AsyncHandler.STATE onBodyPartReceived( HttpResponseBodyPart content) throws Exception {
                            try {
                                String body = new String(content.getBodyPartBytes());
                                System.err.println("suspend Name = " + name + " onBodyPartReceived=" + body);

                                if(listener!=null){
                                    listener.notify(body);
                                } else {
                                    System.err.println("Listner null name=" + name);
                                }

                            } finally {
                            }
                            return super.onBodyPartReceived(content);
                        }

                        @Override
                        public Response onCompleted(Response response) throws Exception {
                            try {
                                String body = response.getResponseBody();
                                System.err.println("suspend Name = " + name + " Body=" + body);
                                if(listener!=null){
                                    listener.notify(body);
                                }
                            } finally {
                            }
                            return response;
                        }
                    }).get();

                } catch (InterruptedException e1) {
                } catch (Exception e) {
                    e.printStackTrace();
                    Assert.fail();
                }
            }
        };

        t.start();

    }

@slandelle
Copy link
Contributor

Will reopen if needed.

cs-workco pushed a commit to cs-workco/async-http-client that referenced this issue Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants