use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class ContextDataJsonAttributeConverterTest method testConvert02.
@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);
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class ContextDataAttributeConverterTest method testConvertToDatabaseColumn01.
@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));
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class GarbageFreeSortedArrayThreadContextMap method createThreadLocalMap.
// LOG4J2-479: by default, use a plain ThreadLocal, only use InheritableThreadLocal if configured.
// (This method is package protected for JUnit tests.)
private ThreadLocal<StringMap> createThreadLocalMap() {
final PropertiesUtil managerProps = PropertiesUtil.getProperties();
final boolean inheritable = managerProps.getBooleanProperty(INHERITABLE_MAP);
if (inheritable) {
return new InheritableThreadLocal<StringMap>() {
@Override
protected StringMap childValue(final StringMap parentValue) {
return parentValue != null ? createStringMap(parentValue) : null;
}
};
}
// if not inheritable, return plain ThreadLocal with null as initial value
return new ThreadLocal<>();
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class GarbageFreeSortedArrayThreadContextMap method getThreadLocalMap.
private StringMap getThreadLocalMap() {
StringMap map = localMap.get();
if (map == null) {
map = createStringMap();
localMap.set(map);
}
return map;
}
use of org.apache.logging.log4j.util.StringMap in project logging-log4j2 by apache.
the class GarbageFreeSortedArrayThreadContextMap method getReadOnlyContextData.
/**
* {@inheritDoc}
*/
@Override
public StringMap getReadOnlyContextData() {
StringMap map = localMap.get();
if (map == null) {
map = createStringMap();
localMap.set(map);
}
return map;
}
Aggregations