RequestScopedMdc { public static void clear(RequestContext ctx) { requireNonNull(ctx, "ctx"); synchronized (ctx) { final Object2ObjectMap<String, String> oldMap = getMap(ctx); if (!oldMap.isEmpty()) { ctx.setAttr(MAP, Object2ObjectMaps.emptyMap()); } } } private  RequestScopedMdc(); @Nullable static String get(RequestContext ctx, String key); static Map<String, String> getAll(RequestContext ctx); static void put(RequestContext ctx, String key, @Nullable String value); static void putAll(RequestContext ctx, Map<String, String> map); static void copy(RequestContext ctx, String key); static void copyAll(RequestContext ctx); static void remove(RequestContext ctx, String key); static void clear(RequestContext ctx);  }
@Test void clear() { final ServiceRequestContext ctx = newContext(); RequestScopedMdc.clear(ctx); assertThat(RequestScopedMdc.getAll(ctx)).isEmpty(); RequestScopedMdc.put(ctx, "foo", "1"); RequestScopedMdc.clear(ctx); assertThat(RequestScopedMdc.getAll(ctx)).isEmpty(); }