Search in sources :

Example 6 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ContextDataFactoryTest method intArgSetsCapacityIfNoPropertySpecified.

@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));
}
Also used : Field(java.lang.reflect.Field) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.Test)

Example 7 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class SortedArrayVsHashMapBenchmark method setup.

@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);
    }
}
Also used : Random(java.util.Random) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Setup(org.openjdk.jmh.annotations.Setup)

Example 8 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap 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);
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.Test)

Example 9 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap 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));
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.Test)

Example 10 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ThreadContextBenchmark method setup.

@Setup
public void setup() {
    System.setProperty("log4j2.threadContextMap", IMPLEMENTATIONS.get(threadContextMapAlias).getName());
    ThreadContextBenchmarkAccess.init();
    injector = ContextDataInjectorFactory.createInjector();
    System.out.println(threadContextMapAlias + ": Injector = " + injector);
    reusableContextData = threadContextMapAlias.contains("Array") ? new SortedArrayStringMap() : new OpenHashStringMap<>();
    keys = new String[count];
    values = new String[count];
    final Random r = new Random();
    for (int j = 0; j < keys.length; j++) {
        final char[] str = new char[KEY_LENGTH];
        for (int i = 0; i < str.length; i++) {
            str[i] = (char) r.nextInt();
        }
        keys[j] = new String(str);
        values[j] = new String(str);
    }
    // count
    final int PROPERTIES_COUNT = 5;
    propertyList = new ArrayList<>(PROPERTIES_COUNT);
    for (int j = 0; j < PROPERTIES_COUNT; j++) {
        final char[] str = new char[KEY_LENGTH];
        for (int i = 0; i < str.length; i++) {
            str[i] = (char) r.nextInt();
        }
        propertyList.add(Property.createProperty(new String(str), new String(str)));
    }
    // ensure ThreadContext contains values
    clearAndPut();
}
Also used : Random(java.util.Random) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) OpenHashStringMap(org.apache.logging.log4j.perf.nogc.OpenHashStringMap) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

SortedArrayStringMap (org.apache.logging.log4j.util.SortedArrayStringMap)12 StringMap (org.apache.logging.log4j.util.StringMap)8 Test (org.junit.Test)8 Field (java.lang.reflect.Field)3 IOException (java.io.IOException)2 Random (java.util.Random)2 Marker (org.apache.logging.log4j.Marker)2 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)2 LogEvent (org.apache.logging.log4j.core.LogEvent)2 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)2 Message (org.apache.logging.log4j.message.Message)2 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)2 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)2 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)2 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)2 ReadOnlyStringMap (org.apache.logging.log4j.util.ReadOnlyStringMap)2 Setup (org.openjdk.jmh.annotations.Setup)2 OpenHashStringMap (org.apache.logging.log4j.perf.nogc.OpenHashStringMap)1