本文整理汇总了Java中io.netty.channel.DefaultChannelPromise.setSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultChannelPromise.setSuccess方法的具体用法?Java DefaultChannelPromise.setSuccess怎么用?Java DefaultChannelPromise.setSuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.DefaultChannelPromise
的用法示例。
在下文中一共展示了DefaultChannelPromise.setSuccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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());
}
示例6: 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);
}
示例7: 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);
}
示例8: testCloseWhenChannelIsActiveClosesChannel
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testCloseWhenChannelIsActiveClosesChannel() throws Exception {
DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
promise.setSuccess();
when(channel.isActive()).thenReturn(true);
when(channel.close()).thenReturn(promise);
clientSession.close();
verify(channel).close();
}
示例9: testCloseWhenChannelIsInactiveClosesChannel
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testCloseWhenChannelIsInactiveClosesChannel() throws Exception {
DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
promise.setSuccess();
when(channel.isActive()).thenReturn(false);
when(channel.close()).thenReturn(promise);
clientSession.close();
verify(channel, times(0)).close();
}
示例10: testSendSmsSetsUUIDAndBoxIdWhenNull
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testSendSmsSetsUUIDAndBoxIdWhenNull() throws Exception {
DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
promise.setSuccess();
when(channel.writeAndFlush(any())).thenReturn(promise);
Sms sms = new Sms("from", "to", "date", SmsType.MOBILE_TERMINATED_PUSH, DataCoding.DC_8BIT);
clientSession.sendSms(sms, 5000);
assertNotNull(sms.getId());
assertSame(clientSessionConfiguration.getClientId(), sms.getBoxId());
verify(channel).writeAndFlush(sms);
}
示例11: testSendHeartBeat
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testSendHeartBeat() throws Exception {
DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
promise.setSuccess();
when(channel.writeAndFlush(any())).thenReturn(promise);
HeartBeat heartBeat = new HeartBeat();
assertSame(promise, clientSession.sendHeartBeat(heartBeat));
verify(channel).writeAndFlush(heartBeat);
}
示例12: testIdentifyWhenCommandIsIdentifyWritesToChannel
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Test
public void testIdentifyWhenCommandIsIdentifyWritesToChannel() 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.IDENTIFY);
clientSession.identify(admin);
verify(channel).writeAndFlush(admin);
verify(sessionHandler).fireSessionInitialized(clientSession);
assertTrue(clientSession.isIdentified());
}
示例13: bind
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Override
public ChannelFuture bind(SocketAddress localAddress) {
DefaultChannelPromise promise = new DefaultChannelPromise(channel);
promise.setSuccess();
return promise;
}
示例14: connect
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Override
public ChannelFuture connect(SocketAddress remoteAddress) {
DefaultChannelPromise promise = new DefaultChannelPromise(channel);
promise.setSuccess();
return promise;
}
示例15: disconnect
import io.netty.channel.DefaultChannelPromise; //导入方法依赖的package包/类
@Override
public ChannelFuture disconnect() {
DefaultChannelPromise promise = new DefaultChannelPromise(channel);
promise.setSuccess();
return promise;
}