List of usage examples for io.netty.channel DefaultEventLoop DefaultEventLoop
public DefaultEventLoop()
From source file:com.linecorp.armeria.client.endpoint.dns.DnsEndpointGroupBuilderTest.java
License:Apache License
@Test public void eventLoop() { assertThat(builder().eventLoop()).isNotNull(); final EventLoop loop = new NioEventLoopGroup().next(); assertThat(builder().eventLoop(loop).eventLoop()).isSameAs(loop); assertThatThrownBy(() -> builder().eventLoop(new DefaultEventLoop())) .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("unsupported"); }
From source file:com.linecorp.armeria.client.tracing.HttpTracingClientTest.java
License:Apache License
@Test public void testPutTraceData() { final ThriftCall req = new ThriftCall(0, HelloService.Iface.class, "hello", "Armeria"); final ClientRequestContext ctx = new DefaultClientRequestContext(new DefaultEventLoop(), SessionProtocol.H2C, Endpoint.of("localhost", 8080), "POST", "/", ClientOptions.DEFAULT, req); ctx.attr(ClientRequestContext.HTTP_HEADERS).set(otherHeaders()); client.putTraceData(ctx, req, testSpanId); HttpHeaders expectedHeaders = traceHeaders().add(otherHeaders()); assertThat(ctx.attr(ClientRequestContext.HTTP_HEADERS).get(), is(expectedHeaders)); }
From source file:com.linecorp.armeria.client.tracing.HttpTracingClientTest.java
License:Apache License
@Test public void testPutTraceDataIfSpanIsNull() { final ThriftCall req = new ThriftCall(0, HelloService.Iface.class, "hello", "Armeria"); final ClientRequestContext ctx = new DefaultClientRequestContext(new DefaultEventLoop(), SessionProtocol.H2C, Endpoint.of("localhost", 8080), "POST", "/", ClientOptions.DEFAULT, req); client.putTraceData(ctx, req, null); HttpHeaders expectedHeaders = traceHeadersNotSampled(); assertThat(ctx.attr(ClientRequestContext.HTTP_HEADERS).get(), is(expectedHeaders)); }
From source file:com.linecorp.armeria.client.tracing.TracingClientTest.java
License:Apache License
private static StubCollector testRemoteInvocationWithSamplingRate(float samplingRate) throws Exception { StubCollector spanCollector = new StubCollector(); Brave brave = new Brave.Builder(TEST_SERVICE).spanCollector(spanCollector) .traceSampler(Sampler.create(samplingRate)).build(); // prepare parameters final ThriftCall req = new ThriftCall(0, HelloService.Iface.class, "hello", "Armeria"); final ThriftReply res = new ThriftReply(0, "Hello, Armeria!"); final ClientRequestContext ctx = new DefaultClientRequestContext(new DefaultEventLoop(), SessionProtocol.H2C, Endpoint.of("localhost", 8080), "POST", "/", ClientOptions.DEFAULT, req); ctx.requestLogBuilder().start(mock(Channel.class), SessionProtocol.H2C, "localhost", "POST", "/"); ctx.requestLogBuilder().end();//from w ww . j a va2 s .c o m @SuppressWarnings("unchecked") Client<ThriftCall, ThriftReply> delegate = mock(Client.class); when(delegate.execute(any(), any())).thenReturn(res); TracingClientImpl stub = new TracingClientImpl(delegate, brave); // do invoke ThriftReply actualRes = stub.execute(ctx, req); assertThat(actualRes, is(res)); verify(delegate, times(1)).execute(ctx, req); return spanCollector; }
From source file:com.linecorp.armeria.client.tracing.TracingRemoteInvokerTest.java
License:Apache License
private static StubCollector testRemoteInvocationWithSamplingRate(float samplingRate) throws Exception { StubCollector spanCollector = new StubCollector(); Brave brave = new Brave.Builder(TEST_SERVICE).spanCollector(spanCollector) .traceSampler(Sampler.create(samplingRate)).build(); Future<Object> mockFut = mockFuture(); RemoteInvoker remoteInvoker = mock(RemoteInvoker.class); when(remoteInvoker.invoke(any(), any(), any(), any(), any(), any())).thenReturn(mockFut); TracingRemoteInvoker stub = new TracingRemoteInvokerImpl(remoteInvoker, brave); // prepare parameters EventLoop eventLoop = new DefaultEventLoop(); URI uri = new URI("http://xxx"); ClientOptions options = ClientOptions.of(); ClientCodec codec = mock(ClientCodec.class); Method method = getServiceMethod(); Object[] args = { "a", "b" }; // do invoke// w ww . j a v a2 s . co m Future<Object> resultFut = stub.invoke(eventLoop, uri, options, codec, method, args); assertThat(resultFut, is(mockFut)); verify(remoteInvoker, times(1)).invoke(eq(eventLoop), eq(uri), anyObject(), eq(codec), eq(method), eq(args)); return spanCollector; }
From source file:com.linecorp.armeria.common.RequestContextTest.java
License:Apache License
@Test public void contextAwareEventExecutor() throws Exception { EventLoop eventLoop = new DefaultEventLoop(); when(channel.eventLoop()).thenReturn(eventLoop); RequestContext context = createContext(); Set<Integer> callbacksCalled = new ConcurrentHashSet<>(); EventExecutor executor = context.contextAwareEventLoop(); CountDownLatch latch = new CountDownLatch(18); executor.execute(() -> checkCallback(1, context, callbacksCalled, latch)); executor.schedule(() -> checkCallback(2, context, callbacksCalled, latch), 0, TimeUnit.SECONDS); executor.schedule(() -> {/* ww w .j av a 2 s .co m*/ checkCallback(2, context, callbacksCalled, latch); return "success"; }, 0, TimeUnit.SECONDS); executor.scheduleAtFixedRate(() -> checkCallback(3, context, callbacksCalled, latch), 0, 1000, TimeUnit.SECONDS); executor.scheduleWithFixedDelay(() -> checkCallback(4, context, callbacksCalled, latch), 0, 1000, TimeUnit.SECONDS); executor.submit(() -> checkCallback(5, context, callbacksCalled, latch)); executor.submit(() -> checkCallback(6, context, callbacksCalled, latch), "success"); executor.submit(() -> { checkCallback(7, context, callbacksCalled, latch); return "success"; }); executor.invokeAll(makeTaskList(8, 10, context, callbacksCalled, latch)); executor.invokeAll(makeTaskList(11, 12, context, callbacksCalled, latch), 10000, TimeUnit.SECONDS); executor.invokeAny(makeTaskList(13, 13, context, callbacksCalled, latch)); executor.invokeAny(makeTaskList(14, 14, context, callbacksCalled, latch), 10000, TimeUnit.SECONDS); Promise<String> promise = executor.newPromise(); promise.addListener(f -> checkCallback(15, context, callbacksCalled, latch)); promise.setSuccess("success"); executor.newSucceededFuture("success").addListener(f -> checkCallback(16, context, callbacksCalled, latch)); executor.newFailedFuture(new IllegalArgumentException()) .addListener(f -> checkCallback(17, context, callbacksCalled, latch)); ProgressivePromise<String> progressivePromise = executor.newProgressivePromise(); progressivePromise.addListener(f -> checkCallback(18, context, callbacksCalled, latch)); progressivePromise.setSuccess("success"); latch.await(); eventLoop.shutdownGracefully().sync(); assertEquals(IntStream.rangeClosed(1, 18).boxed().collect(Collectors.toSet()), callbacksCalled); }
From source file:com.linecorp.armeria.common.stream.AbstractStreamMessageTest.java
License:Apache License
@BeforeClass public static void startEventLoop() { eventLoop = new DefaultEventLoop(); }
From source file:io.hekate.network.netty.NettyUtilsTest.java
License:Apache License
@Test public void testRunAtAllCost() throws Exception { EventLoop eventLoop = new DefaultEventLoop(); try {//from www . j a va 2s . c om // Check execution on event loop thread. Exchanger<Boolean> exchanger = new Exchanger<>(); NettyUtils.runAtAllCost(eventLoop, () -> { try { exchanger.exchange(eventLoop.inEventLoop()); } catch (InterruptedException e) { // No-op. } }); assertTrue(exchanger.exchange(null)); // Check execution on fallback thread if event loop is terminated. NettyUtils.shutdown(eventLoop).awaitUninterruptedly(); NettyUtils.runAtAllCost(eventLoop, () -> { try { exchanger.exchange(eventLoop.inEventLoop()); } catch (InterruptedException e) { // No-op. } }); assertFalse(exchanger.exchange(null)); } finally { NettyUtils.shutdown(eventLoop).awaitUninterruptedly(); } }