当前位置: 首页>>代码示例>>Java>>正文


Java DefaultChannelPromise.setFailure方法代码示例

本文整理汇总了Java中io.netty.channel.DefaultChannelPromise.setFailure方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultChannelPromise.setFailure方法的具体用法?Java DefaultChannelPromise.setFailure怎么用?Java DefaultChannelPromise.setFailure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.DefaultChannelPromise的用法示例。


在下文中一共展示了DefaultChannelPromise.setFailure方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIdentifyWhenWriteFailsAndChannelIsActiveClosesChannelAndThrows

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test(expected = RuntimeException.class)
public void testIdentifyWhenWriteFailsAndChannelIsActiveClosesChannelAndThrows() throws Exception {
    DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.setFailure(new IOException("test"));

    when(channel.writeAndFlush(any())).thenReturn(promise);
    when(channel.isActive()).thenReturn(true);
    when(channel.close()).thenReturn(promise);

    Admin admin = new Admin();
    admin.setBoxId("test");
    admin.setAdminCommand(AdminCommand.IDENTIFY);

    try {
        clientSession.identify(admin);
    } finally {
        verify(channel).writeAndFlush(admin);
        verify(channel).close();

        assertTrue(clientSession.isClosed());
    }
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:23,代码来源:ClientSessionTest.java

示例2: testIdentifyWhenWriteFailsAndChannelIsInactiveSetsClosedState

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test(expected = RuntimeException.class)
public void testIdentifyWhenWriteFailsAndChannelIsInactiveSetsClosedState() throws Exception {
    DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.setFailure(new IOException("test"));

    when(channel.writeAndFlush(any())).thenReturn(promise);
    when(channel.isActive()).thenReturn(false);

    Admin admin = new Admin();
    admin.setBoxId("test");
    admin.setAdminCommand(AdminCommand.IDENTIFY);

    try {
        clientSession.identify(admin);
    } finally {
        verify(channel).writeAndFlush(admin);
        verify(channel, times(0)).close();

        assertTrue(clientSession.isClosed());
    }
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:22,代码来源:ClientSessionTest.java

示例3: testSendSmsAndWaitThrowsWhenWriteFails

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testSendSmsAndWaitThrowsWhenWriteFails() throws Exception {
    DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.setFailure(new IOException());

    when(channel.writeAndFlush(any())).thenReturn(promise);

    Sms sms = new Sms();
    sms.setId(UUID.randomUUID());
    sms.setBoxId("test box");

    try {
        clientSession.sendSmsAndWait(sms, 5000);
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IOException);
    }
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:18,代码来源:ClientSessionTest.java

示例4: assertExceptionsFiredOnFailure

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
private void assertExceptionsFiredOnFailure() throws Exception {
  // get the listener added when the channel was written to
  ArgumentCaptor<ChannelFutureListener> captor = ArgumentCaptor.forClass(ChannelFutureListener.class);
  verify(writeFuture, atLeast(1)).addListener(captor.capture());
  ChannelFutureListener addedListener = captor.getValue();

  // tell the listener the write failed
  DefaultChannelPromise promise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
  promise.setFailure(new Exception());
  addedListener.operationComplete(promise);

  verify(pipeline).fireExceptionCaught(promise.cause());
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:14,代码来源:SmtpSessionTest.java

示例5: testSendSmsReturnsFailedFutureWhenWriteFails

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test(expected = IOException.class)
public void testSendSmsReturnsFailedFutureWhenWriteFails() throws Exception {
    DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.setFailure(new IOException());

    when(channel.writeAndFlush(any())).thenReturn(promise);

    Sms sms = new Sms();
    sms.setId(UUID.randomUUID());
    sms.setBoxId("test box");

    WindowFuture<Sms, Ack> future = clientSession.sendSms(sms, 5000);

    Futures.getChecked(future, IOException.class);
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:16,代码来源:ClientSessionTest.java

示例6: testEncodeMethodCallFailure

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testEncodeMethodCallFailure() throws InvalidProtocolBufferException,
    InterruptedException {
  Channel channel = Mockito.mock(Channel.class);
  ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);

  DefaultChannelPromise failure = new DefaultChannelPromise(
      channel, ImmediateEventExecutor.INSTANCE);
  failure.setFailure(new Exception("OMGWTF"));
  Mockito.when(channel.writeAndFlush(captor.capture())).thenReturn(failure);

  RpcClientHandler handler = new RpcClientHandler();
  RpcClient client = new RpcClient(channel, handler, new NullClientLogger());

  ClientMethod<TimeResponse> method = Mockito.mock(ClientMethod.class);
  Mockito.when(method.serviceName()).thenReturn("TimeService");
  Mockito.when(method.name()).thenReturn("GetTime");
  Mockito.when(method.outputParser()).thenReturn(TimeResponse.PARSER);

  final CountDownLatch latch = new CountDownLatch(1);
  FutureCallback<TimeResponse> callback = new FutureCallback<TimeResponse>() {
    @Override
    public void onSuccess(@Nullable TimeResponse result) {
    }

    @Override
    public void onFailure(Throwable t) {
      Assert.assertEquals("OMGWTF", t.getMessage());
      latch.countDown();
    }
  };

  ListenableFuture<TimeResponse> future = client.encodeMethodCall(
      method, TimeRequest.newBuilder().setTimezone("UTC").build());

  Futures.addCallback(future, callback);
  latch.await(5, TimeUnit.SECONDS);

  Assert.assertEquals(0, handler.inFlightRequests().size());
}
 
开发者ID:jsilland,项目名称:piezo,代码行数:41,代码来源:RpcClientTest.java

示例7: testEncodeMethodCallFailure

import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testEncodeMethodCallFailure() throws InvalidProtocolBufferException,
    InterruptedException {
  Channel channel = Mockito.mock(Channel.class);

  Mockito.when(channel.remoteAddress()).thenReturn(
      new InetSocketAddress(InetAddress.getLoopbackAddress(), 10000));

  ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);

  DefaultChannelPromise failure = new DefaultChannelPromise(
      channel, ImmediateEventExecutor.INSTANCE);
  failure.setFailure(new Exception("OMGWTF"));
  Mockito.when(channel.writeAndFlush(captor.capture())).thenReturn(failure);

  JsonRpcClientHandler handler = new JsonRpcClientHandler();
  HttpJsonRpcClient client = new HttpJsonRpcClient(channel, handler, "/rpc",
      new NullClientLogger());

  ClientMethod<TimeResponse> method = Mockito.mock(ClientMethod.class);
  Mockito.when(method.serviceName()).thenReturn("TimeService");
  Mockito.when(method.name()).thenReturn("GetTime");
  Mockito.when(method.outputParser()).thenReturn(TimeResponse.PARSER);

  final CountDownLatch latch = new CountDownLatch(1);
  FutureCallback<TimeResponse> callback = new FutureCallback<TimeResponse>() {
    @Override
    public void onSuccess(@Nullable TimeResponse result) {
    }

    @Override
    public void onFailure(Throwable t) {
      Assert.assertEquals("OMGWTF", t.getMessage());
      latch.countDown();
    }
  };

  ListenableFuture<TimeResponse> future = client.encodeMethodCall(
      method, TimeRequest.newBuilder().setTimezone("UTC").build());

  Futures.addCallback(future, callback);
  latch.await(5, TimeUnit.SECONDS);

  Assert.assertEquals(0, handler.inFlightRequests().size());
}
 
开发者ID:jsilland,项目名称:piezo,代码行数:46,代码来源:HttpJsonRpcClientTest.java


注:本文中的io.netty.channel.DefaultChannelPromise.setFailure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。