1919
2020import com .google .common .collect .ImmutableList ;
2121import com .google .common .collect .ImmutableSet ;
22- import org . joda .time .Instant ;
22+ import java .time .Instant ;
2323import org .junit .Test ;
2424import org .junit .runner .RunWith ;
2525import org .junit .runners .JUnit4 ;
2626
2727/** Unit tests for {@link Counter}. */
2828@ RunWith (JUnit4 .class )
2929public class CounterTest {
30+
3031 @ Test
3132 public void testGetCardinality_reflectsCurrentCardinality () {
3233 Counter counter =
@@ -75,15 +76,17 @@ public void testIncrement_incrementsValues() {
7576 assertThat (counter .getTimestampedValues ()).isEmpty ();
7677
7778 // use package-private incrementBy once to set the start timestamp predictably.
78- counter .incrementBy (1 , new Instant (1337 ), ImmutableList .of ("test_value1" ));
79- assertThat (counter .getTimestampedValues (new Instant (1337 )))
79+ counter .incrementBy (1 , Instant . ofEpochMilli (1337 ), ImmutableList .of ("test_value1" ));
80+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1337 )))
8081 .containsExactly (
81- MetricPoint .create (counter , ImmutableList .of ("test_value1" ), new Instant (1337 ), 1L ));
82+ MetricPoint .create (
83+ counter , ImmutableList .of ("test_value1" ), Instant .ofEpochMilli (1337 ), 1L ));
8284
8385 counter .increment ("test_value1" );
84- assertThat (counter .getTimestampedValues (new Instant (1337 )))
86+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1337 )))
8587 .containsExactly (
86- MetricPoint .create (counter , ImmutableList .of ("test_value1" ), new Instant (1337 ), 2L ));
88+ MetricPoint .create (
89+ counter , ImmutableList .of ("test_value1" ), Instant .ofEpochMilli (1337 ), 2L ));
8790 }
8891
8992 @ Test
@@ -97,17 +100,20 @@ public void testIncrementBy_incrementsValues() {
97100
98101 assertThat (counter .getTimestampedValues ()).isEmpty ();
99102
100- counter .incrementBy (1 , new Instant (1337 ), ImmutableList .of ("test_value1" ));
101- assertThat (counter .getTimestampedValues (new Instant (1337 )))
103+ counter .incrementBy (1 , Instant . ofEpochMilli (1337 ), ImmutableList .of ("test_value1" ));
104+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1337 )))
102105 .containsExactly (
103- MetricPoint .create (counter , ImmutableList .of ("test_value1" ), new Instant (1337 ), 1L ));
106+ MetricPoint .create (
107+ counter , ImmutableList .of ("test_value1" ), Instant .ofEpochMilli (1337 ), 1L ));
104108
105- counter .set (-10L , new Instant (1337 ), ImmutableList .of ("test_value2" ));
106- counter .incrementBy (5 , new Instant (1337 ), ImmutableList .of ("test_value2" ));
107- assertThat (counter .getTimestampedValues (new Instant (1337 )))
109+ counter .set (-10L , Instant . ofEpochMilli (1337 ), ImmutableList .of ("test_value2" ));
110+ counter .incrementBy (5 , Instant . ofEpochMilli (1337 ), ImmutableList .of ("test_value2" ));
111+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1337 )))
108112 .containsExactly (
109- MetricPoint .create (counter , ImmutableList .of ("test_value1" ), new Instant (1337 ), 1L ),
110- MetricPoint .create (counter , ImmutableList .of ("test_value2" ), new Instant (1337 ), -5L ));
113+ MetricPoint .create (
114+ counter , ImmutableList .of ("test_value1" ), Instant .ofEpochMilli (1337 ), 1L ),
115+ MetricPoint .create (
116+ counter , ImmutableList .of ("test_value2" ), Instant .ofEpochMilli (1337 ), -5L ));
111117 }
112118
113119 @ Test
@@ -133,24 +139,40 @@ public void testResetAll_resetsAllValuesAndStartTimestamps() {
133139 "vdn" ,
134140 ImmutableSet .of (LabelDescriptor .create ("label1" , "bar" )));
135141
136- counter .incrementBy (3 , new Instant (1337 ), ImmutableList .of ("foo" ));
137- counter .incrementBy (5 , new Instant (1338 ), ImmutableList .of ("moo" ));
142+ counter .incrementBy (3 , Instant . ofEpochMilli (1337 ), ImmutableList .of ("foo" ));
143+ counter .incrementBy (5 , Instant . ofEpochMilli (1338 ), ImmutableList .of ("moo" ));
138144
139- assertThat (counter .getTimestampedValues (new Instant (1400 )))
145+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1400 )))
140146 .containsExactly (
141147 MetricPoint .create (
142- counter , ImmutableList .of ("foo" ), new Instant (1337 ), new Instant (1400 ), 3L ),
148+ counter ,
149+ ImmutableList .of ("foo" ),
150+ Instant .ofEpochMilli (1337 ),
151+ Instant .ofEpochMilli (1400 ),
152+ 3L ),
143153 MetricPoint .create (
144- counter , ImmutableList .of ("moo" ), new Instant (1338 ), new Instant (1400 ), 5L ));
154+ counter ,
155+ ImmutableList .of ("moo" ),
156+ Instant .ofEpochMilli (1338 ),
157+ Instant .ofEpochMilli (1400 ),
158+ 5L ));
145159
146- counter .reset (new Instant (1339 ));
160+ counter .reset (Instant . ofEpochMilli (1339 ));
147161
148- assertThat (counter .getTimestampedValues (new Instant (1400 )))
162+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1400 )))
149163 .containsExactly (
150164 MetricPoint .create (
151- counter , ImmutableList .of ("foo" ), new Instant (1339 ), new Instant (1400 ), 0L ),
165+ counter ,
166+ ImmutableList .of ("foo" ),
167+ Instant .ofEpochMilli (1339 ),
168+ Instant .ofEpochMilli (1400 ),
169+ 0L ),
152170 MetricPoint .create (
153- counter , ImmutableList .of ("moo" ), new Instant (1339 ), new Instant (1400 ), 0L ));
171+ counter ,
172+ ImmutableList .of ("moo" ),
173+ Instant .ofEpochMilli (1339 ),
174+ Instant .ofEpochMilli (1400 ),
175+ 0L ));
154176 }
155177
156178 @ Test
@@ -162,23 +184,39 @@ public void testReset_resetsValuesAndStartTimestamps() {
162184 "vdn" ,
163185 ImmutableSet .of (LabelDescriptor .create ("label1" , "bar" )));
164186
165- counter .incrementBy (3 , new Instant (1337 ), ImmutableList .of ("foo" ));
166- counter .incrementBy (5 , new Instant (1338 ), ImmutableList .of ("moo" ));
187+ counter .incrementBy (3 , Instant . ofEpochMilli (1337 ), ImmutableList .of ("foo" ));
188+ counter .incrementBy (5 , Instant . ofEpochMilli (1338 ), ImmutableList .of ("moo" ));
167189
168- assertThat (counter .getTimestampedValues (new Instant (1400 )))
190+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1400 )))
169191 .containsExactly (
170192 MetricPoint .create (
171- counter , ImmutableList .of ("foo" ), new Instant (1337 ), new Instant (1400 ), 3L ),
193+ counter ,
194+ ImmutableList .of ("foo" ),
195+ Instant .ofEpochMilli (1337 ),
196+ Instant .ofEpochMilli (1400 ),
197+ 3L ),
172198 MetricPoint .create (
173- counter , ImmutableList .of ("moo" ), new Instant (1338 ), new Instant (1400 ), 5L ));
199+ counter ,
200+ ImmutableList .of ("moo" ),
201+ Instant .ofEpochMilli (1338 ),
202+ Instant .ofEpochMilli (1400 ),
203+ 5L ));
174204
175- counter .reset (new Instant (1339 ), ImmutableList .of ("foo" ));
205+ counter .reset (Instant . ofEpochMilli (1339 ), ImmutableList .of ("foo" ));
176206
177- assertThat (counter .getTimestampedValues (new Instant (1400 )))
207+ assertThat (counter .getTimestampedValues (Instant . ofEpochMilli (1400 )))
178208 .containsExactly (
179209 MetricPoint .create (
180- counter , ImmutableList .of ("foo" ), new Instant (1339 ), new Instant (1400 ), 0L ),
210+ counter ,
211+ ImmutableList .of ("foo" ),
212+ Instant .ofEpochMilli (1339 ),
213+ Instant .ofEpochMilli (1400 ),
214+ 0L ),
181215 MetricPoint .create (
182- counter , ImmutableList .of ("moo" ), new Instant (1338 ), new Instant (1400 ), 5L ));
216+ counter ,
217+ ImmutableList .of ("moo" ),
218+ Instant .ofEpochMilli (1338 ),
219+ Instant .ofEpochMilli (1400 ),
220+ 5L ));
183221 }
184222}
0 commit comments