Search in sources :

Example 1 with BroadcasterListener

use of org.glassfish.jersey.server.BroadcasterListener in project jersey by jersey.

the class BroadcasterTest method testBroadcaster.

@Test
public void testBroadcaster() throws IOException {
    InputStream is1 = getChunkStream();
    InputStream is2 = getChunkStream();
    InputStream is3 = getChunkStream();
    InputStream is4 = getChunkStream();
    target("test").request().post(Entity.text("text1"));
    checkClosed(0);
    checkStream("firstChunktext1", is1, is2, is3, is4);
    outputs.remove(0).close();
    target("test").request().post(Entity.text("text2"));
    checkStream("text2", is2, is3, is4);
    checkClosed(1);
    outputs.remove(0).close();
    BroadcasterListener<String> bl = new BroadcasterListener<String>() {

        @Override
        public void onException(ChunkedOutput<String> stringChunkedResponse, Exception exception) {
        }

        @Override
        public void onClose(ChunkedOutput<String> stringChunkedResponse) {
            listenerClosed++;
        }
    };
    broadcaster.add(bl);
    target("test").request().post(Entity.text("text3"));
    checkClosed(2);
    assertEquals(1, listenerClosed);
    broadcaster.remove(bl);
    broadcaster.closeAll();
    checkClosed(4);
    assertEquals(1, listenerClosed);
    checkStream("text3", is3, is4);
}
Also used : InputStream(java.io.InputStream) BroadcasterListener(org.glassfish.jersey.server.BroadcasterListener) ChunkedOutput(org.glassfish.jersey.server.ChunkedOutput) IOException(java.io.IOException) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BroadcasterListener (org.glassfish.jersey.server.BroadcasterListener)1 ChunkedOutput (org.glassfish.jersey.server.ChunkedOutput)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1