blob: f32e5bbcdb86f3fd831a442bb4f6b4c3506814d7 [file] [log] [blame]
Jian Li6bd35102018-06-09 00:18:47 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstacktelemetry.codec;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.openstacktelemetry.api.StatsInfo;
22import org.onosproject.openstacktelemetry.impl.DefaultStatsInfo;
23
24import java.nio.ByteBuffer;
25
26/**
27 * Unit tests for TinaStatsInfoByteBufferCodef.
28 */
Jian Li3db90852018-06-10 22:29:16 +090029public class TinaStatsInfoByteBufferCodecTest {
Jian Li6bd35102018-06-09 00:18:47 +090030
31 private static final int STARTUP_TIME = 1000;
32 private static final int CURRENT_ACCUMULATED_PACKETS = 8000;
33 private static final long CURRENT_ACCUMULATED_BYTES = 9000;
34 private static final int PREVIOUS_ACCUMULATED_PACKETS = 8000;
35 private static final long PREVIOUS_ACCUMULATED_BYTES = 9000;
36 private static final long FIRST_PACKET_ARRIVAL_TIME = 10000;
37 private static final int LAST_PACKET_OFFSET = 20000;
38 private static final short ERROR_PACKETS = 30000;
39 private static final short DROP_PACKETS = 30000;
40
41 private StatsInfo info;
42 private final TinaStatsInfoByteBufferCodec codec =
43 new TinaStatsInfoByteBufferCodec();
44
Jian Liae3fcff2018-07-30 11:55:44 +090045 /**
46 * Initial setup for this unit test.
47 */
Jian Li6bd35102018-06-09 00:18:47 +090048 @Before
49 public void setup() {
50 StatsInfo.Builder builder = new DefaultStatsInfo.DefaultBuilder();
51
52 info = builder
53 .withStartupTime(STARTUP_TIME)
54 .withCurrAccPkts(CURRENT_ACCUMULATED_PACKETS)
55 .withCurrAccBytes(CURRENT_ACCUMULATED_BYTES)
56 .withPrevAccPkts(PREVIOUS_ACCUMULATED_PACKETS)
57 .withPrevAccBytes(PREVIOUS_ACCUMULATED_BYTES)
58 .withFstPktArrTime(FIRST_PACKET_ARRIVAL_TIME)
59 .withLstPktOffset(LAST_PACKET_OFFSET)
60 .withErrorPkts(ERROR_PACKETS)
61 .withDropPkts(DROP_PACKETS)
62 .build();
63 }
64
Jian Liae3fcff2018-07-30 11:55:44 +090065 /**
66 * Tests codec encode and decode.
67 */
Jian Li6bd35102018-06-09 00:18:47 +090068 @Test
69 public void testEncodeDecode() {
70 ByteBuffer buffer = codec.encode(info);
71 StatsInfo decoded = codec.decode(ByteBuffer.wrap(buffer.array()));
72 new EqualsTester().addEqualityGroup(info, decoded).testEquals();
73 }
74}