Search in sources :

Example 1 with AsyncIOWriterAdapter

use of org.atmosphere.runtime.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.runtime.AtmosphereRequestImpl) AtmosphereResponse(org.atmosphere.runtime.AtmosphereResponse) AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsyncIOWriterAdapter(org.atmosphere.runtime.AsyncIOWriterAdapter) AsyncIOWriter(org.atmosphere.runtime.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.runtime.AsyncIOWriter)1 AsyncIOWriterAdapter (org.atmosphere.runtime.AsyncIOWriterAdapter)1 AtmosphereRequest (org.atmosphere.runtime.AtmosphereRequest)1 AtmosphereRequestImpl (org.atmosphere.runtime.AtmosphereRequestImpl)1 AtmosphereResponse (org.atmosphere.runtime.AtmosphereResponse)1 Test (org.testng.annotations.Test)1