Search in sources :

Example 21 with UserAgentAnalyzer

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

the class TestBasics method testCacheSetter.

@Test
void testCacheSetter() {
    UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().build();
    userAgentAnalyzer.loadResources("classpath*:SingleDummyMatcher.yaml");
    assertEquals(10000, userAgentAnalyzer.getCacheSize(), "Incorrect default cache size");
    userAgentAnalyzer.setCacheSize(50);
    assertEquals(50, userAgentAnalyzer.getCacheSize(), "Incorrect default cache size");
    userAgentAnalyzer.setCacheSize(50000);
    assertEquals(50000, userAgentAnalyzer.getCacheSize(), "Incorrect default cache size");
    userAgentAnalyzer.setCacheSize(-5);
    assertEquals(0, userAgentAnalyzer.getCacheSize(), "Incorrect default cache size");
    userAgentAnalyzer.setCacheSize(50);
    assertEquals(50, userAgentAnalyzer.getCacheSize(), "Incorrect default cache size");
    userAgentAnalyzer.setCacheSize(50000);
    assertEquals(50000, userAgentAnalyzer.getCacheSize(), "Incorrect default cache size");
    userAgentAnalyzer.setUserAgentMaxLength(555);
    assertEquals(555, userAgentAnalyzer.getUserAgentMaxLength(), "Incorrect user agent max length");
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

Example 22 with UserAgentAnalyzer

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

the class TestJavaSerialization method deserialize.

UserAgentAnalyzer deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    try (ObjectInput in = new ObjectInputStream(bis)) {
        Object o = in.readObject();
        assertTrue(o instanceof UserAgentAnalyzer);
        return (UserAgentAnalyzer) o;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) ObjectInput(java.io.ObjectInput) ObjectInputStream(java.io.ObjectInputStream)

Example 23 with UserAgentAnalyzer

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

the class AbstractSerializationTest method serializeAndDeserializeUAA.

private void serializeAndDeserializeUAA(boolean immediate, boolean runTestsBefore) throws IOException, ClassNotFoundException {
    LOG.info("==============================================================");
    LOG.info("Create");
    LOG.info("--------------------------------------------------------------");
    UserAgentAnalyzerBuilder uaab = UserAgentAnalyzer.newBuilder().keepTests().withCacheInstantiator(new TestingCacheInstantiator()).withCache(1234).hideMatcherLoadStats();
    if (immediate) {
        uaab.immediateInitialization();
    }
    UserAgentAnalyzer uaaBefore = uaab.build();
    String uaaBeforeString = uaaBefore.toString();
    if (runTestsBefore) {
        LOG.info("--------------------------------------------------------------");
        uaaBefore.getTestCases().forEach(testCase -> assertTrue(testCase.verify(uaaBefore)));
        // Get rid of the data of the last tested useragent
        uaaBefore.reset();
        String uaaBeforeAfterTestsString = uaaBefore.toString();
        assertEquals(uaaBeforeString, uaaBeforeAfterTestsString);
    }
    LOG.info("--------------------------------------------------------------");
    LOG.info("Serialize");
    long serializeStartNs = System.nanoTime();
    byte[] bytes = serialize(uaaBefore);
    long serializeStopNs = System.nanoTime();
    LOG.info("Serialize took {} ns ({} ms)", serializeStopNs - serializeStartNs, (serializeStopNs - serializeStartNs) / 1_000_000);
    LOG.info("The UserAgentAnalyzer was serialized into {} bytes", bytes.length);
    LOG.info("--------------------------------------------------------------");
    LOG.info("Deserialize");
    long deserializeStartNs = System.nanoTime();
    UserAgentAnalyzer uaaAfter = deserialize(bytes);
    long deserializeStopNs = System.nanoTime();
    LOG.info("Done");
    LOG.info("Deserialize took {} ns ({} ms)", deserializeStopNs - deserializeStartNs, (deserializeStopNs - deserializeStartNs) / 1_000_000);
    String uaaAfterString = uaaAfter.toString();
    assertEquals(uaaBeforeString, uaaAfterString);
    assertEquals(1234, uaaAfter.getCacheSize());
    LOG.info("==============================================================");
    LOG.info("Validating when getting all fields");
    LOG.info("--------------------------------------------------------------");
    uaaBefore.getTestCases().forEach(testCase -> assertTrue(testCase.verify(uaaBefore)));
    LOG.info("==============================================================");
}
Also used : UserAgentAnalyzerBuilder(nl.basjes.parse.useragent.UserAgentAnalyzer.UserAgentAnalyzerBuilder) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer)

Example 24 with UserAgentAnalyzer

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

the class TestKryoSerialization method deserialize.

UserAgentAnalyzer deserialize(byte[] bytes) {
    Kryo kryo = getKryo();
    ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
    return (UserAgentAnalyzer) kryo.readClassAndObject(byteBufferInput);
}
Also used : ByteBufferInput(com.esotericsoftware.kryo.io.ByteBufferInput) UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Kryo(com.esotericsoftware.kryo.Kryo)

Example 25 with UserAgentAnalyzer

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

the class TestBasics method testUserAgentMaxLengthSetter.

@Test
void testUserAgentMaxLengthSetter() {
    UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().build();
    userAgentAnalyzer.loadResources("classpath*:SingleDummyMatcher.yaml");
    assertEquals(DEFAULT_USER_AGENT_MAX_LENGTH, userAgentAnalyzer.getUserAgentMaxLength(), "Incorrect default user agent max length");
    userAgentAnalyzer.setUserAgentMaxLength(250);
    assertEquals(250, userAgentAnalyzer.getUserAgentMaxLength(), "Incorrect default user agent max length");
    userAgentAnalyzer.setUserAgentMaxLength(-100);
    assertEquals(DEFAULT_USER_AGENT_MAX_LENGTH, userAgentAnalyzer.getUserAgentMaxLength(), "Incorrect default user agent max length");
}
Also used : UserAgentAnalyzer(nl.basjes.parse.useragent.UserAgentAnalyzer) Test(org.junit.jupiter.api.Test)

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