• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, 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.config;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import io.opencensus.trace.samplers.Samplers;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.JUnit4;
25 
26 /** Unit tests for {@link TraceParams}. */
27 @RunWith(JUnit4.class)
28 public class TraceParamsTest {
29   @Test
defaultTraceParams()30   public void defaultTraceParams() {
31     assertThat(TraceParams.DEFAULT.getSampler()).isEqualTo(Samplers.probabilitySampler(1e-4));
32     assertThat(TraceParams.DEFAULT.getMaxNumberOfAttributes()).isEqualTo(32);
33     assertThat(TraceParams.DEFAULT.getMaxNumberOfAnnotations()).isEqualTo(32);
34     assertThat(TraceParams.DEFAULT.getMaxNumberOfNetworkEvents()).isEqualTo(128);
35     assertThat(TraceParams.DEFAULT.getMaxNumberOfMessageEvents()).isEqualTo(128);
36     assertThat(TraceParams.DEFAULT.getMaxNumberOfLinks()).isEqualTo(32);
37   }
38 
39   @Test(expected = NullPointerException.class)
updateTraceParams_NullSampler()40   public void updateTraceParams_NullSampler() {
41     TraceParams.DEFAULT.toBuilder().setSampler(null).build();
42   }
43 
44   @Test(expected = IllegalArgumentException.class)
updateTraceParams_NonPositiveMaxNumberOfAttributes()45   public void updateTraceParams_NonPositiveMaxNumberOfAttributes() {
46     TraceParams.DEFAULT.toBuilder().setMaxNumberOfAttributes(0).build();
47   }
48 
49   @Test(expected = IllegalArgumentException.class)
updateTraceParams_NonPositiveMaxNumberOfAnnotations()50   public void updateTraceParams_NonPositiveMaxNumberOfAnnotations() {
51     TraceParams.DEFAULT.toBuilder().setMaxNumberOfAnnotations(0).build();
52   }
53 
54   @Test(expected = IllegalArgumentException.class)
updateTraceParams_NonPositiveMaxNumberOfNetworkEvents()55   public void updateTraceParams_NonPositiveMaxNumberOfNetworkEvents() {
56     TraceParams.DEFAULT.toBuilder().setMaxNumberOfNetworkEvents(0).build();
57   }
58 
59   @Test(expected = IllegalArgumentException.class)
updateTraceParams_NonPositiveMaxNumberOfMessageEvents()60   public void updateTraceParams_NonPositiveMaxNumberOfMessageEvents() {
61     TraceParams.DEFAULT.toBuilder().setMaxNumberOfMessageEvents(0).build();
62   }
63 
64   @Test(expected = IllegalArgumentException.class)
updateTraceParams_NonPositiveMaxNumberOfLinks()65   public void updateTraceParams_NonPositiveMaxNumberOfLinks() {
66     TraceParams.DEFAULT.toBuilder().setMaxNumberOfLinks(0).build();
67   }
68 
69   @Test
updateTraceParams_All()70   public void updateTraceParams_All() {
71     TraceParams traceParams =
72         TraceParams.DEFAULT
73             .toBuilder()
74             .setSampler(Samplers.alwaysSample())
75             .setMaxNumberOfAttributes(8)
76             .setMaxNumberOfAnnotations(9)
77             .setMaxNumberOfMessageEvents(10)
78             .setMaxNumberOfLinks(11)
79             .build();
80     assertThat(traceParams.getSampler()).isEqualTo(Samplers.alwaysSample());
81     assertThat(traceParams.getMaxNumberOfAttributes()).isEqualTo(8);
82     assertThat(traceParams.getMaxNumberOfAnnotations()).isEqualTo(9);
83     // test maxNumberOfNetworkEvent can be set via maxNumberOfMessageEvent
84     assertThat(traceParams.getMaxNumberOfNetworkEvents()).isEqualTo(10);
85     assertThat(traceParams.getMaxNumberOfMessageEvents()).isEqualTo(10);
86     assertThat(traceParams.getMaxNumberOfLinks()).isEqualTo(11);
87   }
88 
89   @Test
updateTraceParams_maxNumberOfNetworkEvents()90   public void updateTraceParams_maxNumberOfNetworkEvents() {
91     TraceParams traceParams =
92         TraceParams.DEFAULT.toBuilder().setMaxNumberOfNetworkEvents(10).build();
93     assertThat(traceParams.getMaxNumberOfNetworkEvents()).isEqualTo(10);
94     // test maxNumberOfMessageEvent can be set via maxNumberOfNetworkEvent
95     assertThat(traceParams.getMaxNumberOfMessageEvents()).isEqualTo(10);
96   }
97 }
98