@Override public void evaluate() throws Throwable { evaluateRan[0] = true; expectedLogs.verifyNotLogged(messageUnexpected); LOG.info(messageExpected); expectedLogs.verifyInfo(messageExpected); } },
/** * Verify there are no logging events with messages containing the given substring. * * @param substring The message to match against. */ public void verifyNotLogged(String substring) { verifyNotLogged(matcher(substring)); }
private void verifyNo(final Level level, final String substring, final Throwable throwable) { verifyNotLogged(matcher(level, substring, throwable)); }
@Test(expected = AssertionError.class) public void testVerifyNotLoggedWhenMatchedWithException() throws Throwable { String expected = generateRandomString(); LOG.error(expected, new IOException("Fake Exception")); expectedLogs.verifyNotLogged(expected); }
@Test(expected = AssertionError.class) public void testVerifyNotLoggedWhenMatchedFully() throws Throwable { String expected = generateRandomString(); LOG.error(expected); expectedLogs.verifyNotLogged(expected); }
@Test(expected = AssertionError.class) public void testVerifyNotLoggedWhenMatchedPartially() throws Throwable { String expected = generateRandomString(); LOG.error("Extra stuff around expected " + expected + " blah"); expectedLogs.verifyNotLogged(expected); }
@Test public void coderChecksForEquals() throws Exception { SerializableCoder.of(ProperEquals.class); expectedLogs.verifyNotLogged("Can't verify serialized elements of type"); }
@Test public void testVerifyNotLoggedWhenNotMatched() throws Throwable { String expected = generateRandomString(); expectedLogs.verifyNotLogged(expected); }
@Test public void testBasicOperation() throws IOException { when(mockLowLevelRequest.execute()).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).setTimeout(anyInt(), anyInt()); verify(mockLowLevelRequest).setWriteTimeout(anyInt()); verify(mockLowLevelRequest).execute(); verify(mockLowLevelResponse).getStatusCode(); expectedLogs.verifyNotLogged("Request failed"); }
@Test public void testLogsCleared() throws Throwable { final String messageUnexpected = "Message prior to ExpectedLogs."; final String messageExpected = "Message expected."; LOG.info(messageUnexpected); expectedLogs = ExpectedLogs.none(ExpectedLogsTest.class); final boolean[] evaluateRan = new boolean[1]; expectedLogs .apply( new Statement() { @Override public void evaluate() throws Throwable { evaluateRan[0] = true; expectedLogs.verifyNotLogged(messageUnexpected); LOG.info(messageExpected); expectedLogs.verifyInfo(messageExpected); } }, Description.EMPTY) .evaluate(); assertTrue(evaluateRan[0]); // Verify expectedLogs is cleared. expectedLogs.verifyNotLogged(messageExpected); expectedLogs.verifyNotLogged(messageUnexpected); }
/** * Tests that {@link BigQueryServicesImpl.JobServiceImpl#startLoadJob} succeeds with an already * exist job. */ @Test public void testStartLoadJobSucceedsAlreadyExists() throws IOException, InterruptedException { Job testJob = new Job(); JobReference jobRef = new JobReference(); jobRef.setJobId("jobId"); jobRef.setProjectId("projectId"); testJob.setJobReference(jobRef); when(response.getStatusCode()).thenReturn(409); // 409 means already exists Sleeper sleeper = new FastNanoClockAndSleeper(); JobServiceImpl.startJob( testJob, new ApiErrorExtractor(), bigquery, sleeper, BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff())); verify(response, times(1)).getStatusCode(); verify(response, times(1)).getContent(); verify(response, times(1)).getContentType(); expectedLogs.verifyNotLogged("Started BigQuery job"); }
@Test public void testStableUniqueNameOff() { pipeline.enableAbandonedNodeEnforcement(false); pipeline.getOptions().setStableUniqueNames(CheckEnabled.OFF); pipeline.apply(Create.of(5, 6, 7)); pipeline.apply(Create.of(5, 6, 7)); ((Pipeline) pipeline).validate(pipeline.getOptions()); logged.verifyNotLogged("do not have stable unique names"); }
expectedLogs.verifyTrace("UNKNOWN TIMESTAMP"); expectedLogs.verifyTrace("UNKNOWNUNKNOWN"); expectedLogs.verifyNotLogged(unknownTime.toString());
/** Tests the responses that should not log. */ @Test public void testResponseNoLogging() throws IOException { new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, null, null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("hh", "a", null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, "h", null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("hh", null, null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, null, "type")); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("hh", "a", "type")); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, "h", "type")); expectedLogs.verifyNotLogged(""); }