clolov commented on code in PR #12823: URL: https://github.com/apache/kafka/pull/12823#discussion_r1015279648
########## connect/runtime/src/test/java/org/apache/kafka/connect/runtime/SourceTaskOffsetCommitterTest.java: ########## @@ -71,122 +74,74 @@ public void setup() { Long.toString(DEFAULT_OFFSET_COMMIT_INTERVAL_MS)); WorkerConfig config = new StandaloneConfig(workerProps); committer = new SourceTaskOffsetCommitter(config, executor, committers); - Whitebox.setInternalState(SourceTaskOffsetCommitter.class, "log", mockLog); } @SuppressWarnings("unchecked") @Test public void testSchedule() { - Capture<Runnable> taskWrapper = EasyMock.newCapture(); + ArgumentCaptor<Runnable> taskWrapper = ArgumentCaptor.forClass(Runnable.class); - EasyMock.expect(executor.scheduleWithFixedDelay( - EasyMock.capture(taskWrapper), eq(DEFAULT_OFFSET_COMMIT_INTERVAL_MS), + when(executor.scheduleWithFixedDelay( + taskWrapper.capture(), eq(DEFAULT_OFFSET_COMMIT_INTERVAL_MS), eq(DEFAULT_OFFSET_COMMIT_INTERVAL_MS), eq(TimeUnit.MILLISECONDS)) - ).andReturn((ScheduledFuture) commitFuture); - - PowerMock.replayAll(); + ).thenReturn((ScheduledFuture) commitFuture); committer.schedule(taskId, task); - assertTrue(taskWrapper.hasCaptured()); assertNotNull(taskWrapper.getValue()); assertEquals(singletonMap(taskId, commitFuture), committers); - - PowerMock.verifyAll(); } @Test public void testClose() throws Exception { long timeoutMs = 1000; // Normal termination, where termination times out. - executor.shutdown(); - PowerMock.expectLastCall(); - - EasyMock.expect(executor.awaitTermination(eq(timeoutMs), eq(TimeUnit.MILLISECONDS))) - .andReturn(false); - mockLog.error(EasyMock.anyString()); - PowerMock.expectLastCall(); - PowerMock.replayAll(); + when(executor.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS)).thenReturn(false); committer.close(timeoutMs); - PowerMock.verifyAll(); - PowerMock.resetAll(); - // Termination interrupted - executor.shutdown(); - PowerMock.expectLastCall(); - - EasyMock.expect(executor.awaitTermination(eq(timeoutMs), eq(TimeUnit.MILLISECONDS))) - .andThrow(new InterruptedException()); - PowerMock.replayAll(); + when(executor.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS)).thenThrow(new InterruptedException()); committer.close(timeoutMs); - PowerMock.verifyAll(); + verify(executor, times(2)).shutdown(); } @Test public void testRemove() throws Exception { // Try to remove a non-existing task - PowerMock.replayAll(); - assertTrue(committers.isEmpty()); committer.remove(taskId); assertTrue(committers.isEmpty()); - PowerMock.verifyAll(); - PowerMock.resetAll(); - // Try to remove an existing task - EasyMock.expect(taskFuture.cancel(eq(false))).andReturn(false); - EasyMock.expect(taskFuture.isDone()).andReturn(false); - EasyMock.expect(taskFuture.get()).andReturn(null); - EasyMock.expect(taskId.connector()).andReturn("MyConnector"); - EasyMock.expect(taskId.task()).andReturn(1); - PowerMock.replayAll(); + when(taskFuture.cancel(false)).thenReturn(false); + when(taskFuture.isDone()).thenReturn(false); + when(taskFuture.get()) + .thenReturn(null) + .thenThrow(new CancellationException()) + .thenThrow(new InterruptedException()); + when(taskId.connector()).thenReturn("MyConnector"); + when(taskId.task()).thenReturn(1); committers.put(taskId, taskFuture); committer.remove(taskId); assertTrue(committers.isEmpty()); - PowerMock.verifyAll(); - PowerMock.resetAll(); - // Try to remove a cancelled task - EasyMock.expect(taskFuture.cancel(eq(false))).andReturn(false); - EasyMock.expect(taskFuture.isDone()).andReturn(false); - EasyMock.expect(taskFuture.get()).andThrow(new CancellationException()); - EasyMock.expect(taskId.connector()).andReturn("MyConnector"); - EasyMock.expect(taskId.task()).andReturn(1); - mockLog.trace(EasyMock.anyString(), EasyMock.<Object>anyObject()); Review Comment: Amended in the subsequent commit! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org