@Override public Map<String, String> getImmutableMapOrNull() { final StringMap map = localMap.get(); return map == null ? null : Collections.unmodifiableMap(map.toMap()); }
@Override public Map<String, String> getImmutableMapOrNull() { final StringMap map = localMap.get(); return map == null ? null : Collections.unmodifiableMap(map.toMap()); }
@Override public Map<String, String> getCopy() { final StringMap map = localMap.get(); return map == null ? new HashMap<String, String>() : map.toMap(); }
@Override public Map<String, String> getCopy() { final StringMap map = localMap.get(); return map == null ? new HashMap<String, String>() : map.toMap(); }
private void testContextDataInjector() { ReadOnlyThreadContextMap readOnlythreadContextMap = getThreadContextMap(); assertThat("thread context map class name", (readOnlythreadContextMap == null) ? null : readOnlythreadContextMap.getClass().getName(), is(equalTo(readOnlythreadContextMapClassName))); ContextDataInjector contextDataInjector = createInjector(); StringMap stringMap = contextDataInjector.injectContextData(null, new SortedArrayStringMap()); assertThat("thread context map", ThreadContext.getContext(), allOf(hasEntry("foo", "bar"), not(hasKey("baz")))); assertThat("context map", stringMap.toMap(), allOf(hasEntry("foo", "bar"), not(hasKey("baz")))); if (!stringMap.isFrozen()) { stringMap.clear(); assertThat("thread context map", ThreadContext.getContext(), allOf(hasEntry("foo", "bar"), not(hasKey("baz")))); assertThat("context map", stringMap.toMap().entrySet(), is(empty())); } ThreadContext.put("foo", "bum"); ThreadContext.put("baz", "bam"); assertThat("thread context map", ThreadContext.getContext(), allOf(hasEntry("foo", "bum"), hasEntry("baz", "bam"))); if (stringMap.isFrozen()) { assertThat("context map", stringMap.toMap(), allOf(hasEntry("foo", "bar"), not(hasKey("baz")))); } else { assertThat("context map", stringMap.toMap().entrySet(), is(empty())); } }
stringMap.putValue("test1", "one"); stringMap.putValue("test2", "two"); map = stringMap.toMap();
@Override public Map<String, String> getContextMap() { return contextData.toMap(); }
@SuppressWarnings("unchecked") @Override public Map<String, String> getContextMap() { return contextData.toMap(); }
/** * Returns the immutable copy of the ThreadContext Map. * @return The context Map. */ @Override public Map<String, String> getContextMap() { return contextData.toMap(); }
@Override public Map<String, String> getImmutableMapOrNull() { final StringMap map = localMap.get(); return map == null ? null : Collections.unmodifiableMap(map.toMap()); }
@Override public Map<String, String> getImmutableMapOrNull() { final StringMap map = localMap.get(); return map == null ? null : Collections.unmodifiableMap(map.toMap()); }
@Override public Map<String, String> getCopy() { final StringMap map = localMap.get(); return map == null ? new HashMap<String, String>() : map.toMap(); }
@Override public Map<String, String> getCopy() { final StringMap map = localMap.get(); return map == null ? new HashMap<String, String>() : map.toMap(); }
private static void assertContainsOnlyDefaultTracingEntries(StringMap stringMap) { assertThat(stringMap.toMap()) .containsExactly( "traceId", "00000000000000000000000000000000", "spanId", "0000000000000000", "traceSampled", "false"); }
@Test public void insertConfigurationProperties() { assertThat( new OpenCensusTraceContextDataInjector() .injectContextData( Lists.newArrayList( Property.createProperty("property1", "value1"), Property.createProperty("property2", "value2")), new SortedArrayStringMap()) .toMap()) .containsExactly( "property1", "value1", "property2", "value2", "traceId", "00000000000000000000000000000000", "spanId", "0000000000000000", "traceSampled", "false"); }