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


Java DefaultChannelPromise类代码示例

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


DefaultChannelPromise类属于io.netty.channel包,在下文中一共展示了DefaultChannelPromise类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testDestroysClosesChannelAndDestroysTheWindow

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

    when(channel.isActive()).thenReturn(false);
    when(channel.close()).thenReturn(promise);

    WindowFuture windowFuture = clientSession.getWindow().offer(UUID.randomUUID(), new Sms(), 5000);
    clientSession.destroy();

    verify(channel, times(0)).close();
    assertNull("Session handler must be null after destruction", clientSession.getSessionHandler());
    assertTrue("The outstanding requests should be canceled", windowFuture.isCancelled());

}
 
开发者ID:spapageo,项目名称:jannel,代码行数:17,代码来源:ClientSessionTest.java

示例4: testSendSmsReturnsFailedFutureWhenOfferToWindowFails

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

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

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

    //add the sms so the next offer fails
    clientSession.getWindow().offer(sms.getId(), sms, 5000);

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

    assertSame(sms, future.getRequest());

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

示例5: testSendSmsAndWaitReturnsCorrectResponse

import io.netty.channel.DefaultChannelPromise; //导入依赖的package包/类
@Test
public void testSendSmsAndWaitReturnsCorrectResponse() throws Exception {
    final DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.setSuccess();

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

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

    final Ack expectedResponse = new Ack();

    scheduledExecutorService.schedule(new Runnable() {
        @Override
        public void run() {
            clientSession.getWindow().complete(sms.getId(), expectedResponse);
        }
    }, 100, TimeUnit.MILLISECONDS);

    final Ack response = clientSession.sendSmsAndWait(sms, 5000);
    assertSame(expectedResponse, response);
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:24,代码来源:ClientSessionTest.java

示例6: testSendSmsAndWaitThrowsWhenOfferToWindowFails

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

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

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

    //add the sms so the next offer fails
    clientSession.getWindow().offer(sms.getId(), sms, 5000);

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

示例7: 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

示例8: testChannelPromiseWithValidExecutor

import io.netty.channel.DefaultChannelPromise; //导入依赖的package包/类
/**
 * Validates successful {@link WebSessionResources#close()} with valid CloseFuture and other parameters.
 * @throws Exception
 */
@Test
public void testChannelPromiseWithValidExecutor() throws Exception {
  try {
    EventExecutor mockExecutor = mock(EventExecutor.class);
    ChannelPromise closeFuture = new DefaultChannelPromise(null, mockExecutor);
    webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock
        (UserSession.class), closeFuture);
    webSessionResources.close();
    verify(webSessionResources.getAllocator()).close();
    verify(webSessionResources.getSession()).close();
    verify(mockExecutor).inEventLoop();
    verify(mockExecutor).execute(any(Runnable.class));
    assertTrue(webSessionResources.getCloseFuture() == null);
    assertTrue(!listenerComplete);
  } catch (Exception e) {
    fail();
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:23,代码来源:WebSessionResourcesTest.java

示例9: testDoubleClose

import io.netty.channel.DefaultChannelPromise; //导入依赖的package包/类
/**
 * Validates double call to {@link WebSessionResources#close()} doesn't throw any exception.
 * @throws Exception
 */
@Test
public void testDoubleClose() throws Exception {
  try {
    ChannelPromise closeFuture = new DefaultChannelPromise(null, mock(EventExecutor.class));
    webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock
        (UserSession.class), closeFuture);
    webSessionResources.close();

    verify(webSessionResources.getAllocator()).close();
    verify(webSessionResources.getSession()).close();
    assertTrue(webSessionResources.getCloseFuture() == null);

    webSessionResources.close();
  } catch (Exception e) {
    fail();
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:22,代码来源:WebSessionResourcesTest.java

示例10: itClosesTheUnderlyingChannel

import io.netty.channel.DefaultChannelPromise; //导入依赖的package包/类
@Test
public void itClosesTheUnderlyingChannel() {
  DefaultChannelPromise channelPromise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
  when(channel.close()).thenReturn(channelPromise);

  CompletableFuture<Void> f = session.close();
  channelPromise.setSuccess();

  assertThat(f.isDone());
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:11,代码来源:SmtpSessionTest.java

示例11: 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

示例12: resetChannel

import io.netty.channel.DefaultChannelPromise; //导入依赖的package包/类
/** Reset the channel mock and set basic method call expectations */
void resetChannel() {
	reset(channel);
	expect(channel.newPromise()).andAnswer(new IAnswer<ChannelPromise>() {
		@Override
		public ChannelPromise answer() throws Throwable {
			return new DefaultChannelPromise(channel);
		}
	}).anyTimes();
	eventLoop = new TestEventLoop();
	expect(channel.eventLoop()).andReturn(eventLoop).anyTimes();
	expect(channel.pipeline()).andReturn(pipeline).anyTimes();
	expect(channel.remoteAddress()).andReturn(null).anyTimes();
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:15,代码来源:OFChannelHandlerVer13Test.java

示例13: resetChannel

import io.netty.channel.DefaultChannelPromise; //导入依赖的package包/类
/** Reset the channel mock and set basic method call expectations */
  void resetChannel() {
      reset(channel);
      expect(channel.newPromise()).andAnswer(new IAnswer<ChannelPromise>() {
	@Override
	public ChannelPromise answer() throws Throwable {
		return new DefaultChannelPromise(channel);
	}
}).anyTimes();
eventLoop = new TestEventLoop();
expect(channel.eventLoop()).andReturn(eventLoop).anyTimes();
      expect(channel.pipeline()).andReturn(pipeline).anyTimes();
      expect(channel.remoteAddress()).andReturn(InetSocketAddress.createUnresolved("1.1.1.1", 80)).anyTimes();
  }
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:15,代码来源:OFChannelHandlerVer10Test.java

示例14: testSendAck

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

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

    Ack ack = mock(Ack.class);
    assertSame(promise, clientSession.sendAck(ack));

    verify(channel).writeAndFlush(ack);
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:13,代码来源:ClientSessionTest.java

示例15: testIdentifyWhenCommandIsNotIdentifyThrows

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

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

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

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


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