Search in sources :

Example 1 with LogReadRequest

use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.

the class LocalLogServiceTest method testHexRequestIdOffsetHandling.

@Test
public void testHexRequestIdOffsetHandling() {
    LogOffset offset = LogOffset.newBuilder().setRequestId(ByteString.copyFromUtf8(String.format("%x", new BigInteger("12345")))).build();
    LogReadRequest request = LogReadRequest.newBuilder().setAppId("").setOffset(offset).build();
    LocalLogService service = new LocalLogService();
    assertThat(service.read(null, request)).isNotNull();
}
Also used : LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) LogOffset(com.google.apphosting.api.logservice.LogServicePb.LogOffset) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 2 with LogReadRequest

use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.

the class LogServiceImplTest method testFutureStorageError.

@Test
public void testFutureStorageError() throws Exception {
    LogReadRequest request = createLogReadRequest(null, null, null, null);
    ApiProxy.ApiConfig apiConfig = new ApiProxy.ApiConfig();
    Future<byte[]> futureMock = immediateFailedFuture(new ApiProxy.ApplicationException(LogServiceError.ErrorCode.STORAGE_ERROR.getNumber(), "Test error detail"));
    when(delegate.makeAsyncCall(same(ApiProxy.getCurrentEnvironment()), eq(LogServiceImpl.PACKAGE), eq(LogServiceImpl.READ_RPC_NAME), eq(request.toByteArray()), isA(apiConfig.getClass()))).thenReturn(futureMock);
    LogServiceException e = assertThrows(LogServiceException.class, () -> new LogServiceImpl().fetch(LogQuery.Builder.withDefaults()));
    assertThat(e).hasMessageThat().isEqualTo("Test error detail");
}
Also used : LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) ApiProxy(com.google.apphosting.api.ApiProxy) Test(org.junit.Test)

Example 3 with LogReadRequest

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

Example 4 with LogReadRequest

use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.

the class LogServiceImplTest method testFutureInvalidRequest.

@Test
public void testFutureInvalidRequest() throws Exception {
    LogReadRequest request = createLogReadRequest(null, null, null, null);
    ApiProxy.ApiConfig apiConfig = new ApiProxy.ApiConfig();
    Future<byte[]> futureMock = immediateFailedFuture(new ApiProxy.ApplicationException(LogServiceError.ErrorCode.INVALID_REQUEST.getNumber(), "Test error detail"));
    when(delegate.makeAsyncCall(same(ApiProxy.getCurrentEnvironment()), eq(LogServiceImpl.PACKAGE), eq(LogServiceImpl.READ_RPC_NAME), eq(request.toByteArray()), isA(apiConfig.getClass()))).thenReturn(futureMock);
    InvalidRequestException e = assertThrows(InvalidRequestException.class, () -> new LogServiceImpl().fetch(LogQuery.Builder.withDefaults()));
    assertThat(e).hasMessageThat().isEqualTo("Test error detail");
}
Also used : LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) ApiProxy(com.google.apphosting.api.ApiProxy) Test(org.junit.Test)

Example 5 with LogReadRequest

use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest in project appengine-java-standard by GoogleCloudPlatform.

the class LogServiceImplTest method testFutureUnrecognizedError.

@Test
public void testFutureUnrecognizedError() throws Exception {
    LogReadRequest request = createLogReadRequest(null, null, null, null);
    ApiProxy.ApiConfig apiConfig = new ApiProxy.ApiConfig();
    Future<byte[]> futureMock = immediateFailedFuture(new ApiProxy.ApplicationException(LogServiceError.ErrorCode.STORAGE_ERROR.getNumber(), "Test error detail"));
    when(delegate.makeAsyncCall(same(ApiProxy.getCurrentEnvironment()), eq(LogServiceImpl.PACKAGE), eq(LogServiceImpl.READ_RPC_NAME), eq(request.toByteArray()), isA(apiConfig.getClass()))).thenReturn(futureMock);
    LogServiceException e = assertThrows(LogServiceException.class, () -> new LogServiceImpl().fetch(LogQuery.Builder.withDefaults()));
    assertThat(e).hasMessageThat().isEqualTo("Test error detail");
}
Also used : LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) ApiProxy(com.google.apphosting.api.ApiProxy) Test(org.junit.Test)

Aggregations

LogReadRequest (com.google.apphosting.api.logservice.LogServicePb.LogReadRequest)9 Test (org.junit.Test)7 ByteString (com.google.protobuf.ByteString)5 LogReadResponse (com.google.apphosting.api.logservice.LogServicePb.LogReadResponse)4 RequestLog (com.google.apphosting.api.logservice.LogServicePb.RequestLog)4 ArrayList (java.util.ArrayList)4 ApiProxy (com.google.apphosting.api.ApiProxy)3 Version (com.google.appengine.api.log.LogQuery.Version)1 LogModuleVersion (com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion)1 LogOffset (com.google.apphosting.api.logservice.LogServicePb.LogOffset)1 BigInteger (java.math.BigInteger)1