Verifier assertThatValueIs(Metric metric, double expectedValue) { TestContext context = run(metric, false); assertThat(context.doubleValue).isNotNull().isEqualTo(expectedValue); return this; }
Verifier assertThatLeakValueIs(Metric metric, double expectedValue) { TestContext context = run(metric, true); assertThat(context.doubleLeakValue).isNotNull().isEqualTo(expectedValue); return this; }
@Test public void testTimer() throws IOException, InterruptedException { Timer t = metricRegistry.timer(name("timer").tag("foo", "bar").build()); Timer.Context time = t.time(); Thread.sleep(1L); time.stop(); // We slept for 1Ms so we ensure that all timers are above 1ms: assertThat(registry.getSampleValue("timer_seconds", new String[]{"foo", "quantile"}, new String[]{"bar", "0.99"})).isGreaterThan(1 / 1000); assertThat(registry.getSampleValue("timer_seconds_count", new String[]{"foo"}, new String[]{"bar"})).isEqualTo(1); assertThat(registry.getSampleValue("timer_seconds_sum", new String[]{"foo"}, new String[]{"bar"})).isEqualTo(-1); assertThat(registry.getSampleValue("timer_meter_m1", new String[]{"foo"}, new String[]{"bar"})).isNotNull(); assertThat(registry.getSampleValue("timer_meter_total", new String[]{"foo"}, new String[]{"bar"})).isNotNull(); assertEquals(Double.valueOf(1.0D), registry.getSampleValue("timer_seconds_count", new String[]{"foo"}, new String[]{"bar"})); assertNotNull("Metric timer_seconds_count should exist", registry.getSampleValue("timer_seconds_count", new String[]{"foo"}, new String[]{"bar"})); assertTypeHelpTimer("timer"); }
@Test public void getSecondsToMasterByRepoPathListTest() { int timestamp = FIFTEEN_DAYS_AGO - (60 * 60); HashMap<String, Integer> branches1 = new HashMap<String, Integer>(){ { put("refs/remotes/origin/master", ONE_DAY_AGO); } }; HashMap<String, Integer> branches2 = new HashMap<String, Integer>(){ { put("refs/remotes/origin/master", SEVEN_DAYS_AGO); } }; Commit commit1 = new Commit().setRepository(Arrays.asList(GIT_REPO_URLS).get(0)).setTimestamp(timestamp).setBranches(branches1); Commit commit2 = new Commit().setRepository(Arrays.asList(GIT_REPO_URLS).get(2)).setTimestamp(timestamp).setBranches(branches2); repository.saveAll(Arrays.asList(commit1, commit2)); long now = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()); long thirtyDaysAgo = now - (30 * 60 * 60 * 24); Double seconds = repository.getSecondsToMaster(Collections.singletonList(GIT_REPO_URLS[1]), thirtyDaysAgo); assertThat(seconds).isNotNull(); assertThat(seconds).isEqualTo(ONE_DAY_AGO - timestamp); }