@Test public void testNonPublicInterfaceLogsWarning() throws Exception { PipelineOptionsFactory.as(NonPublicPipelineOptions.class); // Make sure we print the name of the class. expectedLogs.verifyWarn(NonPublicPipelineOptions.class.getName()); expectedLogs.verifyWarn("all non-public interfaces to be in the same package"); }
/** * Tests that the {@link DataflowPipelineJob} understands that the {@link State#UNKNOWN UNKNOWN} * state is terminal. */ @Test public void testWaitToFinishUnknown() throws Exception { assertEquals(null, mockWaitToFinishInState(State.UNKNOWN)); expectedLogs.verifyWarn("No terminal state was returned. State value UNKNOWN"); }
/** * Test that {@link DataflowPipelineJob#cancel} doesn't throw if the Dataflow service returns * non-terminal state even though the cancel API call failed, which can happen in practice. * * <p>TODO: delete this code if the API calls become consistent. */ @Test public void testCancelTerminatedJobWithStaleState() throws IOException { Dataflow.Projects.Locations.Jobs.Get statusRequest = mock(Dataflow.Projects.Locations.Jobs.Get.class); Job statusResponse = new Job(); statusResponse.setCurrentState("JOB_STATE_RUNNING"); when(mockJobs.get(PROJECT_ID, REGION_ID, JOB_ID)).thenReturn(statusRequest); when(statusRequest.execute()).thenReturn(statusResponse); Dataflow.Projects.Locations.Jobs.Update update = mock(Dataflow.Projects.Locations.Jobs.Update.class); when(mockJobs.update(eq(PROJECT_ID), eq(REGION_ID), eq(JOB_ID), any(Job.class))) .thenReturn(update); when(update.execute()).thenThrow(new IOException("Job has terminated in state SUCCESS")); DataflowPipelineJob job = new DataflowPipelineJob(DataflowClient.create(options), JOB_ID, options, null); State returned = job.cancel(); assertThat(returned, equalTo(State.RUNNING)); expectedLogs.verifyWarn("Cancel failed because job is already terminated."); }
/** Tests that a retryable error is retried enough times. */ @Test public void testRetryableErrorRetryEnoughTimes() throws IOException { when(mockLowLevelRequest.execute()).thenReturn(mockLowLevelResponse); final int retries = 10; when(mockLowLevelResponse.getStatusCode()) .thenAnswer( new Answer<Integer>() { int n = 0; @Override public Integer answer(InvocationOnMock invocation) { return n++ < retries ? 503 : 9999; } }); Storage.Buckets.Get result = storage.buckets().get("test"); try { result.executeUnparsed(); fail(); } catch (IOException e) { } verify(mockHttpResponseInterceptor).interceptResponse(any(HttpResponse.class)); verify(mockLowLevelRequest, atLeastOnce()).addHeader(anyString(), anyString()); verify(mockLowLevelRequest, times(retries + 1)).setTimeout(anyInt(), anyInt()); verify(mockLowLevelRequest, times(retries + 1)).setWriteTimeout(anyInt()); verify(mockLowLevelRequest, times(retries + 1)).execute(); verify(mockLowLevelResponse, times(retries + 1)).getStatusCode(); expectedLogs.verifyWarn("performed 10 retries due to unsuccessful status codes"); }
/** Tests that a non-retriable error is not retried. */ @Test public void testErrorCodeForbidden() throws IOException { when(mockLowLevelRequest.execute()).thenReturn(mockLowLevelResponse); when(mockLowLevelResponse.getStatusCode()) .thenReturn(403) // Non-retryable error. .thenReturn(200); // Shouldn't happen. try { Storage.Buckets.Get result = storage.buckets().get("test"); HttpResponse response = result.executeUnparsed(); assertNotNull(response); } catch (HttpResponseException e) { assertThat(e.getMessage(), Matchers.containsString("403")); } verify(mockHttpResponseInterceptor).interceptResponse(any(HttpResponse.class)); verify(mockLowLevelRequest, atLeastOnce()).addHeader(anyString(), anyString()); verify(mockLowLevelRequest).setTimeout(anyInt(), anyInt()); verify(mockLowLevelRequest).setWriteTimeout(anyInt()); verify(mockLowLevelRequest).execute(); verify(mockLowLevelResponse).getStatusCode(); expectedLogs.verifyWarn("Request failed with code 403"); }
@Test public void testPackageUploadWithLargeClasspathLogsWarning() throws Exception { File tmpFile = makeFileWithContents("file.txt", "This is a test!"); when(mockGcsUtil.getObjects(anyListOf(GcsPath.class))) .thenReturn( ImmutableList.of( StorageObjectOrIOException.create( createStorageObject(STAGING_PATH, tmpFile.length())))); List<String> classpathElements = Lists.newLinkedList(); for (int i = 0; i < 1005; ++i) { String eltName = "element" + i; classpathElements.add(eltName + '=' + tmpFile.getAbsolutePath()); } defaultPackageUtil.stageClasspathElements(classpathElements, STAGING_PATH, createOptions); logged.verifyWarn("Your classpath contains 1005 elements, which Google Cloud Dataflow"); }
@Test public void testSetASingularAttributeUsingAListIsIgnoredWithoutStrictParsing() { String[] args = new String[] {"--diskSizeGb=100", "--diskSizeGb=200"}; PipelineOptionsFactory.fromArgs(args).withoutStrictParsing().create(); expectedLogs.verifyWarn("Strict parsing is disabled, ignoring option"); }
@Test public void testUsingArgumentWithUnknownPropertyIsIgnoredWithoutStrictParsing() { String[] args = new String[] {"--unknownProperty=value"}; PipelineOptionsFactory.fromArgs(args).withoutStrictParsing().create(); expectedLogs.verifyWarn("missing a property named 'unknownProperty'"); }
@Test public void testUsingArgumentStartingWithIllegalCharacterIsIgnoredWithoutStrictParsing() { String[] args = new String[] {" --diskSizeGb=100"}; PipelineOptionsFactory.fromArgs(args).withoutStrictParsing().create(); expectedLogs.verifyWarn("Strict parsing is disabled, ignoring option"); }
@Test public void testUsingArgumentWithInvalidNameIsIgnoredWithoutStrictParsing() { String[] args = new String[] {"--=100"}; PipelineOptionsFactory.fromArgs(args).withoutStrictParsing().create(); expectedLogs.verifyWarn("Strict parsing is disabled, ignoring option"); }
expectedLogs.verifyWarn("Deadlock detected, retrying");
expectedLogs.verifyWarn(String.format(SolrIO.Write.WriteFn.RETRY_ATTEMPT_LOG, 1)); expectedLogs.verifyWarn(String.format(SolrIO.Write.WriteFn.RETRY_ATTEMPT_LOG, 2));
@Test public void testStableUniqueNameWarning() { pipeline.enableAbandonedNodeEnforcement(false); pipeline.getOptions().setStableUniqueNames(CheckEnabled.WARNING); pipeline.apply(Create.of(5, 6, 7)); pipeline.apply(Create.of(5, 6, 7)); ((Pipeline) pipeline).validate(pipeline.getOptions()); logged.verifyWarn("do not have stable unique names"); }
assertThat(thrown, Matchers.instanceOf(SocketTimeoutException.class)); assertEquals(1 + defaultNumberOfRetries, executeCount.get()); expectedLogs.verifyWarn("performed 10 retries due to IOExceptions");
expectedLogs.verifyWarn("WARNINGWARNING"); expectedLogs.verifyWarn(warningTime.toString()); expectedLogs.verifyInfo("BASICBASIC"); expectedLogs.verifyInfo(basicTime.toString());