Formatting in metrics tests
This commit is contained in:
parent
e150b2ff54
commit
761603c76a
|
@ -16,14 +16,16 @@ public class MetricsTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenMarkMeter_thenCorrectRates() throws InterruptedException {
|
public void whenMarkMeter_thenCorrectRates() throws InterruptedException {
|
||||||
Meter meter = new Meter();
|
Meter meter = new Meter();
|
||||||
|
|
||||||
long initCount = meter.getCount();
|
long initCount = meter.getCount();
|
||||||
|
|
||||||
assertThat(initCount, equalTo(0L));
|
assertThat(initCount, equalTo(0L));
|
||||||
|
|
||||||
meter.mark();
|
meter.mark();
|
||||||
|
|
||||||
assertThat(meter.getCount(), equalTo(1L));
|
assertThat(meter.getCount(), equalTo(1L));
|
||||||
|
|
||||||
meter.mark(20);
|
meter.mark(20);
|
||||||
|
|
||||||
assertThat(meter.getCount(), equalTo(21L));
|
assertThat(meter.getCount(), equalTo(21L));
|
||||||
|
|
||||||
// not use assert for these rate values because they change every time when this test is run
|
// 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
|
@Test
|
||||||
public void whenInitRatioGauge_thenCorrectRatio() {
|
public void whenInitRatioGauge_thenCorrectRatio() {
|
||||||
Gauge<Double> ratioGauge = new AttendanceRatioGauge(15, 20);
|
Gauge<Double> ratioGauge = new AttendanceRatioGauge(15, 20);
|
||||||
|
|
||||||
assertThat(ratioGauge.getValue(), equalTo(0.75));
|
assertThat(ratioGauge.getValue(), equalTo(0.75));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +51,7 @@ public class MetricsTest {
|
||||||
Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
|
Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
|
||||||
List<Long> expected = new ArrayList<Long>();
|
List<Long> expected = new ArrayList<Long>();
|
||||||
expected.add(12L);
|
expected.add(12L);
|
||||||
|
|
||||||
assertThat(activeUsersGauge.getValue(), equalTo(expected));
|
assertThat(activeUsersGauge.getValue(), equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,36 +59,42 @@ public class MetricsTest {
|
||||||
public void whenUseDerivativeGauge_thenCorrectGaugeFromBase() {
|
public void whenUseDerivativeGauge_thenCorrectGaugeFromBase() {
|
||||||
Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
|
Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
|
||||||
Gauge<Integer> activeUserCountGauge = new ActiveUserCountGauge(activeUsersGauge);
|
Gauge<Integer> activeUserCountGauge = new ActiveUserCountGauge(activeUsersGauge);
|
||||||
|
|
||||||
assertThat(activeUserCountGauge.getValue(), equalTo(1));
|
assertThat(activeUserCountGauge.getValue(), equalTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenIncDecCounter_thenCorrectCount() {
|
public void whenIncDecCounter_thenCorrectCount() {
|
||||||
Counter counter = new Counter();
|
Counter counter = new Counter();
|
||||||
|
|
||||||
long initCount = counter.getCount();
|
long initCount = counter.getCount();
|
||||||
|
|
||||||
assertThat(initCount, equalTo(0L));
|
assertThat(initCount, equalTo(0L));
|
||||||
|
|
||||||
counter.inc();
|
counter.inc();
|
||||||
|
|
||||||
assertThat(counter.getCount(), equalTo(1L));
|
assertThat(counter.getCount(), equalTo(1L));
|
||||||
|
|
||||||
counter.inc(11);
|
counter.inc(11);
|
||||||
|
|
||||||
assertThat(counter.getCount(), equalTo(12L));
|
assertThat(counter.getCount(), equalTo(12L));
|
||||||
|
|
||||||
counter.dec();
|
counter.dec();
|
||||||
|
|
||||||
assertThat(counter.getCount(), equalTo(11L));
|
assertThat(counter.getCount(), equalTo(11L));
|
||||||
|
|
||||||
counter.dec(6);
|
counter.dec(6);
|
||||||
|
|
||||||
assertThat(counter.getCount(), equalTo(5L));
|
assertThat(counter.getCount(), equalTo(5L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUpdateHistogram_thenCorrectDistributionData() {
|
public void whenUpdateHistogram_thenCorrectDistributionData() {
|
||||||
Histogram histogram = new Histogram(new UniformReservoir());
|
Histogram histogram = new Histogram(new UniformReservoir());
|
||||||
|
|
||||||
histogram.update(5);
|
histogram.update(5);
|
||||||
long count1 = histogram.getCount();
|
long count1 = histogram.getCount();
|
||||||
|
|
||||||
assertThat(count1, equalTo(1L));
|
assertThat(count1, equalTo(1L));
|
||||||
|
|
||||||
Snapshot snapshot1 = histogram.getSnapshot();
|
Snapshot snapshot1 = histogram.getSnapshot();
|
||||||
assertThat(snapshot1.getValues().length, equalTo(1));
|
assertThat(snapshot1.getValues().length, equalTo(1));
|
||||||
assertThat(snapshot1.getValues()[0], equalTo(5L));
|
assertThat(snapshot1.getValues()[0], equalTo(5L));
|
||||||
|
@ -101,8 +111,11 @@ public class MetricsTest {
|
||||||
|
|
||||||
histogram.update(20);
|
histogram.update(20);
|
||||||
long count2 = histogram.getCount();
|
long count2 = histogram.getCount();
|
||||||
|
|
||||||
assertThat(count2, equalTo(2L));
|
assertThat(count2, equalTo(2L));
|
||||||
|
|
||||||
Snapshot snapshot2 = histogram.getSnapshot();
|
Snapshot snapshot2 = histogram.getSnapshot();
|
||||||
|
|
||||||
assertThat(snapshot2.getValues().length, equalTo(2));
|
assertThat(snapshot2.getValues().length, equalTo(2));
|
||||||
assertThat(snapshot2.getValues()[0], equalTo(5L));
|
assertThat(snapshot2.getValues()[0], equalTo(5L));
|
||||||
assertThat(snapshot2.getValues()[1], equalTo(20L));
|
assertThat(snapshot2.getValues()[1], equalTo(20L));
|
||||||
|
@ -121,11 +134,11 @@ public class MetricsTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenUseTimer_thenCorrectTimerContexts() throws InterruptedException {
|
public void whenUseTimer_thenCorrectTimerContexts() throws InterruptedException {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
|
|
||||||
Timer.Context context1 = timer.time();
|
Timer.Context context1 = timer.time();
|
||||||
TimeUnit.SECONDS.sleep(5);
|
TimeUnit.SECONDS.sleep(5);
|
||||||
|
|
||||||
long elapsed1 = context1.stop();
|
long elapsed1 = context1.stop();
|
||||||
|
|
||||||
assertEquals(5000000000L, elapsed1, 1000000);
|
assertEquals(5000000000L, elapsed1, 1000000);
|
||||||
assertThat(timer.getCount(), equalTo(1L));
|
assertThat(timer.getCount(), equalTo(1L));
|
||||||
assertEquals(0.2, timer.getMeanRate(), 0.1);
|
assertEquals(0.2, timer.getMeanRate(), 0.1);
|
||||||
|
@ -133,6 +146,7 @@ public class MetricsTest {
|
||||||
Timer.Context context2 = timer.time();
|
Timer.Context context2 = timer.time();
|
||||||
TimeUnit.SECONDS.sleep(2);
|
TimeUnit.SECONDS.sleep(2);
|
||||||
context2.close();
|
context2.close();
|
||||||
|
|
||||||
assertThat(timer.getCount(), equalTo(2L));
|
assertThat(timer.getCount(), equalTo(2L));
|
||||||
assertEquals(0.3, timer.getMeanRate(), 0.1);
|
assertEquals(0.3, timer.getMeanRate(), 0.1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,13 @@ public class HealthCheckTest {
|
||||||
assertThat(healthCheckRegistry.getNames().size(), equalTo(2));
|
assertThat(healthCheckRegistry.getNames().size(), equalTo(2));
|
||||||
|
|
||||||
Map<String, HealthCheck.Result> results = healthCheckRegistry.runHealthChecks();
|
Map<String, HealthCheck.Result> results = healthCheckRegistry.runHealthChecks();
|
||||||
|
|
||||||
assertFalse(results.isEmpty());
|
assertFalse(results.isEmpty());
|
||||||
|
|
||||||
results.forEach((k, v) -> assertTrue(v.isHealthy()));
|
results.forEach((k, v) -> assertTrue(v.isHealthy()));
|
||||||
|
|
||||||
healthCheckRegistry.unregister("uc");
|
healthCheckRegistry.unregister("uc");
|
||||||
|
|
||||||
assertThat(healthCheckRegistry.getNames().size(), equalTo(1));
|
assertThat(healthCheckRegistry.getNames().size(), equalTo(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue