Example usage for io.netty.buffer ByteBuf writeInt

List of usage examples for io.netty.buffer ByteBuf writeInt

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeInt.

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpPushPromiseFrameReservedBits() throws Exception {
    int length = 4;
    byte flags = (byte) 0xE7; // END_HEADERS -- should ignore any unknown flags
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf frame = pushPromiseFrame(length, flags, streamId);
    setReservedBits(frame);/*from   www.  java2s.com*/
    frame.writeInt(promisedStreamId | 0x80000000); // should ignore reserved bit
    decoder.decode(frame);

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate).readHeaderBlockEnd();
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testIllegalHttpPushPromiseFrame() throws Exception {
    int length = 4;
    byte flags = 0x04; // END_HEADERS
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = 0; // illegal stream identifier

    ByteBuf frame = pushPromiseFrame(length, flags, streamId);
    frame.writeInt(promisedStreamId);
    decoder.decode(frame);// www  .ja va2 s .co  m

    verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testContinuedHttpPushPromiseFrame() throws Exception {
    int headerBlockLength = 16;
    int length = 4;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf pushPromiseFrame = pushPromiseFrame(length, flags, streamId);
    pushPromiseFrame.writeInt(promisedStreamId);
    ByteBuf continuationFrame = continuationFrame(headerBlockLength, (byte) 0x04, streamId); // END_HEADERS
    writeRandomData(continuationFrame, headerBlockLength);
    decoder.decode(releaseLater(Unpooled.wrappedBuffer(pushPromiseFrame, continuationFrame)));

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate)/*from  ww w  . j av  a2s  .co m*/
            .readHeaderBlock(continuationFrame.slice(HTTP_FRAME_HEADER_SIZE, headerBlockLength));
    inOrder.verify(delegate).readHeaderBlockEnd();
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpPushPromiseFrameEmptyContinuation() throws Exception {
    int headerBlockLength = 16;
    int length = 4 + headerBlockLength;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf pushPromiseFrame = pushPromiseFrame(length, flags, streamId);
    pushPromiseFrame.writeInt(promisedStreamId);
    writeRandomData(pushPromiseFrame, headerBlockLength);
    ByteBuf continuationFrame = continuationFrame(0, (byte) 0x04, streamId); // END_HEADERS
    decoder.decode(releaseLater(Unpooled.wrappedBuffer(pushPromiseFrame, continuationFrame)));

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate)//ww  w  .j av a 2  s  . c o m
            .readHeaderBlock(pushPromiseFrame.slice(HTTP_FRAME_HEADER_SIZE + 4, headerBlockLength));
    inOrder.verify(delegate).readHeaderBlockEnd();
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpPushPromiseFrameMultipleContinuations() throws Exception {
    int headerBlockLength = 16;
    int length = 4 + headerBlockLength;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf pushPromiseFrame = pushPromiseFrame(length, flags, streamId);
    pushPromiseFrame.writeInt(promisedStreamId);
    writeRandomData(pushPromiseFrame, headerBlockLength);
    ByteBuf continuationFrame1 = continuationFrame(0, (byte) 0x00, streamId);
    ByteBuf continuationFrame2 = continuationFrame(0, (byte) 0x04, streamId); // END_HEADERS
    decoder.decode(//from ww  w.j a  v a2  s  . co m
            releaseLater(Unpooled.wrappedBuffer(pushPromiseFrame, continuationFrame1, continuationFrame2)));

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate)
            .readHeaderBlock(pushPromiseFrame.slice(HTTP_FRAME_HEADER_SIZE + 4, headerBlockLength));
    inOrder.verify(delegate).readHeaderBlockEnd();
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpPushPromiseFrameContinuationReservedFlags() throws Exception {
    int headerBlockLength = 16;
    int length = 4 + headerBlockLength;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf pushPromiseFrame = pushPromiseFrame(length, flags, streamId);
    pushPromiseFrame.writeInt(promisedStreamId);
    writeRandomData(pushPromiseFrame, headerBlockLength);
    ByteBuf continuationFrame = continuationFrame(0, (byte) 0xE7, streamId); // END_HEADERS
    decoder.decode(releaseLater(Unpooled.wrappedBuffer(pushPromiseFrame, continuationFrame)));

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate)/*from  w  ww . j a  v  a 2s .c o m*/
            .readHeaderBlock(pushPromiseFrame.slice(HTTP_FRAME_HEADER_SIZE + 4, headerBlockLength));
    inOrder.verify(delegate).readHeaderBlockEnd();
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpPushPromiseFrameContinuationIllegalStreamId() throws Exception {
    int headerBlockLength = 16;
    int length = 4 + headerBlockLength;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf pushPromiseFrame = pushPromiseFrame(length, flags, streamId);
    pushPromiseFrame.writeInt(promisedStreamId);
    writeRandomData(pushPromiseFrame, headerBlockLength);
    // different stream identifier
    ByteBuf continuationFrame = continuationFrame(0, (byte) 0x04, streamId + 1); // END_HEADERS
    decoder.decode(releaseLater(Unpooled.wrappedBuffer(pushPromiseFrame, continuationFrame)));

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate)//from w w  w.j  av a 2  s .c  o  m
            .readHeaderBlock(pushPromiseFrame.slice(HTTP_FRAME_HEADER_SIZE + 4, headerBlockLength));
    inOrder.verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpPushPromiseFrameMissingContinuation() throws Exception {
    int length = 4;
    byte flags = 0;
    int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;

    ByteBuf pushPromiseFrame = pushPromiseFrame(length, flags, streamId);
    pushPromiseFrame.writeInt(promisedStreamId);
    ByteBuf dataFrame = dataFrame(0, (byte) 0, streamId);
    decoder.decode(releaseLater(Unpooled.wrappedBuffer(pushPromiseFrame, dataFrame)));

    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).readPushPromiseFrame(streamId, promisedStreamId);
    inOrder.verify(delegate).readFrameError(anyString());
    verifyNoMoreInteractions(delegate);/* w w  w . ja v  a  2s  .  c o m*/
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpGoAwayFrame() throws Exception {
    int length = 8;
    byte flags = 0;
    int streamId = 0; // connection identifier
    int lastStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int errorCode = RANDOM.nextInt();

    ByteBuf frame = goAwayFrame(length, flags, streamId);
    frame.writeInt(lastStreamId);
    frame.writeInt(errorCode);//from w ww . j  a v  a  2s .c o  m
    decoder.decode(frame);

    verify(delegate).readGoAwayFrame(lastStreamId, errorCode);
    verifyNoMoreInteractions(delegate);
}

From source file:com.twitter.http2.HttpFrameDecoderTest.java

License:Apache License

@Test
public void testHttpGoAwayFrameReservedBits() throws Exception {
    int length = 8;
    byte flags = (byte) 0xFF; // should ignore any flags
    int streamId = 0; // connection identifier
    int lastStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
    int errorCode = RANDOM.nextInt();

    ByteBuf frame = goAwayFrame(length, flags, streamId);
    setReservedBits(frame);/* w w  w.  j  av  a2s  . c om*/
    frame.writeInt(lastStreamId | 0x80000000); // should ignore reserved bit
    frame.writeInt(errorCode);
    decoder.decode(frame);

    verify(delegate).readGoAwayFrame(lastStreamId, errorCode);
    verifyNoMoreInteractions(delegate);
}