Search in sources :

Example 16 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestBuilder method createWithWantedFieldNames.

private UserAgentAnalyzer createWithWantedFieldNames(String... fieldNames) {
    UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder().dropTests().hideMatcherLoadStats();
    for (String fieldName : fieldNames) {
        builder.withField(fieldName);
    }
    UserAgentAnalyzer userAgentAnalyzer = builder.build();
    Set<String> wantedFieldNames = userAgentAnalyzer.getWantedFieldNames();
    LOG.info("Input : fields({}): {}", fieldNames.length, fieldNames);
    LOG.info("Output: fields({}): {}", wantedFieldNames == null ? "null" : wantedFieldNames.size(), wantedFieldNames);
    return userAgentAnalyzer;
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer)

Example 17 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestBuilder method testWantedFieldNamesAll.

@Test
void testWantedFieldNamesAll() {
    UserAgentAnalyzer uaa = createWithWantedFieldNames();
    assertNull(uaa.getWantedFieldNames());
    Set<String> expectedFields = fields(SYNTAX_ERROR, DEVICE_CLASS, DEVICE_BRAND, DEVICE_NAME, DEVICE_CPU, DEVICE_CPU_BITS, DEVICE_FIRMWARE_VERSION, DEVICE_VERSION, OPERATING_SYSTEM_CLASS, OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_VERSION, OPERATING_SYSTEM_VERSION_MAJOR, OPERATING_SYSTEM_NAME_VERSION, OPERATING_SYSTEM_NAME_VERSION_MAJOR, OPERATING_SYSTEM_VERSION_BUILD, LAYOUT_ENGINE_CLASS, LAYOUT_ENGINE_NAME, LAYOUT_ENGINE_VERSION, LAYOUT_ENGINE_VERSION_MAJOR, LAYOUT_ENGINE_NAME_VERSION, LAYOUT_ENGINE_NAME_VERSION_MAJOR, AGENT_CLASS, AGENT_NAME, AGENT_VERSION, AGENT_VERSION_MAJOR, AGENT_NAME_VERSION, AGENT_NAME_VERSION_MAJOR, AGENT_INFORMATION_EMAIL, AGENT_INFORMATION_URL, AGENT_LANGUAGE, AGENT_LANGUAGE_CODE, AGENT_NAME, AGENT_NAME_VERSION, AGENT_NAME_VERSION_MAJOR, AGENT_SECURITY, AGENT_UUID, AGENT_VERSION, AGENT_VERSION_MAJOR, HACKER_ATTACK_VECTOR, HACKER_TOOLKIT, LAYOUT_ENGINE_BUILD, LAYOUT_ENGINE_CLASS, LAYOUT_ENGINE_NAME, LAYOUT_ENGINE_NAME_VERSION, LAYOUT_ENGINE_NAME_VERSION_MAJOR, LAYOUT_ENGINE_VERSION, LAYOUT_ENGINE_VERSION_MAJOR, WEBVIEW_APP_NAME, WEBVIEW_APP_NAME_VERSION, WEBVIEW_APP_NAME_VERSION_MAJOR, WEBVIEW_APP_VERSION, WEBVIEW_APP_VERSION_MAJOR);
    // We only specify a subset of all fields to test for because otherwise each new field will fail this test.
    List<String> allPossibleFieldNames = uaa.getAllPossibleFieldNamesSorted();
    for (String expectedField : expectedFields) {
        assertTrue(allPossibleFieldNames.contains(expectedField), "Missing field: " + expectedField);
    }
    UserAgent userAgent = uaa.parse(TEST_UA);
    List<String> available = userAgent.getAvailableFieldNamesSorted();
    // We only specify a subset of all fields to test for because otherwise each new field will fail this test.
    for (String expectedField : expectedFields) {
        assertTrue(available.contains(expectedField), "Missing field: " + expectedField);
    }
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) UserAgent(nl.basjes.parse.useragent.UserAgent) Test(org.junit.jupiter.api.Test)

Example 18 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestAnnotationCachesetting method testAnnotationCacheSetting1.

