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