Example usage for io.netty.channel DefaultChannelPromise cancel

List of usage examples for io.netty.channel DefaultChannelPromise cancel

Introduction

In this page you can find the example usage for io.netty.channel DefaultChannelPromise cancel.

Prototype

@Override
boolean cancel(boolean mayInterruptIfRunning);

Source Link

Document

If the cancellation was successful it will fail the future with a CancellationException .

Usage

From source file:com.github.milenkovicm.kafka.KafkaTopic.java

License:Apache License

private DefaultChannelPromise getDefaultChannelPromise() {
    final DefaultChannelPromise channelPromise = new DefaultChannelPromise(null, GlobalEventExecutor.INSTANCE);
    channelPromise.cancel(true);
    return channelPromise;
}

From source file:com.github.spapageo.jannel.client.ClientSessionTest.java

License:Open Source License

@Test(expected = CancellationException.class)
public void testSendSmsReturnsFailedFutureWhenWriteIsCancelled() throws Exception {
    DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.cancel(true);

    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.getUnchecked(future);/* www  .j  a va2 s. co  m*/
}

From source file:com.github.spapageo.jannel.client.ClientSessionTest.java

License:Open Source License

@Test(expected = CancellationException.class)
public void testSendSmsAndWaitThrowsWhenWriteIsCancelled() throws Exception {
    DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next());
    promise.cancel(true);

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

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

    clientSession.sendSmsAndWait(sms, 5000);
}