Example usage for io.netty.buffer Unpooled EMPTY_BUFFER

List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled EMPTY_BUFFER.

Prototype

ByteBuf EMPTY_BUFFER

To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.

Click Source Link

Document

A buffer whose capacity is 0 .

Usage

From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.AtomicAggregateAttributeParser.java

License:Open Source License

@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(attribute instanceof Attributes,
            "Attribute parameter is not a PathAttribute object.");
    final Attributes pathAttributes = (Attributes) attribute;
    if (pathAttributes.getAtomicAggregate() == null) {
        return;// w  w w .  ja  va2s.c  o  m
    }
    AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, Unpooled.EMPTY_BUFFER, byteAggregator);
}

From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.BgpPrefixSidAttributeParserTest.java

License:Open Source License

@Test
public void testHandling() throws BGPDocumentedException, BGPParsingException {
    final AttributesBuilder builder = new AttributesBuilder();
    this.parser.parseAttribute(Unpooled.copiedBuffer(this.bytes), builder);
    assertEquals(3, builder.getBgpPrefixSid().getBgpPrefixSidTlvs().size());

    this.parser.serializeAttribute(builder.build(), Unpooled.EMPTY_BUFFER);
    Mockito.verify(this.reg, Mockito.times(3)).serializeBgpPrefixSidTlv(Mockito.any(BgpPrefixSidTlv.class),
            Mockito.any(ByteBuf.class));
}

From source file:org.opendaylight.protocol.bgp.parser.spi.AbstractMessageRegistryTest.java

License:Open Source License

@Test
public void testMessageParser() throws Exception {
    final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
            .getMessageRegistry();/* ww w. j a v  a  2 s.c om*/
    String ex = "";
    try {
        msgReg.serializeMessage(null, Unpooled.EMPTY_BUFFER);
    } catch (final NullPointerException e) {
        ex = e.getMessage();
    }
    assertEquals("BGPMessage is mandatory.", ex);
}

From source file:org.opendaylight.protocol.bmp.spi.parser.AbstractBmpMessageWithTlvParserTest.java

License:Open Source License

@Test
public void testParseTlvs() throws BmpDeserializationException {
    final ByteBuf buffer = Unpooled.EMPTY_BUFFER;
    final TlvsBuilder builder = new TlvsBuilder();
    this.parser.parseTlvs(builder, buffer);
    assertNull(builder.getDescriptionTlv());

    this.parser.parseTlvs(builder, Unpooled.wrappedBuffer(DATA));
    assertNotNull(builder.getDescriptionTlv());
    assertEquals("test", builder.getDescriptionTlv().getDescription());
}

From source file:org.opendaylight.protocol.bmp.spi.parser.TlvUtilTest.java

License:Open Source License

@Test
public void testFormatTlvCounter32() throws Exception {
    ByteBuf out = Unpooled.buffer(TLV_COUNTER32_OUT.length);
    TlvUtil.formatTlvCounter32(1, new Counter32(5L), out);
    Assert.assertArrayEquals(TLV_COUNTER32_OUT, ByteArray.getAllBytes(out));
    out = Unpooled.EMPTY_BUFFER;
    TlvUtil.formatTlvCounter32(1, null, out);
    Assert.assertFalse(out.isReadable());
}

From source file:org.opendaylight.protocol.bmp.spi.parser.TlvUtilTest.java

License:Open Source License

@Test
public void testFormatTlvGauge64() throws Exception {
    ByteBuf out = Unpooled.buffer(TLV_GAUGE64_OUT.length);
    TlvUtil.formatTlvGauge64(1, new Gauge64(BigInteger.valueOf(5)), out);
    Assert.assertArrayEquals(TLV_GAUGE64_OUT, ByteArray.getAllBytes(out));
    out = Unpooled.EMPTY_BUFFER;
    TlvUtil.formatTlvGauge64(1, null, out);
    Assert.assertFalse(out.isReadable());
}

From source file:org.opendaylight.protocol.bmp.spi.parser.TlvUtilTest.java

License:Open Source License

@Test
public void testFormatTlvUtf8() throws Exception {
    ByteBuf out = Unpooled.buffer(TLV_UTF8_OUT.length);
    TlvUtil.formatTlvUtf8(1, "info1", out);
    Assert.assertArrayEquals(TLV_UTF8_OUT, ByteArray.getAllBytes(out));
    out = Unpooled.EMPTY_BUFFER;
    TlvUtil.formatTlvUtf8(1, null, out);
    Assert.assertFalse(out.isReadable());
}

From source file:org.opendaylight.protocol.bmp.spi.parser.TlvUtilTest.java

License:Open Source License

@Test
public void testFormatTlvASCII() throws Exception {
    ByteBuf out = Unpooled.buffer(TLV_ASCII_OUT.length);
    TlvUtil.formatTlvAscii(1, "Name", out);
    Assert.assertArrayEquals(TLV_ASCII_OUT, ByteArray.getAllBytes(out));
    out = Unpooled.EMPTY_BUFFER;
    TlvUtil.formatTlvAscii(1, null, out);
    Assert.assertFalse(out.isReadable());
}

From source file:org.opendaylight.protocol.bmp.spi.registry.SimpleBmpTlvRegistryTest.java

License:Open Source License

@Test
public void testUnrecognizedType() throws BmpDeserializationException {
    assertNull(this.bmpTlvRegistry.parseTlv(otherTlvType, this.input));
    final ByteBuf output = Unpooled.EMPTY_BUFFER;
    this.bmpTlvRegistry.serializeTlv(new MockTlv(), output);
    assertEquals(0, output.readableBytes());
}

From source file:org.opendaylight.protocol.bmp.spi.registry.SimpleBmpTlvRegistryTest.java

License:Open Source License

@Test
public void testParseTlv() throws BmpDeserializationException {
    final Tlv output = this.bmpTlvRegistry.parseTlv(descriptionTlvType, this.input);
    assertNotNull(output);/*from w w w  . jav  a  2  s .  c  o  m*/
    assertTrue(output instanceof MockDescriptionTlv);

    final ByteBuf aggregator = Unpooled.EMPTY_BUFFER;
    this.bmpTlvRegistry.serializeTlv(output, aggregator);
    Mockito.verify(this.descriptionTlvSerializer).serializeTlv(output, aggregator);
}