public void run() { context.put(testKey, testValue); finished.countDown(); } });
public void testGetRetrievesPutValue() { final String testKey = "brainy"; final Object testValue = new Object(); context.put(testKey, testValue); assertEquals(testValue, context.get(testKey)); }
public void testGetAfterRemoveReturnsNull() { final String testKey = "hefty"; final Object testValue = new Object(); context.put(testKey, testValue); context.remove(testKey); assertNull("remove() should result in null value for get()", context.get(testKey)); }
public void testClearRemovesValue() { final String testKey = "painter"; context.put(testKey, 7); context.clear(); assertNull("get() after clear should return null", context.get(testKey)); }
public void testClearRemovesMDCValue() { ThreadContext log4jThreadContext = ThreadContext.newMDCEnabledContext(); Hashtable mdcContext = MDC.getContext(); assertTrue(mdcContext == null || mdcContext.isEmpty()); final String testKey = "painter"; log4jThreadContext.put(testKey, 7); mdcContext = MDC.getContext(); assertEquals(1, mdcContext.size()); mdcContext.clear(); assertEquals(0, mdcContext.size()); log4jThreadContext.clear(); assertNull("get() after clear should return null", log4jThreadContext.get(testKey)); } }
@Override public void run() { EventMetricCollector collector = timer.getCollector(); for (int i = 1; i < 30; i++) { try { context.put("Name", randomName()); context.put("Company", randomCompany()); collector.startTiming(this, action); doJob(i); collector.pauseForForward(); collector.startTiming(this, "frog"); collector.stopTiming(); collector.resumeAfterForward(); collector.stopTiming(); context.remove("Name"); context.remove("Company"); } catch (Exception e) { throw new RuntimeException(e); } } }
@Test public void testValuesConvertedToStringsForExport() { ThreadContext context = new ThreadContext(); context.put("stringvalue", "floop"); context.put("intvalue", 99); Timeable t = new Timeable() { @Override public void setEventTimer(EventTimer timer) { } }; EventTimer timer = new EventTimer("foo", new MonitorableRegistry(), ThreadMetricSuite.blank(), false, false, Collections.<StepMeasurementSink>singletonList(new LoggerSink())); timer.registerTimeable(t, "foo"); timer.getCollector().startTiming(t, "stuff"); InProgressSnapshot snapshot = InProgressSnapshot.capture(timer, context); TabularData data = JmxInProgressMonitor.TO_TABULAR_DATA.apply(snapshot); assertEquals(SimpleType.STRING, data.getTabularType().getRowType().getType("stringvalue")); assertEquals(SimpleType.STRING, data.getTabularType().getRowType().getType("intvalue")); }