use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.
the class ContextDataAttributeConverterTest method testConvertToDatabaseColumn02.
@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));
}
use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.
the class ContextDataJsonAttributeConverterTest method testConvert01.
@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);
}
use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.
the class ReadOnlyStringMapResolverTest method test_mdc_flatten.
@Test
void test_mdc_flatten() {
// Create the log event.
final SimpleMessage message = new SimpleMessage("Hello, World!");
final StringMap contextData = new SortedArrayStringMap();
final String mdcPatternMatchedKey = "mdcKey1";
final String mdcPatternMatchedValue = "mdcValue1";
contextData.putValue(mdcPatternMatchedKey, mdcPatternMatchedValue);
final String mdcPatternMismatchedKey = "mdcKey2";
final String mdcPatternMismatchedValue = "mdcValue2";
contextData.putValue(mdcPatternMismatchedKey, mdcPatternMismatchedValue);
final LogEvent logEvent = Log4jLogEvent.newBuilder().setMessage(message).setContextData(contextData).build();
// Check the serialized event.
testReadOnlyStringMapFlatten(mdcPatternMatchedKey, mdcPatternMatchedValue, mdcPatternMismatchedKey, logEvent, "mdc");
}
use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.
the class ReadOnlyStringMapResolverTest method test_mdc_pattern.
@Test
void test_mdc_pattern() {
// Create the log event.
final SimpleMessage message = new SimpleMessage("Hello, World!");
final StringMap contextData = new SortedArrayStringMap();
final String mdcPatternMatchedKey = "mdcKey1";
final String mdcPatternMatchedValue = "mdcValue1";
contextData.putValue(mdcPatternMatchedKey, mdcPatternMatchedValue);
final String mdcPatternMismatchedKey = "mdcKey2";
final String mdcPatternMismatchedValue = "mdcValue2";
contextData.putValue(mdcPatternMismatchedKey, mdcPatternMismatchedValue);
final LogEvent logEvent = Log4jLogEvent.newBuilder().setMessage(message).setContextData(contextData).build();
// Check the serialized event.
testReadOnlyStringMapPattern(mdcPatternMatchedKey, mdcPatternMatchedValue, mdcPatternMismatchedKey, logEvent, "mdc");
}
use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.
the class MDCContextMap method getReadOnlyContextData.
@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;
}
Aggregations