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");
}
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;
}
}
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("==============================================================");
}
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);
}
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");
}
Aggregations