use of org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider in project jersey by jersey.
the class ChunkedInputOutputITCase method configureClient.
@Override
protected void configureClient(final ClientConfig config) {
config.register(App.createMoxyJsonResolver());
config.property(ClientProperties.CONNECT_TIMEOUT, 15000).property(ClientProperties.READ_TIMEOUT, 5000).property(ClientProperties.ASYNC_THREADPOOL_SIZE, MAX_LISTENERS + 1).connectorProvider(new GrizzlyConnectorProvider());
}
use of org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider in project jersey by jersey.
the class EventOutputTest method testGrizzlyConnectorWithEventSource.
@Test
public void testGrizzlyConnectorWithEventSource() throws InterruptedException {
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 15000);
clientConfig.property(ClientProperties.READ_TIMEOUT, 0);
clientConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 8);
clientConfig.connectorProvider(new GrizzlyConnectorProvider());
Client client = ClientBuilder.newBuilder().withConfig(clientConfig).build();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> eventData = new AtomicReference<String>();
final AtomicInteger counter = new AtomicInteger(0);
WebTarget single = client.target(getBaseUri()).path("test/single");
EventSource es = EventSource.target(single).build();
es.register(new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
final int i = counter.incrementAndGet();
if (i == 1) {
eventData.set(inboundEvent.readData());
}
latch.countDown();
}
});
boolean latchTimedOut;
boolean closeTimedOut;
try {
es.open();
latchTimedOut = latch.await(5 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS);
} finally {
closeTimedOut = es.close(5, TimeUnit.SECONDS);
}
assertEquals("Unexpected event count", 1, counter.get());
assertEquals("Unexpected event data", "single", eventData.get());
assertTrue("Event latch has timed out", latchTimedOut);
assertTrue("EventSource.close() has timed out", closeTimedOut);
}
use of org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider in project jersey by jersey.
the class EventOutputTest method testReadCommentsOnlySseEvents.
/**
* Reproducer for JERSEY-2912: Sending and receiving comments-only events.
*
* @throws Exception
*/
@Test
public void testReadCommentsOnlySseEvents() throws Exception {
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 15000);
clientConfig.property(ClientProperties.READ_TIMEOUT, 0);
clientConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 8);
clientConfig.connectorProvider(new GrizzlyConnectorProvider());
Client client = ClientBuilder.newBuilder().withConfig(clientConfig).build();
final CountDownLatch latch = new CountDownLatch(2);
final Queue<String> eventComments = new ArrayBlockingQueue<>(2);
WebTarget single = client.target(getBaseUri()).path("test/comments-only");
EventSource es = EventSource.target(single).build();
es.register(new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
eventComments.add(inboundEvent.getComment());
latch.countDown();
}
});
boolean latchTimedOut;
boolean closeTimedOut;
try {
es.open();
latchTimedOut = latch.await(5 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS);
} finally {
closeTimedOut = es.close(5, TimeUnit.SECONDS);
}
assertEquals("Unexpected event count", 2, eventComments.size());
for (int i = 1; i <= 2; i++) {
assertEquals("Unexpected comment data on event #" + i, "No comment #" + i, eventComments.poll());
}
assertTrue("Event latch has timed out", latchTimedOut);
assertTrue("EventSource.close() has timed out", closeTimedOut);
}
Aggregations