use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testGetByRequestId.
@Test
public void testGetByRequestId() throws Exception {
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
String expectedId = allLogs.get(1).getRequestId().toStringUtf8();
List<String> requestIds = new ArrayList<>();
requestIds.add(expectedId);
LogQuery query = LogQuery.Builder.withRequestIds(requestIds);
List<String> actualRequestIds = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualRequestIds.add(record.getRequestId());
}
assertThat(actualRequestIds.size()).isEqualTo(1);
assertThat(actualRequestIds.get(0)).isEqualTo(expectedId);
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testSetStartAndEndTime.
@Test
public void testSetStartAndEndTime() throws Exception {
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
long startTime = 4;
long endTime = 7;
// Logs are stored reverse-chronologically
List<Long> expectedLogStartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(allLogs)) {
if ((record.getEndTime() >= startTime) && (record.getEndTime() < endTime)) {
expectedLogStartTimes.add(record.getStartTime());
}
}
LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime).endTimeUsec(endTime);
List<Long> actualLogStartTimes = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualLogStartTimes.add(record.getStartTimeUsec());
}
String expected = joinLogStartTimes(expectedLogStartTimes);
String actual = joinLogStartTimes(actualLogStartTimes);
assertThat(actual).isEqualTo(expected);
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testGetOneLog.
@Test
public void testGetOneLog() throws Exception {
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
Long expectedFirstLogStartTime = allLogs.get(0).getStartTime();
LogQuery query = LogQuery.Builder.withBatchSize(1);
Long actualFirstLogStartTime = (long) -1;
for (RequestLogs record : logService.fetch(query)) {
actualFirstLogStartTime = record.getStartTimeUsec();
}
assertThat(actualFirstLogStartTime).isEqualTo(expectedFirstLogStartTime);
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testMinLogLevelFiltering.
@Test
public void testMinLogLevelFiltering() throws Exception {
boolean appLogsDesired = true;
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, appLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
List<Integer> allAppLogLevels = new ArrayList<>();
for (RequestLog record : Lists.reverse(allLogs)) {
for (LogLine line : record.getLineList()) {
allAppLogLevels.add(line.getLevel());
}
}
// Test filtering for all legitimate log level values
for (LogLevel minLogLevel : LogLevel.values()) {
int minLogLevelInt = minLogLevel.ordinal();
List<Integer> expectedAppLogLevels = new ArrayList<>();
for (Integer thisLevel : allAppLogLevels) {
if (thisLevel >= minLogLevelInt) {
expectedAppLogLevels.add(thisLevel);
}
}
LogQuery query = LogQuery.Builder.withIncludeAppLogs(appLogsDesired).minLogLevel(minLogLevel);
List<Integer> actualAppLogLevels = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
for (AppLogLine line : record.getAppLogLines()) {
actualAppLogLevels.add(line.getLogLevel().ordinal());
}
}
String expectedLevels = joinAppLogLevels(expectedAppLogLevels);
String actualLevels = joinAppLogLevels(actualAppLogLevels);
assertThat(actualLevels).isEqualTo(expectedLevels);
}
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testIncludeAppLogs.
@Test
public void testIncludeAppLogs() throws Exception {
boolean appLogsDesired = true;
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, appLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
// Try a test where we want app logs
List<Integer> expectedLogLevels = new ArrayList<>();
for (RequestLog item : Lists.reverse(allLogs)) {
for (LogLine line : item.getLineList()) {
expectedLogLevels.add(line.getLevel());
}
}
LogQuery query = LogQuery.Builder.withIncludeAppLogs(appLogsDesired);
List<Integer> actualLogLevels = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
for (AppLogLine line : record.getAppLogLines()) {
actualLogLevels.add(line.getLogLevel().ordinal());
}
}
String expectedLevels = joinAppLogLevels(expectedLogLevels);
String actualLevels = joinAppLogLevels(actualLogLevels);
assertThat(actualLevels).isEqualTo(expectedLevels);
// Now try a test where we don't want app logs
query.includeAppLogs(false);
List<Integer> actualLogLevelsForExcludedQuery = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
for (AppLogLine line : record.getAppLogLines()) {
actualLogLevelsForExcludedQuery.add(line.getLogLevel().ordinal());
}
}
assertThat(actualLogLevelsForExcludedQuery.size()).isEqualTo(0);
}
Aggregations