// ----------------------------------------------------------------
@Test
void testAnnotationCacheSetting1() throws IllegalAccessException, NoSuchFieldException {
    UserAgentAnnotationAnalyzer<TestRecord> userAgentAnnotationAnalyzer = new UserAgentAnnotationAnalyzer<>();
    // To make sure the internals behave as expected
    Field userAgentAnalyzerField = userAgentAnnotationAnalyzer.getClass().getDeclaredField("userAgentAnalyzer");
    userAgentAnalyzerField.setAccessible(true);
    assertNull(userAgentAnalyzerField.get(userAgentAnnotationAnalyzer));
    // Initial value
    assertEquals(DEFAULT_PARSE_CACHE_SIZE, userAgentAnnotationAnalyzer.getCacheSize());
    // Setting and getting while no UserAgentAnalyzer exists
    userAgentAnnotationAnalyzer.setCacheSize(1234);
    assertEquals(1234, userAgentAnnotationAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.disableCaching();
    assertEquals(0, userAgentAnnotationAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.setCacheSize(4567);
    assertEquals(4567, userAgentAnnotationAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.initialize(new MyMapper());
    UserAgentAnalyzer userAgentAnalyzer = (UserAgentAnalyzer) userAgentAnalyzerField.get(userAgentAnnotationAnalyzer);
    assertNotNull(userAgentAnalyzer);
    // Setting and getting while there IS a UserAgentAnalyzer
    userAgentAnnotationAnalyzer.setCacheSize(1234);
    assertEquals(1234, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(1234, userAgentAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.disableCaching();
    assertEquals(0, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(0, userAgentAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.setCacheSize(4567);
    assertEquals(4567, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(4567, userAgentAnalyzer.getCacheSize());
}
Also used : Field(java.lang.reflect.Field) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

Example 19 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestAnnotationCachesetting method testAnnotationCacheSetting2.

@Test
void testAnnotationCacheSetting2() throws IllegalAccessException, NoSuchFieldException {
    UserAgentAnnotationAnalyzer<TestRecord> userAgentAnnotationAnalyzer = new UserAgentAnnotationAnalyzer<>();
    // To make sure the internals behave as expected
    Field userAgentAnalyzerField = userAgentAnnotationAnalyzer.getClass().getDeclaredField("userAgentAnalyzer");
    userAgentAnalyzerField.setAccessible(true);
    assertNull(userAgentAnalyzerField.get(userAgentAnnotationAnalyzer));
    // Initial value
    assertEquals(DEFAULT_PARSE_CACHE_SIZE, userAgentAnnotationAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.initialize(new MyMapper());
    UserAgentAnalyzer userAgentAnalyzer = (UserAgentAnalyzer) userAgentAnalyzerField.get(userAgentAnnotationAnalyzer);
    assertNotNull(userAgentAnalyzer);
    // Initial value
    assertEquals(DEFAULT_PARSE_CACHE_SIZE, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(DEFAULT_PARSE_CACHE_SIZE, userAgentAnalyzer.getCacheSize());
    // Setting and getting while there IS a UserAgentAnalyzer
    userAgentAnnotationAnalyzer.setCacheSize(1234);
    assertEquals(1234, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(1234, userAgentAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.disableCaching();
    assertEquals(0, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(0, userAgentAnalyzer.getCacheSize());
    userAgentAnnotationAnalyzer.setCacheSize(4567);
    assertEquals(4567, userAgentAnnotationAnalyzer.getCacheSize());
    assertEquals(4567, userAgentAnalyzer.getCacheSize());
}
Also used : Field(java.lang.reflect.Field) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

Example 20 with UserAgentAnalyzer

use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.

the class TestMemoryFootprint method checkForMemoryLeaksDuringRuns.

@Disabled
@Test
void checkForMemoryLeaksDuringRuns() {
    // NOSONAR: Do not complain about ignored performance test
    UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().withoutCache().hideMatcherLoadStats().keepTests().build();
    LOG.info("Init complete");
    int iterationsDone = 0;
    final int iterationsPerLoop = 1000;
    for (int i = 0; i < 100; i++) {
        long start = System.nanoTime();
        uaa.preHeat(iterationsPerLoop, false);
        long stop = System.nanoTime();
        iterationsDone += iterationsPerLoop;
        long averageNanos = (stop - start) / iterationsPerLoop;
        printMemoryUsage(iterationsDone, averageNanos);
    }
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

UserAgentAnalyzer (nl.basjes.parse.useragent.UserAgentAnalyzer)38 Test (org.junit.jupiter.api.Test)24 UserAgent (nl.basjes.parse.useragent.UserAgent)11 ArrayList (java.util.ArrayList)4 Disabled (org.junit.jupiter.api.Disabled)4 Map (java.util.Map)3 UserAgentAnalyzerBuilder (nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder)3 MissingUserAgentException (nl.basjes.parse.useragent.servlet.exceptions.MissingUserAgentException)3 Kryo (com.esotericsoftware.kryo.Kryo)2 ByteBufferInput (com.esotericsoftware.kryo.io.ByteBufferInput)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInput (java.io.ObjectInput)2 ObjectInputStream (java.io.ObjectInputStream)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 TestCase (nl.basjes.parse.useragent.config.TestCase)2 IngestDocument (org.elasticsearch.ingest.IngestDocument)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2