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);
}
Aggregations