本文整理汇总了Java中org.apache.logging.log4j.util.SortedArrayStringMap类的典型用法代码示例。如果您正苦于以下问题:Java SortedArrayStringMap类的具体用法?Java SortedArrayStringMap怎么用?Java SortedArrayStringMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortedArrayStringMap类属于org.apache.logging.log4j.util包,在下文中一共展示了SortedArrayStringMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLogEvent
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
private LogEvent createLogEvent(DateTime timestamp) {
final MutableLogEvent logEvent = new MutableLogEvent();
logEvent.setMessage(new SimpleMessage("Test"));
logEvent.setLevel(Level.TRACE);
logEvent.setLoggerName("org.example.Test");
logEvent.setMarker(MarkerManager.getMarker("TestMarker"));
logEvent.setTimeMillis(timestamp.getMillis());
logEvent.setNanoTime(42L);
logEvent.setContextStack(new MutableThreadContextStack(ImmutableList.of("one", "two")));
final SortedArrayStringMap contextData = new SortedArrayStringMap(1);
contextData.putValue("foobar", "quux");
logEvent.setContextData(contextData);
logEvent.setThreadId(23L);
logEvent.setThreadName("thread-name");
logEvent.setThreadPriority(42);
logEvent.setThrown(new Throwable("Test", new Throwable("cause")));
logEvent.setIncludeLocation(true);
return logEvent.createMemento();
}
示例2: testConvert02
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void testConvert02() {
final StringMap map = new SortedArrayStringMap();
map.putValue("someKey", "coolValue");
map.putValue("anotherKey", "testValue");
map.putValue("myKey", "yourValue");
final String converted = this.converter.convertToDatabaseColumn(map);
assertNotNull("The converted value should not be null.", converted);
final ReadOnlyStringMap reversed = this.converter.convertToEntityAttribute(converted);
assertNotNull("The reversed value should not be null.", reversed);
assertEquals("The reversed value is not correct.", map, reversed);
}
示例3: setup
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Setup
public void setup() {
openHashMapContextData = new OpenHashStringMap<>();
sortedStringArrayMap = new SortedArrayStringMap();
map = new HashMap<>();
keys = new String[count];
final Random r = new Random();
for (int j = 0; j < keys.length; j++) {
final char[] str = new char[length];
for (int i = 0; i < str.length; i++) {
str[i] = (char) r.nextInt();
}
keys[j] = new String(str);
}
populatedMap = new HashMap<>();
for (int i = 0; i < count; i++) {
populatedMap.put(keys[i], value);
}
populatedSortedStringArrayMap = new SortedArrayStringMap();
for (int i = 0; i < count; i++) {
populatedSortedStringArrayMap.putValue(keys[i], value);
}
populatedOpenHashContextData = new OpenHashStringMap<>();
for (int i = 0; i < count; i++) {
populatedOpenHashContextData.putValue(keys[i], value);
}
}
示例4: testConvert01
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void testConvert01() {
final StringMap map = new SortedArrayStringMap();
map.putValue("test1", "another1");
map.putValue("key2", "value2");
final String converted = this.converter.convertToDatabaseColumn(map);
assertNotNull("The converted value should not be null.", converted);
final ReadOnlyStringMap reversed = this.converter.convertToEntityAttribute(converted);
assertNotNull("The reversed value should not be null.", reversed);
assertEquals("The reversed value is not correct.", map, reversed);
}
示例5: testConvertToDatabaseColumn01
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void testConvertToDatabaseColumn01() {
final StringMap map = new SortedArrayStringMap();
map.putValue("test1", "another1");
map.putValue("key2", "value2");
assertEquals("The converted value is not correct.", map.toString(),
this.converter.convertToDatabaseColumn(map));
}
示例6: testConvertToDatabaseColumn02
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void testConvertToDatabaseColumn02() {
final StringMap map = new SortedArrayStringMap();
map.putValue("someKey", "coolValue");
map.putValue("anotherKey", "testValue");
map.putValue("myKey", "yourValue");
assertEquals("The converted value is not correct.", map.toString(),
this.converter.convertToDatabaseColumn(map));
}
示例7: getReadOnlyContextData
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Override
public StringMap getReadOnlyContextData() {
final Map<String, String> copy = getCopy();
if (copy.isEmpty()) {
return EMPTY_CONTEXT_DATA;
}
final StringMap result = new SortedArrayStringMap();
for (final Entry<String, String> entry : copy.entrySet()) {
result.putValue(entry.getKey(), entry.getValue());
}
return result;
}
示例8: createContextData
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
public static StringMap createContextData() {
if (DEFAULT_CONSTRUCTOR == null) {
return new SortedArrayStringMap();
}
try {
return (IndexedStringMap) DEFAULT_CONSTRUCTOR.invoke();
} catch (final Throwable ignored) {
return new SortedArrayStringMap();
}
}
示例9: MapFilter
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
protected MapFilter(final Map<String, List<String>> map, final boolean oper, final Result onMatch, final Result onMismatch) {
super(onMatch, onMismatch);
this.isAnd = oper;
Objects.requireNonNull(map, "map cannot be null");
this.map = new SortedArrayStringMap(map.size());
for (final Map.Entry<String, List<String>> entry : map.entrySet()) {
this.map.putValue(entry.getKey(), entry.getValue());
}
}
示例10: intArgSetsCapacityIfNoPropertySpecified
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void intArgSetsCapacityIfNoPropertySpecified() throws Exception {
final SortedArrayStringMap actual = (SortedArrayStringMap) ContextDataFactory.createContextData(2);
final Field thresholdField = SortedArrayStringMap.class.getDeclaredField("threshold");
thresholdField.setAccessible(true);
assertEquals(2, thresholdField.getInt(actual));
}
示例11: intArgReturnsSortedArrayStringMapIfPropertySpecifiedButMissingIntConstructor
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void intArgReturnsSortedArrayStringMapIfPropertySpecifiedButMissingIntConstructor() throws Exception {
System.setProperty("log4j2.ContextData", FactoryTestStringMapWithoutIntConstructor.class.getName());
assertTrue(ContextDataFactory.createContextData(2) instanceof SortedArrayStringMap);
final SortedArrayStringMap actual = (SortedArrayStringMap) ContextDataFactory.createContextData(2);
final Field thresholdField = SortedArrayStringMap.class.getDeclaredField("threshold");
thresholdField.setAccessible(true);
assertEquals(2, thresholdField.getInt(actual));
System.clearProperty("log4j2.ContextData");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:11,代码来源:ContextDataFactoryPropertySetMissingConstructorTest.java
示例12: testContextDataInjector
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
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()));
}
}
示例13: test_mdc_key_access
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Test
public void test_mdc_key_access() throws IOException {
// Create the log event.
SimpleMessage message = new SimpleMessage("Hello, World!");
StringMap contextData = new SortedArrayStringMap();
String mdcDirectlyAccessedKey = "mdcKey1";
String mdcDirectlyAccessedValue = "mdcValue1";
contextData.putValue(mdcDirectlyAccessedKey, mdcDirectlyAccessedValue);
String mdcPatternMatchedKey = "mdcKey2";
String mdcPatternMatchedValue = "mdcValue2";
contextData.putValue(mdcPatternMatchedKey, mdcPatternMatchedValue);
String mdcPatternMismatchedKey = "mdcKey3";
String mdcPatternMismatchedValue = "mdcValue3";
contextData.putValue(mdcPatternMismatchedKey, mdcPatternMismatchedValue);
LogEvent logEvent = Log4jLogEvent
.newBuilder()
.setLoggerName(LogstashLayoutTest.class.getSimpleName())
.setLevel(Level.INFO)
.setMessage(message)
.setContextData(contextData)
.build();
// Create the template.
ObjectNode templateRootNode = JSON_NODE_FACTORY.objectNode();
String mdcFieldName = "mdc";
templateRootNode.put(mdcFieldName, "${json:mdc}");
templateRootNode.put(mdcDirectlyAccessedKey, String.format("${json:mdc:%s}", mdcDirectlyAccessedKey));
String template = templateRootNode.toString();
// Create the layout.
BuiltConfiguration configuration = ConfigurationBuilderFactory.newConfigurationBuilder().build();
LogstashLayout layout = LogstashLayout
.newBuilder()
.setConfiguration(configuration)
.setStackTraceEnabled(true)
.setTemplate(template)
.setMdcKeyPattern(mdcPatternMatchedKey)
.build();
// Check the serialized event.
String serializedLogEvent = layout.toSerializable(logEvent);
JsonNode rootNode = OBJECT_MAPPER.readTree(serializedLogEvent);
assertThat(point(rootNode, mdcDirectlyAccessedKey).asText()).isEqualTo(mdcDirectlyAccessedValue);
assertThat(point(rootNode, mdcFieldName, mdcPatternMatchedKey).asText()).isEqualTo(mdcPatternMatchedValue);
assertThat(point(rootNode, mdcFieldName, mdcPatternMismatchedKey).asText()).isNullOrEmpty();
}
示例14: putAllArrayContextData
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Benchmark
public SortedArrayStringMap putAllArrayContextData() {
sortedStringArrayMap.clear();
sortedStringArrayMap.putAll(populatedSortedStringArrayMap);
return sortedStringArrayMap;
}
示例15: cloneArrayContextData
import org.apache.logging.log4j.util.SortedArrayStringMap; //导入依赖的package包/类
@Benchmark
public SortedArrayStringMap cloneArrayContextData() {
return new SortedArrayStringMap(populatedSortedStringArrayMap);
}