org.apache.logging.log4j.ThreadContext.containsKey()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.apache.logging.log4j.ThreadContext.containsKey()方法的一些代码示例,展示了ThreadContext.containsKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.containsKey()方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:containsKey

ThreadContext.containsKey介绍

[英]Determines if the key is in the context.
[中]确定键是否在上下文中。

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void testContainsKey() {
  ThreadContext.clearMap();
  assertFalse(ThreadContext.containsKey("testKey"));
  ThreadContext.put("testKey", "testValue");
  assertTrue(ThreadContext.containsKey("testKey"));
  ThreadContext.remove("testKey");
  assertFalse(ThreadContext.containsKey("testKey"));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void testContainsKey() {
  ThreadContext.clearMap();
  assertFalse(ThreadContext.containsKey("testKey"));
  ThreadContext.put("testKey", "testValue");
  assertTrue(ThreadContext.containsKey("testKey"));
  ThreadContext.remove("testKey");
  assertFalse(ThreadContext.containsKey("testKey"));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void shouldRemoveAnEntryFromTheMapWhenAutoClosed() throws Exception {
  try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value)) {
    assertThat(ThreadContext.get(key), is(value));
  }
  assertThat(ThreadContext.containsKey(key), is(false));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void shouldAddEntriesToBothStackAndMap() throws Exception {
  final String stackValue = "something";
  try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value).push(stackValue)) {
    assertThat(ThreadContext.get(key), is(value));
    assertThat(ThreadContext.peek(), is(stackValue));
  }
  assertThat(ThreadContext.containsKey(key), is(false));
  assertThat(ThreadContext.peek(), is(""));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void testPutAll() {
  ThreadContext.clearMap();
  //
  assertTrue(ThreadContext.isEmpty());
  assertFalse(ThreadContext.containsKey("key"));
  final int mapSize = 10;
  final Map<String, String> newMap = new HashMap<>(mapSize);
  for (int i = 1; i <= mapSize; i++) {
    newMap.put("key" + i, "value" + i);
  }
  ThreadContext.putAll(newMap);
  assertFalse(ThreadContext.isEmpty());
  for (int i = 1; i <= mapSize; i++) {
    assertTrue(ThreadContext.containsKey("key" + i));
    assertEquals("value" + i, ThreadContext.get("key" + i));
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void canReuseCloseableThreadContext() throws Exception {
  final String stackValue = "something";
  // Create a ctc and close it
  final CloseableThreadContext.Instance ctc = CloseableThreadContext.push(stackValue).put(key, value);
  assertThat(ThreadContext.get(key), is(value));
  assertThat(ThreadContext.peek(), is(stackValue));
  ctc.close();
  assertThat(ThreadContext.containsKey(key), is(false));
  assertThat(ThreadContext.peek(), is(""));
  final String anotherKey = "key2";
  final String anotherValue = "value2";
  final String anotherStackValue = "something else";
  // Use it again
  ctc.push(anotherStackValue).put(anotherKey, anotherValue);
  assertThat(ThreadContext.get(anotherKey), is(anotherValue));
  assertThat(ThreadContext.peek(), is(anotherStackValue));
  ctc.close();
  assertThat(ThreadContext.containsKey(anotherKey), is(false));
  assertThat(ThreadContext.peek(), is(""));
}

代码示例来源:origin: zstackio/zstack

if (!ThreadContext.containsKey(Constants.THREAD_CONTEXT_API)) {
  if (args != null) {
    logger.warn(String.format("no task uuid found for:" + fmt, args));

代码示例来源:origin: zstackio/zstack

if (!ThreadContext.containsKey(Constants.THREAD_CONTEXT_API)) {
  if (args != null) {
    logger.warn(String.format("no task uuid found for:" + fmt, args));

代码示例来源:origin: com.visionarts/power-jambda-core

public static void putThreadContext(Context context) {
  if (!ThreadContext.containsKey("AWSRequestId")) {
    // AWS Lambda does not put request id to MDC at cold start,
    // so put it myself
    ThreadContext.put("AWSRequestId", context.getAwsRequestId());
  }
  ThreadContext.put("version", context.getFunctionVersion());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-audit-api

StringBuilder sb = new StringBuilder();
for (String attr : reqCtxAttrs) {
  if (!ThreadContext.containsKey(attr)) {
    if (sb.length() > 0) {
      sb.append(", ");
Attribute attribute = entry.getValue();
String attr = entry.getKey();
if (attribute.isRequired() && !ThreadContext.containsKey(attr)) {
  if (errors.length() > 0) {
    errors.append(", ");
if (!ThreadContext.containsKey(entry.getKey())) {
  continue;

相关文章