use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method testGetLogsForRequestIds.
@Test
public void testGetLogsForRequestIds() throws Exception {
int numRequested = LogService.DEFAULT_ITEMS_PER_FETCH;
List<RequestLog> expectedData = getTestData(numRequested);
List<String> requestIds = new ArrayList<>();
LogReadRequest.Builder request = createLogReadRequest(null, null, null, null, requestIds).toBuilder();
LogReadResponse response = createLogReadResponse(expectedData);
ArrayList<String> queriedIds = new ArrayList<>();
// List<ByteString> expectedIds = request.getRequestIdList();
for (int i = 0; i < numRequested; i++) {
String requestId = Integer.toString(i);
queriedIds.add(requestId);
// expectedIds.add(ByteString.copyFromUtf8(requestId));
request.addRequestId(ByteString.copyFromUtf8(requestId));
}
setupExpectations(request.build(), response);
LogQuery query = LogQuery.Builder.withRequestIds(queriedIds);
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.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method testFetchWithOffset.
@Test
public void testFetchWithOffset() throws Exception {
List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
LogReadRequest.Builder request = createLogReadRequest(null, null, null, null).toBuilder();
LogOffset offset = LogOffset.newBuilder().setRequestId(ByteString.copyFrom(new byte[] { (byte) 0xfe, (byte) 0xff, (byte) 0xcd })).build();
request.setOffset(offset);
LogReadResponse response = createLogReadResponse(expectedData);
setupExpectations(request.build(), response);
LogQuery query = LogQuery.Builder.withDefaults();
query.offset(base64().encode(offset.toByteArray()));
new LogServiceImpl().fetch(query);
// Test negative case.
// Not parseable as Base64.
query.offset("!");
assertThrows(IllegalArgumentException.class, () -> new LogServiceImpl().fetch(query));
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method getJustCombinedRequestFields.
public String getJustCombinedRequestFields(List<RequestLog> data) {
StringBuilder combinedFields = new StringBuilder("[ ");
for (RequestLog datum : data) {
combinedFields.append(datum.getCombined()).append(" ");
}
combinedFields.append("]");
return combinedFields.toString();
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LogServiceImplTest method testGetLogsForLast24Hours.
@Test
public void testGetLogsForLast24Hours() throws Exception {
List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
Long startTime = getTimeForNDaysAgo(1, null);
Long endTime = null;
Integer batchSize = null;
LogReadRequest request = createLogReadRequest(startTime, endTime, batchSize, null);
LogReadResponse response = createLogReadResponse(expectedData);
setupExpectations(request, response);
LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime);
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.RequestLog 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);
}
Aggregations