• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018, OpenCensus Authors
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  */
16 
17 package io.opencensus.trace.internal;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import io.opencensus.trace.MessageEvent;
22 import io.opencensus.trace.NetworkEvent;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.JUnit4;
26 
27 /** Unit tests for {@link BaseMessageEventUtils}. */
28 @RunWith(JUnit4.class)
29 public class BaseMessageEventUtilsTest {
30   private static final long SENT_EVENT_ID = 12345L;
31   private static final long RECV_EVENT_ID = 67890L;
32   private static final long UNCOMPRESSED_SIZE = 100;
33   private static final long COMPRESSED_SIZE = 99;
34 
35   private static final MessageEvent SENT_MESSAGE_EVENT =
36       MessageEvent.builder(MessageEvent.Type.SENT, SENT_EVENT_ID)
37           .setUncompressedMessageSize(UNCOMPRESSED_SIZE)
38           .setCompressedMessageSize(COMPRESSED_SIZE)
39           .build();
40   private static final MessageEvent RECV_MESSAGE_EVENT =
41       MessageEvent.builder(MessageEvent.Type.RECEIVED, RECV_EVENT_ID)
42           .setUncompressedMessageSize(UNCOMPRESSED_SIZE)
43           .setCompressedMessageSize(COMPRESSED_SIZE)
44           .build();
45   private static final NetworkEvent SENT_NETWORK_EVENT =
46       NetworkEvent.builder(NetworkEvent.Type.SENT, SENT_EVENT_ID)
47           .setUncompressedMessageSize(UNCOMPRESSED_SIZE)
48           .setCompressedMessageSize(COMPRESSED_SIZE)
49           .build();
50   private static final NetworkEvent RECV_NETWORK_EVENT =
51       NetworkEvent.builder(NetworkEvent.Type.RECV, RECV_EVENT_ID)
52           .setUncompressedMessageSize(UNCOMPRESSED_SIZE)
53           .setCompressedMessageSize(COMPRESSED_SIZE)
54           .build();
55 
56   @Test
networkEventToMessageEvent()57   public void networkEventToMessageEvent() {
58     assertThat(BaseMessageEventUtils.asMessageEvent(SENT_NETWORK_EVENT))
59         .isEqualTo(SENT_MESSAGE_EVENT);
60     assertThat(BaseMessageEventUtils.asMessageEvent(RECV_NETWORK_EVENT))
61         .isEqualTo(RECV_MESSAGE_EVENT);
62   }
63 
64   @Test
messageEventToNetworkEvent()65   public void messageEventToNetworkEvent() {
66     assertThat(BaseMessageEventUtils.asNetworkEvent(SENT_MESSAGE_EVENT))
67         .isEqualTo(SENT_NETWORK_EVENT);
68     assertThat(BaseMessageEventUtils.asNetworkEvent(RECV_MESSAGE_EVENT))
69         .isEqualTo(RECV_NETWORK_EVENT);
70   }
71 }
72