Search in sources :

Example 6 with RequestLog

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;
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogLine(com.google.apphosting.api.logservice.LogServicePb.LogLine) AppLogLine(com.google.appengine.api.log.AppLogLine)

Example 7 with RequestLog

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);
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Example 8 with RequestLog

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);
    }
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Example 9 with RequestLog

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);
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Example 10 with RequestLog

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());
}
Also used : ApiProxy(com.google.apphosting.api.ApiProxy) LogOffset(com.google.apphosting.api.logservice.LogServicePb.LogOffset) ArrayList(java.util.ArrayList) RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) LogReadResponse(com.google.apphosting.api.logservice.LogServicePb.LogReadResponse) Test(org.junit.Test)

Aggregations

RequestLog (com.google.apphosting.api.logservice.LogServicePb.RequestLog)28 ByteString (com.google.protobuf.ByteString)20 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)19 LogQuery (com.google.appengine.api.log.LogQuery)13 RequestLogs (com.google.appengine.api.log.RequestLogs)13 LogReadResponse (com.google.apphosting.api.logservice.LogServicePb.LogReadResponse)8 LogReadRequest (com.google.apphosting.api.logservice.LogServicePb.LogReadRequest)7 LogLine (com.google.apphosting.api.logservice.LogServicePb.LogLine)6 AppLogLine (com.google.appengine.api.log.AppLogLine)4 LogOffset (com.google.apphosting.api.logservice.LogServicePb.LogOffset)4 BigInteger (java.math.BigInteger)3 LogLevel (com.google.appengine.api.log.LogService.LogLevel)2 ApiProxy (com.google.apphosting.api.ApiProxy)1 LogModuleVersion (com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion)1 Level (java.util.logging.Level)1