use of com.yahoo.container.core.AccessLogConfig in project vespa by vespa-engine.
the class AccessLogTest method access_log_can_be_configured.
@Test
public void access_log_can_be_configured() throws Exception {
Element clusterElem = DomBuilderTest.parse("<jdisc id='default' version='1.0'>", " <accesslog type='yapache' ", " fileNamePattern='pattern' rotationInterval='interval'", " rotationScheme='date' />", " <accesslog type='json' ", " fileNamePattern='pattern' rotationInterval='interval'", " rotationScheme='date' />", nodesXml, "</jdisc>");
createModel(root, clusterElem);
{
// yapache
Component<?, ?> accessLogComponent = getContainerComponent("default", YApacheAccessLog.class.getName());
assertNotNull(accessLogComponent);
assertEquals(YApacheAccessLog.class.getName(), accessLogComponent.getClassId().getName(), YApacheAccessLog.class.getName());
AccessLogConfig config = root.getConfig(AccessLogConfig.class, "default/component/com.yahoo.container.logging.YApacheAccessLog");
AccessLogConfig.FileHandler fileHandlerConfig = config.fileHandler();
assertEquals("pattern", fileHandlerConfig.pattern());
assertEquals("interval", fileHandlerConfig.rotation());
assertEquals(AccessLogConfig.FileHandler.RotateScheme.DATE, fileHandlerConfig.rotateScheme());
}
{
// json
Component<?, ?> accessLogComponent = getContainerComponent("default", JSONAccessLog.class.getName());
assertNotNull(accessLogComponent);
assertEquals(JSONAccessLog.class.getName(), accessLogComponent.getClassId().getName(), JSONAccessLog.class.getName());
AccessLogConfig config = root.getConfig(AccessLogConfig.class, "default/component/com.yahoo.container.logging.JSONAccessLog");
AccessLogConfig.FileHandler fileHandlerConfig = config.fileHandler();
assertEquals("pattern", fileHandlerConfig.pattern());
assertEquals("interval", fileHandlerConfig.rotation());
assertEquals(AccessLogConfig.FileHandler.RotateScheme.DATE, fileHandlerConfig.rotateScheme());
}
}
use of com.yahoo.container.core.AccessLogConfig in project vespa by vespa-engine.
the class YApacheLogTestCase method assertCorrectSequenceBehavior.
/**
* author someone-else. Please rewrite this.
*/
private void assertCorrectSequenceBehavior(int startN) throws IOException, InterruptedException {
AccessLogConfig.Builder builder = new AccessLogConfig.Builder().fileHandler(new AccessLogConfig.FileHandler.Builder().pattern("yapachetest2/access").compressOnRotation(false).rotateScheme(AccessLogConfig.FileHandler.RotateScheme.Enum.SEQUENCE));
AccessLogConfig config = new AccessLogConfig(builder);
YApacheAccessLog accessLog = new YApacheAccessLog(config);
try {
// log and rotate trice
accessLog.log(newAccessLogEntry("query1"));
accessLog.rotateNow();
accessLog.log(newAccessLogEntry("query2"));
accessLog.rotateNow();
accessLog.log(newAccessLogEntry("query3.1"));
accessLog.log(newAccessLogEntry("query3.2"));
accessLog.rotateNow();
accessLog.log(newAccessLogEntry("query4"));
// wait for the last rotation, which should cause us to have an "access" file containing query4
int waitTimeMs = 0;
while (!containsExpectedLine("00000000000000010000271000000008?query=query4", "yapachetest2/access", 0)) {
Thread.sleep(2);
waitTimeMs += 2;
if (waitTimeMs > 40 * 1000)
throw new RuntimeException("Waited 40 seconds for the right log file entry to be written, giving up");
}
// Should now have 3 rotated away files
assertTrue(containsExpectedLine("00000000000000010000271000000008?query=query1", "yapachetest2/access." + (startN + 0), 0));
assertTrue(containsExpectedLine("00000000000000010000271000000008?query=query2", "yapachetest2/access." + (startN + 1), 0));
assertTrue(containsExpectedLine("00000000000000010000271000000008?query=query3.1", "yapachetest2/access." + (startN + 2), 0));
assertTrue(containsExpectedLine("00000000000000010000271000000008?query=query3.2", "yapachetest2/access." + (startN + 2), 1));
} finally {
accessLog.shutdown();
deleteDirectory("yapachetest2");
}
}
use of com.yahoo.container.core.AccessLogConfig in project vespa by vespa-engine.
the class YApacheLogTestCase method testYApacheAccessLogWithDateNamingScheme.
/**
* author someone-else. Please rewrite this.
*/
@Test
public void testYApacheAccessLogWithDateNamingScheme() {
AccessLogConfig.Builder builder = new AccessLogConfig.Builder().fileHandler(new AccessLogConfig.FileHandler.Builder().pattern("yapachetest/testaccess.%Y%m%d%H%M%S").symlink("testaccess"));
AccessLogConfig config = new AccessLogConfig(builder);
YApacheAccessLog accessLog = new YApacheAccessLog(config);
try {
final AccessLogEntry entry = newAccessLogEntry("hans");
accessLog.log(entry);
// wait for the log writing thread to do all its work, then check it did it right
// check that symlink appears
int waitTimeMs = 0;
while (!new File("yapachetest/testaccess").exists()) {
Thread.sleep(2);
waitTimeMs += 2;
if (waitTimeMs > 40 * 1000)
throw new RuntimeException("Waited 40 seconds for the configured symlink to be created, giving up");
}
// ..and check that the log entry is written
waitTimeMs = 0;
while (!containsExpectedLine("00000000000000010000271000000008?query=hans", "yapachetest/testaccess", 0)) {
Thread.sleep(2);
waitTimeMs += 2;
if (waitTimeMs > 40 * 1000)
throw new RuntimeException("Waited 40 seconds for a log file entry to be written, giving up");
}
} catch (IOException e) {
throw new RuntimeException("yapache log io exception", e);
} catch (InterruptedException e) {
throw new RuntimeException("Interruption", e);
} finally {
accessLog.shutdown();
deleteDirectory("yapachetest");
}
}
Aggregations