public void testStandardValues() throws InvocationTargetException { @SuppressWarnings("unchecked") final Map<String, Boolean> map = mock(Map.class); Map<String, Boolean> forward = new ForwardingMap<String, Boolean>() { @Override protected Map<String, Boolean> delegate() { return map; } @Override public Collection<Boolean> values() { return new StandardValues(); } }; callAllPublicMethods(new TypeToken<Collection<Boolean>>() {}, forward.values()); // These are the methods specified by StandardValues verify(map, atLeast(0)).clear(); verify(map, atLeast(0)).containsValue(anyObject()); verify(map, atLeast(0)).isEmpty(); verify(map, atLeast(0)).size(); verify(map, atLeast(0)).entrySet(); verifyNoMoreInteractions(map); }
public void testStandardKeySet() throws InvocationTargetException { @SuppressWarnings("unchecked") final Map<String, Boolean> map = mock(Map.class); Map<String, Boolean> forward = new ForwardingMap<String, Boolean>() { @Override protected Map<String, Boolean> delegate() { return map; } @Override public Set<String> keySet() { return new StandardKeySet(); } }; callAllPublicMethods(new TypeToken<Set<String>>() {}, forward.keySet()); // These are the methods specified by StandardKeySet verify(map, atLeast(0)).clear(); verify(map, atLeast(0)).containsKey(anyObject()); verify(map, atLeast(0)).isEmpty(); verify(map, atLeast(0)).remove(anyObject()); verify(map, atLeast(0)).size(); verify(map, atLeast(0)).entrySet(); verifyNoMoreInteractions(map); }
@Test public void testFileManagerInit() throws Exception { FilterFileManagerConfig config = new FilterFileManagerConfig(new String[]{"test", "test1"}, new String[]{"com.netflix.blah.SomeFilter"}, 1); FilterFileManager manager = new FilterFileManager(config, filterLoader); manager = spy(manager); doNothing().when(manager).manageFiles(); manager.init(); verify(manager, atLeast(1)).manageFiles(); verify(manager, times(1)).startPoller(); assertNotNull(manager.poller); } }
public void testStandardEntrySet() throws InvocationTargetException { @SuppressWarnings("unchecked") final Map<String, Boolean> map = mock(Map.class); Map<String, Boolean> forward = new ForwardingMap<String, Boolean>() { @Override protected Map<String, Boolean> delegate() { return map; } @Override public Set<Entry<String, Boolean>> entrySet() { return new StandardEntrySet() { @Override public Iterator<Entry<String, Boolean>> iterator() { return Iterators.emptyIterator(); } }; } }; callAllPublicMethods(new TypeToken<Set<Entry<String, Boolean>>>() {}, forward.entrySet()); // These are the methods specified by StandardEntrySet verify(map, atLeast(0)).clear(); verify(map, atLeast(0)).containsKey(anyObject()); verify(map, atLeast(0)).get(anyObject()); verify(map, atLeast(0)).isEmpty(); verify(map, atLeast(0)).remove(anyObject()); verify(map, atLeast(0)).size(); verifyNoMoreInteractions(map); }
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .getTableDescriptors((RpcController)Mockito.any(), (GetTableDescriptorsRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .getTableNames((RpcController)Mockito.any(), (GetTableNamesRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .isCatalogJanitorEnabled((RpcController)Mockito.any(), (IsCatalogJanitorEnabledRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .setBalancerRunning((RpcController)Mockito.any(), (SetBalancerRunningRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .balance((RpcController)Mockito.any(), (BalanceRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .enableCatalogJanitor((RpcController)Mockito.any(), (EnableCatalogJanitorRequest)Mockito.any()); } });
/** * Verify the cohort controller got called once per expected node to start the operation */ private void verifyCohort(ProcedureMember member, int cohortSize, String operationName, byte[] data) { // verify(member, Mockito.times(cohortSize)).submitSubprocedure(Mockito.eq(operationName), // (byte[]) Mockito.argThat(new ArrayEquals(data))); Mockito.verify(member, Mockito.atLeast(cohortSize)).submitSubprocedure(Mockito.any()); }
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .getTableDescriptors((RpcController)Mockito.any(), (GetTableDescriptorsRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .moveRegion((RpcController)Mockito.any(), (MoveRegionRequest)Mockito.any()); } });
@Override public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception { Mockito.verify(masterAdmin, Mockito.atLeast(count)) .getTableDescriptors((RpcController)Mockito.any(), (GetTableDescriptorsRequest)Mockito.any()); } });
@Test public void shouldResumeWhenWritableOnceAgain() throws Exception { // given TransportThrottle throttle = newThrottleAndInstall( channel ); when( channel.isWritable() ).thenReturn( false ).thenReturn( true ); // when throttle.acquire( channel ); // expect verify( lock, atLeast( 1 ) ).lock( any(), anyLong() ); verify( lock, never() ).unlock( any() ); }
@Test public void testFileManagerInit() throws Exception { FilterFileManagerConfig config = new FilterFileManagerConfig(new String[]{"test", "test1"}, new String[]{"com.netflix.blah.SomeFilter"}, 1); FilterFileManager manager = new FilterFileManager(config, filterLoader); manager = spy(manager); doNothing().when(manager).manageFiles(); manager.init(); verify(manager, atLeast(1)).manageFiles(); verify(manager, times(1)).startPoller(); assertNotNull(manager.poller); } }
@Test public void readInactivity() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {0, 1}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {1, 0}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutChannel, atLeast(2)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(2, messages.size()); MessageHeaders headers = messages.get(0).getHeaders(); assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); headers = messages.get(1).getHeaders(); assertEquals(SimpMessageType.DISCONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER)); assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER)); }
@Test void shouldHaveMultipleEndConditions() throws Throwable { // GIVEN ControlledBooleanSupplier endCondition1 = spy( new ControlledBooleanSupplier( false ) ); ControlledBooleanSupplier endCondition2 = spy( new ControlledBooleanSupplier( false ) ); ControlledBooleanSupplier endCondition3 = spy( new ControlledBooleanSupplier( false ) ); Race race = new Race().withEndCondition( endCondition1, endCondition2, endCondition3 ); race.addContestant( () -> endCondition2.set( true ) ); race.addContestants( 3, Runnables.EMPTY_RUNNABLE ); // WHEN race.go(); // THEN verify( endCondition1, atLeast( 4 ) ).getAsBoolean(); verify( endCondition2, atLeast( 4 ) ).getAsBoolean(); }
private void defrag( int nodeCount, RecordStore<RelationshipGroupRecord> groupStore ) { Monitor monitor = mock( Monitor.class ); RelationshipGroupDefragmenter defragmenter = new RelationshipGroupDefragmenter( CONFIG, ExecutionMonitors.invisible(), monitor, AUTO_WITHOUT_PAGECACHE ); // Calculation below correlates somewhat to calculation in RelationshipGroupDefragmenter. // Anyway we verify below that we exercise the multi-pass bit, which is what we want long memory = groupStore.getHighId() * 15 + 200; defragmenter.run( memory, stores, nodeCount ); // Verify that we exercise the multi-pass functionality verify( monitor, atLeast( 2 ) ).defragmentingNodeRange( anyLong(), anyLong() ); verify( monitor, atMost( 10 ) ).defragmentingNodeRange( anyLong(), anyLong() ); }
@Test public void shouldRetransmitNakForMissingData() { final long rebuildPosition = ACTIVE_TERM_POSITION; final long hwmPosition = ACTIVE_TERM_POSITION + (ALIGNED_FRAME_LENGTH * 3); insertDataFrame(offsetOfMessage(0)); insertDataFrame(offsetOfMessage(2)); lossDetector.scan(termBuffer, rebuildPosition, hwmPosition, currentTime, MASK, POSITION_BITS_TO_SHIFT, TERM_ID); currentTime = TimeUnit.MILLISECONDS.toNanos(30); lossDetector.scan(termBuffer, rebuildPosition, hwmPosition, currentTime, MASK, POSITION_BITS_TO_SHIFT, TERM_ID); currentTime = TimeUnit.MILLISECONDS.toNanos(60); lossDetector.scan(termBuffer, rebuildPosition, hwmPosition, currentTime, MASK, POSITION_BITS_TO_SHIFT, TERM_ID); verify(lossHandler, atLeast(2)).onGapDetected(TERM_ID, offsetOfMessage(1), gapLength()); }