Search in sources :

Example 1 with AsyncIOWriterAdapter

use of org.atmosphere.cpr.AsyncIOWriterAdapter in project atmosphere by Atmosphere.

the class EncoderDecoderTest method testEncoder.

@Test
public void testEncoder() throws IOException, ServletException, InterruptedException {
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/h").method("GET").build();
    AtmosphereResponse response = AtmosphereResponseImpl.newInstance();
    final AtomicReference<String> ref = new AtomicReference();
    response.asyncIOWriter(new AsyncIOWriterAdapter() {

        @Override
        public AsyncIOWriter write(AtmosphereResponse r, byte[] data) throws IOException {
            ref.set(new String(data));
            return this;
        }
    });
    framework.doCometSupport(request, response);
    assertNotNull(r.get());
    latch.get().await(5, TimeUnit.SECONDS);
    r.get().resume();
    assertNotNull(message.get());
    assertEquals(message.get(), "message");
    assertEquals(ref.get(), "message-yo!");
}
Also used : AtmosphereRequestImpl(org.atmosphere.cpr.AtmosphereRequestImpl) AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsyncIOWriterAdapter(org.atmosphere.cpr.AsyncIOWriterAdapter) AsyncIOWriter(org.atmosphere.cpr.AsyncIOWriter) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Aggregations

IOException (java.io.IOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AsyncIOWriter (org.atmosphere.cpr.AsyncIOWriter)1 AsyncIOWriterAdapter (org.atmosphere.cpr.AsyncIOWriterAdapter)1 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)1 AtmosphereRequestImpl (org.atmosphere.cpr.AtmosphereRequestImpl)1 AtmosphereResponse (org.atmosphere.cpr.AtmosphereResponse)1 Test (org.testng.annotations.Test)1