diff options
author | 2018-06-04 13:51:29 +0200 | |
---|---|---|
committer | 2018-08-01 09:06:13 +0200 | |
commit | 5644fbd17af113c2d65ffbad71548eb26898ee18 (patch) | |
tree | 2a4a4b4515658cf9d1467dc5c9f136eb4454d8de /hv-collector-core/src/test/kotlin | |
parent | 4b8cfb3e5bafc0cb078e37f64d0f21e8dfb0916a (diff) |
Fix wire protocol decoder refCnt issue
We should use retain + slice because every reactor-netty operator
automatically releases the buffer.
Change-Id: Ie0282e70fadb56d56fc410a08e036fb0ca10584c
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-core/src/test/kotlin')
-rw-r--r-- | hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameTest.kt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameTest.kt new file mode 100644 index 00000000..5a923c4e --- /dev/null +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/domain/WireFrameTest.kt @@ -0,0 +1,55 @@ +package org.onap.dcae.collectors.veshv.domain + +import io.netty.buffer.ByteBufAllocator +import io.netty.buffer.Unpooled +import org.assertj.core.api.Assertions.assertThat +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it + +/** + * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> + * @since June 2018 + */ +object WireFrameTest : Spek({ + describe("Wire Frame codec") { + describe("encode-decode methods' compatibility") { + val payloadContent = "test" + val payload = Unpooled.wrappedBuffer(payloadContent.toByteArray(Charsets.US_ASCII)) + val frame = WireFrame(payload = payload, + majorVersion = 1, + minorVersion = 2, + mark = 0xFF, + payloadSize = payload.readableBytes()) + + val encoded = frame.encode(ByteBufAllocator.DEFAULT) + val decoded = WireFrame.decode(encoded) + + it("should decode major version") { + assertThat(decoded.majorVersion).isEqualTo(frame.majorVersion) + } + + it("should decode minor version") { + assertThat(decoded.minorVersion).isEqualTo(frame.minorVersion) + } + + it("should decode mark") { + assertThat(decoded.mark).isEqualTo(frame.mark) + } + + it("should decode payload size") { + assertThat(decoded.payloadSize).isEqualTo(frame.payloadSize) + } + + it("should decode payload") { + assertThat(decoded.payload.toString(Charsets.US_ASCII)) + .isEqualTo(payloadContent) + } + + it("should retain decoded payload") { + encoded.release() + assertThat(decoded.payload.refCnt()).isEqualTo(1) + } + } + } +})
\ No newline at end of file |