Example usage for io.netty.channel DefaultChannelPromise setSuccess

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

Introduction

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

Prototype

@Override
    public ChannelPromise setSuccess() 

Source Link

Usage

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

License:Open Source License

@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);//from ww w. jav a 2  s  .  co  m
}

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

License:Open Source License

@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);/*from  w w w  .j  a  v a 2s .c  o m*/

    verify(channel).writeAndFlush(admin);
    verify(sessionHandler).fireSessionInitialized(clientSession);

    assertTrue(clientSession.isIdentified());
}

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

License:Open Source License

@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);/*from w w  w.  j  av  a2  s .  c o  m*/
}

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

License:Open Source License

@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();/*from   w  w  w .j  ava 2  s  .  c  om*/

    verify(channel).close();
}

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

License:Open Source License

@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();/*from   w  ww . j a va  2  s . co  m*/

    verify(channel, times(0)).close();
}

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

License:Open Source License

@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();//from  w  w w  . j  a  v  a2s  .c o  m

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

}

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

License:Open Source License

@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);//from  ww w.j  ava  2s. c om

    assertNotNull(sms.getId());
    assertSame(clientSessionConfiguration.getClientId(), sms.getBoxId());
    verify(channel).writeAndFlush(sms);
}

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

License:Open Source License

@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());//from ww  w .  j a va2 s  . c  om

    assertSame(sms, future.getRequest());

    Futures.getChecked(future, DuplicateKeyException.class);
}

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

License:Open Source License

@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);
}

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

License:Open Source License

@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/*w w  w.j  a v  a2 s .  c  o m*/
        public void run() {
            clientSession.getWindow().complete(sms.getId(), expectedResponse);
        }
    }, 100, TimeUnit.MILLISECONDS);

    final Ack response = clientSession.sendSmsAndWait(sms, 5000);
    assertSame(expectedResponse, response);
}