@Test public void testWaitsForGivenTimeoutMillisIfTimeoutSet() throws InterruptedException { long timeout = 2; try { future.get(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } catch (TimeoutException e) { // Expected. } verify(waiter, atLeastOnce()).waitForTimeout(eq(future), eq(timeout)); }
/** * see #testTruncateNotCalledIfSizeIsSameAsTargetSize */ @Test public void testTruncateIfSizeIsDifferentToTargetSize() throws IOException { FileChannel channelMock = mock(FileChannel.class); when(channelMock.size()).thenReturn(42L); when(channelMock.truncate(anyLong())).thenReturn(channelMock); FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false); fileRecords.truncateTo(23); verify(channelMock, atLeastOnce()).size(); verify(channelMock).truncate(23); }
private String getHostFromClient() throws Exception { ArgumentCaptor<InetAddress> addrCaptor = ArgumentCaptor.forClass( InetAddress.class ); verify( ftpClient, atLeastOnce() ).setRemoteAddr( addrCaptor.capture() ); return addrCaptor.getValue().getHostName(); } }
@Test public void testResetNextBatchExpiry() throws Exception { client = spy(new MockClient(time, metadata)); setupWithTransactionState(null); accumulator.append(tp0, 0L, "key".getBytes(), "value".getBytes(), null, null, MAX_BLOCK_TIMEOUT); sender.run(time.milliseconds()); sender.run(time.milliseconds()); time.setCurrentTimeMs(time.milliseconds() + accumulator.getDeliveryTimeoutMs() + 1); sender.run(time.milliseconds()); InOrder inOrder = inOrder(client); inOrder.verify(client, atLeastOnce()).ready(any(), anyLong()); inOrder.verify(client, atLeastOnce()).newClientRequest(anyString(), any(), anyLong(), anyBoolean(), anyInt(), any()); inOrder.verify(client, atLeastOnce()).send(any(), anyLong()); inOrder.verify(client).poll(eq(0L), anyLong()); inOrder.verify(client).poll(eq(accumulator.getDeliveryTimeoutMs()), anyLong()); inOrder.verify(client).poll(geq(1L), anyLong()); }
when(mockAssigner.assignWindows(anyInt(), anyLong(), anyAssignerContext())) .thenReturn(Arrays.asList(new TimeWindow(0, 100))); timeAdaptor.verifyTriggerCallback(mockTrigger, atLeastOnce(), 1L, new TimeWindow(0, 100)); timeAdaptor.verifyTriggerCallback(mockTrigger, times(1), null, null); assertEquals(3, timeAdaptor.numTimers(testHarness)); // +1 because of the GC timer of the window timeAdaptor.verifyTriggerCallback(mockTrigger, atLeastOnce(), 17L, new TimeWindow(0, 100)); timeAdaptor.verifyTriggerCallback(mockTrigger, atLeastOnce(), 42L, new TimeWindow(0, 100)); timeAdaptor.verifyTriggerCallback(mockTrigger, times(3), null, null); assertEquals(1, timeAdaptor.numTimers(testHarness)); // +1 because of the GC timer of the window
/** * Test that truncateTo only calls truncate on the FileChannel if the size of the * FileChannel is bigger than the target size. This is important because some JVMs * change the mtime of the file, even if truncate should do nothing. */ @Test public void testTruncateNotCalledIfSizeIsSameAsTargetSize() throws IOException { FileChannel channelMock = mock(FileChannel.class); when(channelMock.size()).thenReturn(42L); when(channelMock.position(42L)).thenReturn(null); FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false); fileRecords.truncateTo(42); verify(channelMock, atLeastOnce()).size(); verify(channelMock, times(0)).truncate(anyLong()); }
@Test public void testConvertsOtherTimeUnitsToMillisForWaiter() throws InterruptedException { long timeoutMicros = 1000; try { future.get(timeoutMicros, TimeUnit.MICROSECONDS); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } catch (TimeoutException e) { // Expected. } verify(waiter, atLeastOnce()) .waitForTimeout(eq(future), eq(TimeUnit.MICROSECONDS.toMillis(timeoutMicros))); }
private void assertAllNamingEnumerationsClosed(MockResultCollection resultCollection) throws NamingException { for (NamingEnumeration<SearchResult> namingEnumeration : resultCollection) { verify(namingEnumeration, atLeastOnce()).close(); } }
@Test public void shouldUnloadAPlugin() throws BundleException { GoPluginDescriptor pluginDescriptor = mock(GoPluginDescriptor.class); when(pluginDescriptor.bundle()).thenReturn(bundle); spy.unloadPlugin(pluginDescriptor); verify(bundle, atLeastOnce()).stop(); verify(bundle, atLeastOnce()).uninstall(); }
@Test public void testClose() throws NamingException { search = new LdapSearch(conf, ctx); search.close(); verify(ctx, atLeastOnce()).close(); }
private void assertChangeOfCreationDateTo(long createdAt) { verify(issueUpdater, atLeastOnce()) .setCreationDate(same(issue), eq(new Date(createdAt)), any()); } }
@Test public void testReadFullyIfEofIsReached() throws IOException { final FileChannel channelMock = mock(FileChannel.class); final int bufferSize = 100; final String fileChannelContent = "abcdefghkl"; ByteBuffer buffer = ByteBuffer.allocate(bufferSize); when(channelMock.read(any(), anyLong())).then(invocation -> { ByteBuffer bufferArg = invocation.getArgument(0); bufferArg.put(fileChannelContent.getBytes()); return -1; }); Utils.readFully(channelMock, buffer, 0L); assertEquals("abcdefghkl", new String(buffer.array(), 0, buffer.position())); assertEquals(fileChannelContent.length(), buffer.position()); assertTrue(buffer.hasRemaining()); verify(channelMock, atLeastOnce()).read(any(), anyLong()); }
@Test() public void clearFolderSynchronous_shouldListFolders() throws MessagingException { controller.clearFolderSynchronous(account, FOLDER_NAME, listener); verify(listener, atLeastOnce()).listFoldersStarted(account); }
private void seekAndAssert(long seekPos) throws IOException { Assert.assertEquals(verifyInputStream.getPos(), testInputStream.getPos()); long delta = seekPos - testInputStream.getPos(); testInputStream.seek(seekPos); if (delta > 0L && delta <= HadoopDataInputStream.MIN_SKIP_BYTES) { verify(verifyInputStream, atLeastOnce()).skip(anyLong()); verify(verifyInputStream, never()).seek(anyLong()); } else if (delta != 0L) { verify(verifyInputStream, atLeastOnce()).seek(seekPos); verify(verifyInputStream, never()).skip(anyLong()); } else { verify(verifyInputStream, never()).seek(anyLong()); verify(verifyInputStream, never()).skip(anyLong()); } Assert.assertEquals(seekPos, verifyInputStream.getPos()); reset(verifyInputStream); }
/** * Expect a KafkaException if targetSize is bigger than the size of * the FileRecords. */ @Test public void testTruncateNotCalledIfSizeIsBiggerThanTargetSize() throws IOException { FileChannel channelMock = mock(FileChannel.class); when(channelMock.size()).thenReturn(42L); FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false); try { fileRecords.truncateTo(43); fail("Should throw KafkaException"); } catch (KafkaException e) { // expected } verify(channelMock, atLeastOnce()).size(); }
@Test public void clearFolderSynchronous_shouldCloseTheFolder() throws MessagingException { controller.clearFolderSynchronous(account, FOLDER_NAME, listener); verify(localFolder, atLeastOnce()).close(); }
private void authenticateUserAndCheckSearchIsClosed(String user) throws IOException { auth = new LdapAuthenticationProviderImpl(conf, factory); try { auth.Authenticate(user, "password doesn't matter"); } finally { verify(search, atLeastOnce()).close(); } } }
/** * Tests that `readFullyOrFail` behaves correctly if multiple `FileChannel.read` operations are required to fill * the destination buffer. */ @Test public void testReadFullyOrFailWithPartialFileChannelReads() throws IOException { FileChannel channelMock = mock(FileChannel.class); final int bufferSize = 100; ByteBuffer buffer = ByteBuffer.allocate(bufferSize); String expectedBufferContent = fileChannelMockExpectReadWithRandomBytes(channelMock, bufferSize); Utils.readFullyOrFail(channelMock, buffer, 0L, "test"); assertEquals("The buffer should be populated correctly", expectedBufferContent, new String(buffer.array())); assertFalse("The buffer should be filled", buffer.hasRemaining()); verify(channelMock, atLeastOnce()).read(any(), anyLong()); }
@Test public void testAttachPlayer_setsAdUiViewGroup() { setupPlayback(CONTENT_TIMELINE, PREROLL_ADS_DURATIONS_US, PREROLL_CUE_POINTS_SECONDS); imaAdsLoader.attachPlayer(fakeExoPlayer, adsLoaderListener, adUiViewGroup); verify(adDisplayContainer, atLeastOnce()).setAdContainer(adUiViewGroup); }
/** * Tests that `readFullyOrFail` behaves correctly if multiple `FileChannel.read` operations are required to fill * the destination buffer. */ @Test public void testReadFullyWithPartialFileChannelReads() throws IOException { FileChannel channelMock = mock(FileChannel.class); final int bufferSize = 100; String expectedBufferContent = fileChannelMockExpectReadWithRandomBytes(channelMock, bufferSize); ByteBuffer buffer = ByteBuffer.allocate(bufferSize); Utils.readFully(channelMock, buffer, 0L); assertEquals("The buffer should be populated correctly.", expectedBufferContent, new String(buffer.array())); assertFalse("The buffer should be filled", buffer.hasRemaining()); verify(channelMock, atLeastOnce()).read(any(), anyLong()); }