Formatting in metrics tests

This commit is contained in:
Predrag Maric 2017-01-19 13:01:10 +01:00
parent e150b2ff54
commit 761603c76a
2 changed files with 21 additions and 4 deletions

View File

@ -16,14 +16,16 @@ public class MetricsTest {
@Test
public void whenMarkMeter_thenCorrectRates() throws InterruptedException {
Meter meter = new Meter();
long initCount = meter.getCount();
assertThat(initCount, equalTo(0L));
meter.mark();
assertThat(meter.getCount(), equalTo(1L));
meter.mark(20);
assertThat(meter.getCount(), equalTo(21L));
// not use assert for these rate values because they change every time when this test is run
@ -40,6 +42,7 @@ public class MetricsTest {
@Test
public void whenInitRatioGauge_thenCorrectRatio() {
Gauge<Double> ratioGauge = new AttendanceRatioGauge(15, 20);
assertThat(ratioGauge.getValue(), equalTo(0.75));
}
@ -48,6 +51,7 @@ public class MetricsTest {
Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
List<Long> expected = new ArrayList<Long>();
expected.add(12L);
assertThat(activeUsersGauge.getValue(), equalTo(expected));
}
@ -55,36 +59,42 @@ public class MetricsTest {
public void whenUseDerivativeGauge_thenCorrectGaugeFromBase() {
Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
Gauge<Integer> activeUserCountGauge = new ActiveUserCountGauge(activeUsersGauge);
assertThat(activeUserCountGauge.getValue(), equalTo(1));
}
@Test
public void whenIncDecCounter_thenCorrectCount() {
Counter counter = new Counter();
long initCount = counter.getCount();
assertThat(initCount, equalTo(0L));
counter.inc();
assertThat(counter.getCount(), equalTo(1L));
counter.inc(11);
assertThat(counter.getCount(), equalTo(12L));
counter.dec();
assertThat(counter.getCount(), equalTo(11L));
counter.dec(6);
assertThat(counter.getCount(), equalTo(5L));
}
@Test
public void whenUpdateHistogram_thenCorrectDistributionData() {
Histogram histogram = new Histogram(new UniformReservoir());
histogram.update(5);
long count1 = histogram.getCount();
assertThat(count1, equalTo(1L));
Snapshot snapshot1 = histogram.getSnapshot();
assertThat(snapshot1.getValues().length, equalTo(1));
assertThat(snapshot1.getValues()[0], equalTo(5L));
@ -101,8 +111,11 @@ public class MetricsTest {
histogram.update(20);
long count2 = histogram.getCount();
assertThat(count2, equalTo(2L));
Snapshot snapshot2 = histogram.getSnapshot();
assertThat(snapshot2.getValues().length, equalTo(2));
assertThat(snapshot2.getValues()[0], equalTo(5L));
assertThat(snapshot2.getValues()[1], equalTo(20L));
@ -121,11 +134,11 @@ public class MetricsTest {
@Test
public void whenUseTimer_thenCorrectTimerContexts() throws InterruptedException {
Timer timer = new Timer();
Timer.Context context1 = timer.time();
TimeUnit.SECONDS.sleep(5);
long elapsed1 = context1.stop();
assertEquals(5000000000L, elapsed1, 1000000);
assertThat(timer.getCount(), equalTo(1L));
assertEquals(0.2, timer.getMeanRate(), 0.1);
@ -133,6 +146,7 @@ public class MetricsTest {
Timer.Context context2 = timer.time();
TimeUnit.SECONDS.sleep(2);
context2.close();
assertThat(timer.getCount(), equalTo(2L));
assertEquals(0.3, timer.getMeanRate(), 0.1);
}

View File

@ -23,10 +23,13 @@ public class HealthCheckTest {
assertThat(healthCheckRegistry.getNames().size(), equalTo(2));
Map<String, HealthCheck.Result> results = healthCheckRegistry.runHealthChecks();
assertFalse(results.isEmpty());
results.forEach((k, v) -> assertTrue(v.isHealthy()));
healthCheckRegistry.unregister("uc");
assertThat(healthCheckRegistry.getNames().size(), equalTo(1));
}
}