use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method testGetLogsForTwoDaysAgo.
@Test
public void testGetLogsForTwoDaysAgo() throws Exception {
List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
Long endTime = getTimeForNDaysAgo(1, null);
Long startTime = getTimeForNDaysAgo(1, endTime);
Integer batchSize = null;
LogReadRequest request = createLogReadRequest(startTime, endTime, batchSize, null);
LogReadResponse response = createLogReadResponse(expectedData);
setupExpectations(request, response);
LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime).endTimeUsec(endTime);
List<RequestLogs> actualData = new ArrayList<>();
for (RequestLogs record : new LogServiceImpl().fetch(query)) {
actualData.add(record);
}
String expectedLogs = getJustCombinedRequestFields(expectedData);
String actualLogs = getJustCombinedFields(actualData);
assertThat(actualLogs).isEqualTo(expectedLogs);
}
use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method getAllLogsForAppVersions.
private void getAllLogsForAppVersions(LogQuery query, List<Version> moduleVersions) throws Exception {
List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
Long startTime = null;
Long endTime = null;
Integer batchSize = null;
LogReadRequest request = createLogReadRequest(startTime, endTime, batchSize, moduleVersions);
LogReadResponse response = createLogReadResponse(expectedData);
setupExpectations(request, response);
List<RequestLogs> actualData = new ArrayList<>();
for (RequestLogs record : new LogServiceImpl().fetch(query)) {
actualData.add(record);
}
String expectedLogs = getJustCombinedRequestFields(expectedData);
String actualLogs = getJustCombinedFields(actualData);
assertThat(actualLogs).isEqualTo(expectedLogs);
}
use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method testGetLogsForTwoDaysAgoMillis.
@Test
public void testGetLogsForTwoDaysAgoMillis() throws Exception {
List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
// Use millisecond-aligned microsecond timestamps.
Long endTimeUsec = getTimeForNDaysAgo(1, null) / 1000 * 1000;
Long startTimeUsec = getTimeForNDaysAgo(1, endTimeUsec) / 1000 * 1000;
Long endTimeMillis = endTimeUsec / 1000;
Long startTimeMillis = startTimeUsec / 1000;
Integer batchSize = null;
LogReadRequest request = createLogReadRequest(startTimeMillis * 1000, endTimeMillis * 1000, batchSize, null);
LogReadResponse response = createLogReadResponse(expectedData);
setupExpectations(request, response);
LogQuery query = LogQuery.Builder.withStartTimeMillis(startTimeMillis).endTimeMillis(endTimeMillis);
List<RequestLogs> actualData = new ArrayList<>();
for (RequestLogs record : new LogServiceImpl().fetch(query)) {
actualData.add(record);
}
String expectedLogs = getJustCombinedRequestFields(expectedData);
String actualLogs = getJustCombinedFields(actualData);
assertThat(actualLogs).isEqualTo(expectedLogs);
// Test the Usec/Millis variants.
assertThat(startTimeUsec).isEqualTo(query.getStartTimeUsec());
assertThat(endTimeUsec).isEqualTo(query.getEndTimeUsec());
assertThat(startTimeMillis).isEqualTo(query.getStartTimeMillis());
assertThat(endTimeMillis).isEqualTo(query.getEndTimeMillis());
query = LogQuery.Builder.withEndTimeMillis(endTimeMillis).startTimeMillis(startTimeMillis);
assertThat(startTimeUsec).isEqualTo(query.getStartTimeUsec());
assertThat(endTimeUsec).isEqualTo(query.getEndTimeUsec());
assertThat(startTimeMillis).isEqualTo(query.getStartTimeMillis());
assertThat(endTimeMillis).isEqualTo(query.getEndTimeMillis());
query = LogQuery.Builder.withDefaults();
assertThat(query.getStartTimeUsec()).isNull();
assertThat(query.getEndTimeUsec()).isNull();
assertThat(query.getStartTimeMillis()).isNull();
assertThat(query.getEndTimeMillis()).isNull();
}
use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method createLogReadRequest.
public LogReadRequest createLogReadRequest(Long startTime, Long endTime, Integer batchSize, List<Version> versions, List<String> requestIds) {
LogReadRequest.Builder request = LogReadRequest.newBuilder().setAppId(APPLICATION_ID);
if (startTime != null) {
request.setStartTime(startTime);
}
if (endTime != null) {
request.setEndTime(endTime);
}
if (batchSize != null) {
batchSize = 20;
}
if (versions != null) {
for (Version version : versions) {
LogModuleVersion.Builder requestModuleVersion = request.addModuleVersionBuilder();
if (!version.getModuleId().equals("default")) {
requestModuleVersion.setModuleId(version.getModuleId());
}
requestModuleVersion.setVersionId(version.getVersionId());
}
} else {
request.addModuleVersionBuilder().setVersionId(LogServiceImplTest.MAJOR_VERSION_ID);
}
if (requestIds != null) {
for (String requestId : requestIds) {
request.addRequestId(ByteString.copyFromUtf8(requestId));
}
}
if (batchSize == null) {
batchSize = LogService.DEFAULT_ITEMS_PER_FETCH;
}
return request.setCount(batchSize).setIncludeIncomplete(false).setIncludeAppLogs(false).build();
}
Aggregations