use of org.apache.hadoop.hive.ql.hooks.HiveProtoLoggingHook.EventLogger in project hive by apache.
the class TestHiveProtoLoggingHook method testPostEventLog.
@Test
public void testPostEventLog() throws Exception {
context.setHookType(HookType.POST_EXEC_HOOK);
context.getPerfLogger().perfLogBegin("test", "LogTest");
context.getPerfLogger().perfLogEnd("test", "LogTest");
EventLogger evtLogger = new EventLogger(conf, SystemClock.getInstance());
evtLogger.handle(context);
evtLogger.shutdown();
HiveHookEventProto event = loadEvent(conf, tmpFolder);
Assert.assertEquals(EventType.QUERY_COMPLETED.name(), event.getEventType());
Assert.assertEquals(System.getProperty("user.name"), event.getUser());
Assert.assertEquals("test_user", event.getRequestUser());
Assert.assertEquals("test_queryId", event.getHiveQueryId());
Assert.assertEquals("test_op_id", event.getOperationId());
assertOtherInfo(event, OtherInfoType.STATUS, Boolean.TRUE.toString());
String val = findOtherInfo(event, OtherInfoType.PERF);
Map<String, Long> map = new ObjectMapper().readValue(val, new TypeReference<Map<String, Long>>() {
});
// This should be really close to zero.
Assert.assertTrue("Expected LogTest in PERF", map.get("LogTest") < 100);
}
use of org.apache.hadoop.hive.ql.hooks.HiveProtoLoggingHook.EventLogger in project hive by apache.
the class TestHiveProtoLoggingHook method testRolloverFiles.
@Test
public void testRolloverFiles() throws Exception {
long waitTime = 100;
context.setHookType(HookType.PRE_EXEC_HOOK);
conf.setTimeDuration(ConfVars.HIVE_PROTO_EVENTS_ROLLOVER_CHECK_INTERVAL.varname, waitTime, TimeUnit.MICROSECONDS);
Path path = new Path(tmpFolder);
FileSystem fs = path.getFileSystem(conf);
AtomicLong time = new AtomicLong();
EventLogger evtLogger = new EventLogger(conf, () -> time.get());
evtLogger.handle(context);
int statusLen = 0;
// Loop to ensure that we give some grace for scheduling issues.
for (int i = 0; i < 3; ++i) {
Thread.sleep(waitTime + 100);
statusLen = fs.listStatus(path).length;
if (statusLen > 0) {
break;
}
}
Assert.assertEquals(1, statusLen);
// Move to next day and ensure a new file gets created.
time.set(24 * 60 * 60 * 1000 + 1000);
for (int i = 0; i < 3; ++i) {
Thread.sleep(waitTime + 100);
statusLen = fs.listStatus(path).length;
if (statusLen > 1) {
break;
}
}
Assert.assertEquals(2, statusLen);
}
Aggregations