/** Tests that an IOException is retried. */ @Test public void testThrowIOException() throws IOException { when(mockLowLevelRequest.execute()) .thenThrow(new IOException("Fake Error")) .thenReturn(mockLowLevelResponse); when(mockLowLevelResponse.getStatusCode()).thenReturn(200); Storage.Buckets.Get result = storage.buckets().get("test"); HttpResponse response = result.executeUnparsed(); assertNotNull(response); verify(mockHttpResponseInterceptor).interceptResponse(any(HttpResponse.class)); verify(mockLowLevelRequest, atLeastOnce()).addHeader(anyString(), anyString()); verify(mockLowLevelRequest, times(2)).setTimeout(anyInt(), anyInt()); verify(mockLowLevelRequest, times(2)).setWriteTimeout(anyInt()); verify(mockLowLevelRequest, times(2)).execute(); verify(mockLowLevelResponse).getStatusCode(); expectedLogs.verifyDebug("Request failed with IOException"); }
/** Tests that a retriable error is retried. */ @Test public void testRetryableError() throws IOException { when(mockLowLevelRequest.execute()) .thenReturn(mockLowLevelResponse) .thenReturn(mockLowLevelResponse) .thenReturn(mockLowLevelResponse); when(mockLowLevelResponse.getStatusCode()) .thenReturn(503) // Retryable .thenReturn(429) // We also retry on 429 Too Many Requests. .thenReturn(200); Storage.Buckets.Get result = storage.buckets().get("test"); HttpResponse response = result.executeUnparsed(); assertNotNull(response); verify(mockHttpResponseInterceptor).interceptResponse(any(HttpResponse.class)); verify(mockLowLevelRequest, atLeastOnce()).addHeader(anyString(), anyString()); verify(mockLowLevelRequest, times(3)).setTimeout(anyInt(), anyInt()); verify(mockLowLevelRequest, times(3)).setWriteTimeout(anyInt()); verify(mockLowLevelRequest, times(3)).execute(); verify(mockLowLevelResponse, times(3)).getStatusCode(); expectedLogs.verifyDebug("Request failed with code 503"); }
/** Check that a response logs with the correct log. */ @Test public void testResponseLogs() throws IOException { new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("abc", null, "type")); GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL); url.put("uploadType", "type"); String worker = System.getProperty("worker_id"); expectedLogs.verifyDebug("Upload ID for url " + url + " on worker " + worker + " is abc"); } }
@Test public void testRemoveTemporaryTables() throws Exception { FakeDatasetService datasetService = new FakeDatasetService(); String projectId = "project"; String datasetId = "dataset"; datasetService.createDataset(projectId, datasetId, "", "", null); List<TableReference> tableRefs = Lists.newArrayList( BigQueryHelpers.parseTableSpec( String.format("%s:%s.%s", projectId, datasetId, "table1")), BigQueryHelpers.parseTableSpec( String.format("%s:%s.%s", projectId, datasetId, "table2")), BigQueryHelpers.parseTableSpec( String.format("%s:%s.%s", projectId, datasetId, "table3"))); for (TableReference tableRef : tableRefs) { datasetService.createTable(new Table().setTableReference(tableRef)); } // Add one more table to delete that does not actually exist. tableRefs.add( BigQueryHelpers.parseTableSpec(String.format("%s:%s.%s", projectId, datasetId, "table4"))); WriteRename.removeTemporaryTables(datasetService, tableRefs); for (TableReference ref : tableRefs) { loggedWriteRename.verifyDebug("Deleting table " + toJsonString(ref)); checkState(datasetService.getTable(ref) == null, "Table " + ref + " was not deleted!"); } }
/** Tests that a record gets written to the service and messages are logged. */ @Test public void testWriting() throws Exception { final String table = "table"; final String key = "key"; final String value = "value"; service.createTable(table); p.apply("single row", Create.of(makeWrite(key, value)).withCoder(bigtableCoder)) .apply("write", defaultWrite.withTableId(table)); p.run(); logged.verifyDebug("Wrote 1 records"); assertEquals(1, service.tables.size()); assertNotNull(service.getTable(table)); Map<ByteString, ByteString> rows = service.getTable(table); assertEquals(1, rows.size()); assertEquals(ByteString.copyFromUtf8(value), rows.get(ByteString.copyFromUtf8(key))); }
expectedLogs.verifyInfo("DETAILEDDETAILED"); expectedLogs.verifyInfo(detailedTime.toString()); expectedLogs.verifyDebug("DEBUGDEBUG"); expectedLogs.verifyDebug(debugTime.toString()); expectedLogs.verifyTrace("UNKNOWN TIMESTAMP"); expectedLogs.verifyTrace("UNKNOWNUNKNOWN");