use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method getTestData.
List<RequestLog> getTestData(long start, String version, boolean appLogsDesired, boolean complete) {
List<RequestLog> list = new ArrayList<>();
for (int i = 0; i < 20; i++) {
Long end;
if (complete) {
end = start + i + 1;
} else {
end = null;
}
RequestLog.Builder rl = getLog(start + i, end, version).toBuilder();
if (appLogsDesired) {
LogLine line = LogLine.newBuilder().setTime(i).setLevel(i % 5).setLogMessage(Integer.toString(i)).build();
rl.addLine(line);
}
list.add(rl.build());
}
return list;
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testNoLogs.
@Test
public void testNoLogs() throws Exception {
boolean noAppLogsDesired = false;
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, noAppLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
// In this test we have request logs with no associated app logs - therefore,
// a query with minimumLogLevel = 0 should exclude them all (returning no
// logs).
List<Long> expectedLogStartTimes = new ArrayList<Long>();
LogQuery query = LogQuery.Builder.withMinLogLevel(LogLevel.DEBUG);
List<Long> actualLogStartTimes = new ArrayList<Long>();
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 testOffsets.
@Test
public void testOffsets() throws Exception {
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
// Logs are stored reverse-chronologically
List<Long> expectedLogStartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(allLogs)) {
expectedLogStartTimes.add(record.getStartTime());
}
LogQuery query = LogQuery.Builder.withDefaults();
List<Long> actualLogStartTimes = new ArrayList<>();
List<String> logOffsets = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualLogStartTimes.add(record.getStartTimeUsec());
logOffsets.add(record.getOffset());
}
String expected = joinLogStartTimes(expectedLogStartTimes);
String actual = joinLogStartTimes(actualLogStartTimes);
assertThat(actual).isEqualTo(expected);
for (int i = 0; i < 20; i++) {
query = LogQuery.Builder.withOffset(logOffsets.get(i));
actualLogStartTimes.clear();
for (RequestLogs record : logService.fetch(query)) {
actualLogStartTimes.add(record.getStartTimeUsec());
logOffsets.add(record.getOffset());
}
expected = joinLogStartTimes(expectedLogStartTimes.subList(i + 1, expectedLogStartTimes.size()));
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 testGetCertainVersionsOfData.
@Test
public void testGetCertainVersionsOfData() throws Exception {
long v1StartTime = 1;
List<RequestLog> v1Data = getTestData(v1StartTime, "1", defaultAppLogsDesired, completeLogsRequested);
writeTestData(v1Data, completeLogsRequested);
long v2StartTime = 40;
List<RequestLog> v2Data = getTestData(v2StartTime, "2", defaultAppLogsDesired, completeLogsRequested);
writeTestData(v2Data, completeLogsRequested);
List<Long> allLogStartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(v2Data)) {
allLogStartTimes.add(record.getStartTime());
}
List<Long> v1StartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(v1Data)) {
allLogStartTimes.add(record.getStartTime());
v1StartTimes.add(record.getStartTime());
}
List<String> bothVersionIds = new ArrayList<>();
bothVersionIds.add("1");
bothVersionIds.add("2");
LogQuery query = LogQuery.Builder.withMajorVersionIds(bothVersionIds);
List<Long> actualStartTimesBothVersions = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualStartTimesBothVersions.add(record.getStartTimeUsec());
}
assertThat(actualStartTimesBothVersions).isEqualTo(allLogStartTimes);
List<String> justFirstVersionId = new ArrayList<>();
justFirstVersionId.add("1");
query.majorVersionIds(justFirstVersionId);
List<Long> actualStartTimesV1 = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualStartTimesV1.add(record.getStartTimeUsec());
}
String expectedV1 = joinLogStartTimes(v1StartTimes);
String actualV1 = joinLogStartTimes(actualStartTimesV1);
assertThat(actualV1).isEqualTo(expectedV1);
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method testGetAllLogs.
@Test
public void testGetAllLogs() throws Exception {
int totalNumItems = LogService.DEFAULT_ITEMS_PER_FETCH * 2;
List<RequestLog> expectedLogs = getTestData(totalNumItems);
// The first request should have all the user-specified filters.
LogReadRequest.Builder initialRequest = LogReadRequest.newBuilder().setAppId(APPLICATION_ID);
initialRequest.addModuleVersionBuilder().setVersionId(MAJOR_VERSION_ID);
initialRequest.setIncludeIncomplete(false).setCount(LogService.DEFAULT_ITEMS_PER_FETCH).setIncludeAppLogs(false);
// The offset returned by the first request will be a reference to where the
// next request should begin - here, since we ask for MAX_ITEMS, the offset
// should be pointing at MAX_ITEMS.
LogOffset offset = LogOffset.newBuilder().setRequestId(ByteString.copyFromUtf8(Integer.toString(LogService.DEFAULT_ITEMS_PER_FETCH))).build();
// The first response will contain the first batch of logs and an offset for
// the second (and last) batch of logs.
LogReadResponse.Builder initialResponse = LogReadResponse.newBuilder();
for (int i = 0; i < LogService.DEFAULT_ITEMS_PER_FETCH; i++) {
initialResponse.addLog(expectedLogs.get(i));
}
initialResponse.setOffset(offset);
// The second request should contain everything the first request had, but
// with the offset given to us by the first response.
LogReadRequest.Builder secondRequest = LogReadRequest.newBuilder().setAppId(APPLICATION_ID);
secondRequest.addModuleVersionBuilder().setVersionId(MAJOR_VERSION_ID);
secondRequest.setIncludeIncomplete(false).setCount(LogService.DEFAULT_ITEMS_PER_FETCH).setIncludeAppLogs(false).setOffset(offset);
// The second response contains the second batch of logs and a None pointer
// in the offset, as there are no more logs after this.
LogReadResponse.Builder secondResponse = LogReadResponse.newBuilder();
for (int i = LogService.DEFAULT_ITEMS_PER_FETCH; i < LogService.DEFAULT_ITEMS_PER_FETCH * 2; i++) {
secondResponse.addLog(expectedLogs.get(i));
}
ApiProxy.ApiConfig apiConfig = new ApiProxy.ApiConfig();
Future<byte[]> mockedFirstFuture = immediateFuture(initialResponse.build().toByteArray());
when(delegate.makeAsyncCall(same(ApiProxy.getCurrentEnvironment()), eq(LogServiceImpl.PACKAGE), eq(LogServiceImpl.READ_RPC_NAME), eq(initialRequest.build().toByteArray()), isA(apiConfig.getClass()))).thenReturn(mockedFirstFuture);
Future<byte[]> mockedSecondFuture = immediateFuture(secondResponse.build().toByteArray());
when(delegate.makeAsyncCall(same(ApiProxy.getCurrentEnvironment()), eq(LogServiceImpl.PACKAGE), eq(LogServiceImpl.READ_RPC_NAME), eq(secondRequest.build().toByteArray()), isA(apiConfig.getClass()))).thenReturn(mockedSecondFuture);
LogQuery query = LogQuery.Builder.withDefaults();
List<RequestLogs> actualLogs = new ArrayList<>();
for (RequestLogs record : new LogServiceImpl().fetch(query)) {
actualLogs.add(record);
}
assertThat(actualLogs).hasSize(expectedLogs.size());
}
Aggregations