1
+ package com .navercorp .pinpoint .common .server .bo .serializer .trace .v2 .bitfield ;
2
+
3
+ import com .navercorp .pinpoint .common .server .bo .SpanBo ;
4
+ import com .navercorp .pinpoint .common .trace .LoggingInfo ;
5
+ import org .apache .logging .log4j .LogManager ;
6
+ import org .apache .logging .log4j .Logger ;
7
+ import org .junit .jupiter .api .Assertions ;
8
+ import org .junit .jupiter .api .Test ;
9
+
10
+ /**
11
+ * @author Woonduk Kang(emeroad)
12
+ */
13
+ public class SpanBitFieldTest {
14
+ private final Logger logger = LogManager .getLogger (this .getClass ());
15
+
16
+ @ Test
17
+ public void testRoot_1 () throws Exception {
18
+ SpanBo spanBo = new SpanBo ();
19
+ spanBo .setParentSpanId (-1 );
20
+
21
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
22
+ Assertions .assertTrue (spanBitField .isRoot ());
23
+
24
+ spanBitField .setRoot (false );
25
+ Assertions .assertFalse (spanBitField .isRoot ());
26
+
27
+ }
28
+
29
+ @ Test
30
+ public void testRoot_2 () throws Exception {
31
+ SpanBo spanBo = new SpanBo ();
32
+ spanBo .setParentSpanId (0 );
33
+
34
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
35
+ Assertions .assertFalse (spanBitField .isRoot ());
36
+
37
+ spanBitField .maskAll ();
38
+ spanBitField .setRoot (false );
39
+ Assertions .assertFalse (spanBitField .isRoot ());
40
+ }
41
+
42
+ @ Test
43
+ public void testErrorCode_1 () {
44
+ SpanBo spanBo = new SpanBo ();
45
+ spanBo .setErrCode (1 );
46
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
47
+
48
+ Assertions .assertTrue (spanBitField .isSetErrorCode ());
49
+
50
+ spanBitField .setErrorCode (false );
51
+ Assertions .assertFalse (spanBitField .isSetErrorCode ());
52
+ }
53
+
54
+ @ Test
55
+ public void testErrorCode_2 () {
56
+ SpanBo spanBo = new SpanBo ();
57
+ spanBo .setErrCode (0 );
58
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
59
+
60
+ Assertions .assertFalse (spanBitField .isSetErrorCode ());
61
+
62
+ spanBitField .maskAll ();
63
+ spanBitField .setErrorCode (false );
64
+ Assertions .assertFalse (spanBitField .isSetErrorCode ());
65
+ }
66
+
67
+ @ Test
68
+ public void testApplicationServiceTypeEncodingStrategy_PREV_TYPE_EQUALS () {
69
+ SpanBo spanBo = new SpanBo ();
70
+ spanBo .setServiceType ((short ) 1000 );
71
+ spanBo .setApplicationServiceType ((short ) 1000 );
72
+
73
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
74
+
75
+ Assertions .assertEquals (spanBitField .getApplicationServiceTypeEncodingStrategy (), ServiceTypeEncodingStrategy .PREV_EQUALS );
76
+ }
77
+
78
+ @ Test
79
+ public void testApplicationServiceTypeEncodingStrategy_RAW () {
80
+ SpanBo spanBo = new SpanBo ();
81
+ spanBo .setServiceType ((short ) 1000 );
82
+ spanBo .setApplicationServiceType ((short ) 2000 );
83
+
84
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
85
+
86
+ Assertions .assertEquals (spanBitField .getApplicationServiceTypeEncodingStrategy (), ServiceTypeEncodingStrategy .RAW );
87
+
88
+ spanBitField .maskAll ();
89
+ Assertions .assertEquals (spanBitField .getApplicationServiceTypeEncodingStrategy (), ServiceTypeEncodingStrategy .RAW );
90
+ spanBitField .setApplicationServiceTypeEncodingStrategy (ServiceTypeEncodingStrategy .PREV_EQUALS );
91
+ Assertions .assertEquals (spanBitField .getApplicationServiceTypeEncodingStrategy (), ServiceTypeEncodingStrategy .PREV_EQUALS );
92
+ }
93
+
94
+
95
+ @ Test
96
+ public void testHasException_1 () {
97
+ SpanBo spanBo = new SpanBo ();
98
+ spanBo .setExceptionInfo (1 , "error" );
99
+
100
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
101
+
102
+ Assertions .assertTrue (spanBitField .isSetHasException ());
103
+
104
+ spanBitField .setHasException (false );
105
+ Assertions .assertFalse (spanBitField .isSetHasException ());
106
+ }
107
+
108
+ @ Test
109
+ public void testHasException_2 () {
110
+ SpanBo spanBo = new SpanBo ();
111
+
112
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
113
+
114
+ Assertions .assertFalse (spanBitField .isSetHasException ());
115
+
116
+ spanBitField .maskAll ();
117
+ spanBitField .setHasException (false );
118
+ Assertions .assertFalse (spanBitField .isSetHasException ());
119
+ }
120
+
121
+
122
+ @ Test
123
+ public void testLoggingTransactionInfo_1 () {
124
+ SpanBo spanBo = new SpanBo ();
125
+ spanBo .setLoggingTransactionInfo (LoggingInfo .INFO .getCode ());
126
+
127
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
128
+
129
+ Assertions .assertTrue (spanBitField .isSetLoggingTransactionInfo ());
130
+
131
+ spanBitField .setLoggingTransactionInfo (false );
132
+ Assertions .assertFalse (spanBitField .isSetLoggingTransactionInfo ());
133
+ }
134
+
135
+ @ Test
136
+ public void testLoggingTransactionInfo_2 () {
137
+ SpanBo spanBo = new SpanBo ();
138
+
139
+ SpanBitField spanBitField = SpanBitField .build (spanBo );
140
+
141
+ Assertions .assertFalse (spanBitField .isSetLoggingTransactionInfo ());
142
+
143
+ spanBitField .maskAll ();
144
+ spanBitField .setLoggingTransactionInfo (false );
145
+ Assertions .assertFalse (spanBitField .isSetLoggingTransactionInfo ());
146
+ }
147
+
148
+ }
0 commit comments