use of java.util.concurrent.ArrayBlockingQueue in project components by Talend.
the class CouchbaseStreamingConnectionTest method testStartStreaming.
@Test
public void testStartStreaming() throws InterruptedException {
Mockito.when(client.initializeState(StreamFrom.BEGINNING, StreamTo.NOW)).thenReturn(Completable.complete());
Mockito.when(client.startStreaming(Mockito.<Short[]>anyVararg())).thenReturn(Completable.complete());
SessionState sessionState = Mockito.mock(SessionState.class);
Mockito.when(sessionState.isAtEnd()).thenReturn(false, false, true);
Mockito.when(client.sessionState()).thenReturn(sessionState);
BlockingQueue<ByteBuf> resultsQueue = new ArrayBlockingQueue<>(3);
streamingConnection.startStreaming(resultsQueue);
Assert.assertTrue(streamingConnection.isStreaming());
Thread.sleep(2000);
Mockito.verify(client, Mockito.times(3)).sessionState();
}
use of java.util.concurrent.ArrayBlockingQueue in project photon-model by vmware.
the class AWSImageEnumerationAdapterService method allocateExecutor.
/**
* Creates an executor specific to AWS public images enum, which by default is single threaded
* with a queue of size 20.
*/
private ExecutorService allocateExecutor() {
final int corePoolSize = 1;
// By default returns 1, so effectively we have single threaded executor;
// otherwise the pool size varies
final int imagesMaxConcurrentEnums = getImagesMaxConcurrentEnums();
final long keepAliveTime = 0L;
final TimeUnit unit = TimeUnit.MILLISECONDS;
// Use queue with size 20, which is close to AWS regions count
final BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(20);
ThreadFactory tFactory = r -> new Thread(r, "/" + getUri() + "/" + Utils.getSystemNowMicrosUtc());
return new ThreadPoolExecutor(corePoolSize, imagesMaxConcurrentEnums, keepAliveTime, unit, workQueue, tFactory);
}
use of java.util.concurrent.ArrayBlockingQueue in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorInteractionSuccessAsHttpReuseChannel.
@Test(timeout = 5000)
public void testInitiatorInteractionSuccessAsHttpReuseChannel() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, Feature.ENABLE_LOGGING);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), Feature.ENABLE_LOGGING);
assertEquals(0, allActiveAllocationsCount(allocator));
try {
final Channel ch1 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), standardInteraction(allocator, trades)).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
final Channel ch2 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), standardInteraction(allocator, trades)).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
assertSame(ch1, ch2);
} finally {
client.close();
server.unsubscribe();
}
}
use of java.util.concurrent.ArrayBlockingQueue in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorInteractionNo1NotSendNo2SuccessReuseChannelAsHttps.
@Test(timeout = 5000)
public void testInitiatorInteractionNo1NotSendNo2SuccessReuseChannelAsHttps() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, enableSSL4ServerWithSelfSigned(), Feature.ENABLE_LOGGING_OVER_SSL);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), enableSSL4Client(), Feature.ENABLE_LOGGING_OVER_SSL);
assertEquals(0, allActiveAllocationsCount(allocator));
try {
final Channel ch1 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.<HttpObject>error(new RuntimeException("test error")), new Interaction() {
@Override
public void interact(final HttpInitiator initiator, final Observable<DisposableWrapper<FullHttpResponse>> getresp) throws Exception {
final TestSubscriber<DisposableWrapper<FullHttpResponse>> subscriber = new TestSubscriber<>();
getresp.subscribe(subscriber);
subscriber.awaitTerminalEvent();
subscriber.assertError(RuntimeException.class);
subscriber.assertNoValues();
}
}).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
final Channel ch2 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), standardInteraction(allocator, trades)).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
assertSame(ch1, ch2);
} finally {
client.close();
server.unsubscribe();
}
}
use of java.util.concurrent.ArrayBlockingQueue in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorMultiInteractionSuccessAsHttp.
@Test(timeout = 5000)
public void testInitiatorMultiInteractionSuccessAsHttp() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
assertEquals(0, allActiveAllocationsCount(allocator));
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, Feature.ENABLE_LOGGING);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), Feature.ENABLE_LOGGING);
try (final HttpInitiator initiator = client.initiator().remoteAddress(new LocalAddress(addr)).build().toBlocking().single()) {
{
final Observable<? extends DisposableWrapper<HttpObject>> cached = initiator.defineInteraction(Observable.just(fullHttpRequest())).cache();
cached.subscribe();
// server side recv req
final HttpTrade trade = trades.take();
// recv all request
trade.inbound().toCompletable().await();
assertEquals(0, allActiveAllocationsCount(allocator));
final ByteBuf svrRespContent = allocator.buffer(CONTENT.length).writeBytes(CONTENT);
// send back resp
trade.outbound(TestHttpUtil.buildByteBufResponse("text/plain", svrRespContent));
// wait for recv all resp at client side
cached.toCompletable().await();
svrRespContent.release();
assertTrue(Arrays.equals(dumpResponseContentAsBytes(cached.compose(RxNettys.message2fullresp(initiator))), CONTENT));
cached.doOnNext(DISPOSE_EACH).toCompletable().await();
}
assertEquals(0, allActiveAllocationsCount(allocator));
{
final Observable<? extends DisposableWrapper<HttpObject>> cached = initiator.defineInteraction(Observable.just(fullHttpRequest())).cache();
final Observable<HttpObject> resp2 = cached.map(DisposableWrapperUtil.<HttpObject>unwrap());
resp2.subscribe();
// server side recv req
final HttpTrade trade = trades.take();
// recv all request
trade.inbound().toCompletable().await();
// assertEquals(0, allActiveAllocationsCount(allocator));
final ByteBuf svrRespContent = allocator.buffer(CONTENT.length).writeBytes(CONTENT);
// send back resp
trade.outbound(TestHttpUtil.buildByteBufResponse("text/plain", svrRespContent));
// wait for recv all resp at client side
resp2.toCompletable().await();
svrRespContent.release();
assertTrue(Arrays.equals(dumpResponseContentAsBytes(cached.compose(RxNettys.message2fullresp(initiator))), CONTENT));
}
} finally {
assertEquals(0, allActiveAllocationsCount(allocator));
client.close();
server.unsubscribe();
}
}
Aggregations