use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogService method findLogInLogMapOrAddNewLog.
private synchronized RequestLog findLogInLogMapOrAddNewLog(String requestId) {
if (requestId == null) {
requestId = "null";
}
// assumed to be sorted by requestId.
for (int i = 0; i < logs.size(); i++) {
RequestLog possibleLog = logs.get(i);
if (possibleLog.getRequestId().toStringUtf8().equals(requestId)) {
return possibleLog;
}
}
/* Items are sorted in descending order w.r.t. request id. Since request ids
* are monotonically increasing, this means that the new request id we're
* about to generate will have the largest value ever seen in the log list,
* so put it at the beginning of the list. Lists also are not
* thread-safe for adds and deletes, so synchronize access to it. */
// Fill with required fields with dummy data that will be replaced later anyway.
RequestLog.Builder log = RequestLog.newBuilder().setRequestId(ByteString.copyFromUtf8(requestId)).setFinished(false);
LogOffset offset = LogOffset.newBuilder().setRequestId(ByteString.copyFromUtf8(requestId)).build();
RequestLog built = log.setOffset(offset).buildPartial();
logs.add(0, built);
// If there are too many logs stored, remove the oldest (last) one.
if (logs.size() > MAX_NUM_LOGS) {
logs.remove(logs.size() - 1);
}
return built;
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testGetAllLogs.
@Test
public void testGetAllLogs() 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<>();
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 testIncludeIncomplete.
@Test
public void testIncludeIncomplete() throws Exception {
long completeLogStartTime = 10;
List<RequestLog> completeLogs = getTestData(completeLogStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
writeTestData(completeLogs, completeLogsRequested);
long incompleteLogStartTime = 40;
List<RequestLog> incompleteLogs = getTestData(incompleteLogStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
boolean incompleteLogsRequested = false;
writeTestData(incompleteLogs, incompleteLogsRequested);
List<Long> allLogStartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(incompleteLogs)) {
allLogStartTimes.add(record.getStartTime());
}
List<Long> completeLogStartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(completeLogs)) {
allLogStartTimes.add(record.getStartTime());
completeLogStartTimes.add(record.getStartTime());
}
LogQuery query = LogQuery.Builder.withIncludeIncomplete(true);
List<Long> actualStartTimes = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualStartTimes.add(record.getStartTimeUsec());
}
String expected = joinLogStartTimes(allLogStartTimes);
String actual = joinLogStartTimes(actualStartTimes);
assertThat(actual).isEqualTo(expected);
query.includeIncomplete(false);
List<Long> actualCompleteStartTimes = new ArrayList<>();
for (RequestLogs record : logService.fetch(query)) {
actualCompleteStartTimes.add(record.getStartTimeUsec());
}
String expectedIncomplete = joinLogStartTimes(completeLogStartTimes);
String actualIncomplete = joinLogStartTimes(actualCompleteStartTimes);
assertThat(actualIncomplete).isEqualTo(expectedIncomplete);
}
use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.
the class LocalLogServiceTest method testSetStartTime.
@Test
public void testSetStartTime() throws Exception {
List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
writeTestData(allLogs, completeLogsRequested);
long startTime = 4;
// Logs are stored reverse-chronologically
List<Long> expectedLogStartTimes = new ArrayList<>();
for (RequestLog record : Lists.reverse(allLogs)) {
if (record.getEndTime() >= startTime) {
expectedLogStartTimes.add(record.getStartTime());
}
}
LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime);
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 testGetAllLogsWithSmallLimit.
@Test
public void testGetAllLogsWithSmallLimit() 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.withBatchSize(1);
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);
}
Aggregations