Buggy code:
reader . createClusterStateWatchersAndUpdate ( ) ; for ( int i = 0 ; i < nodeCount ; i ++ ) { controllers [ i ] = new OverseerTest . MockZKController ( server . getZkAddress ( ) , ( "node" + i ) , "collection1" ) ; } for ( int i = 0 ; i < nodeCount ; i ++ ) { nodeExecutors [ i ] = Executors . newFixedThreadPool ( 1 , new DefaultSolrThreadFactory ( "testShardAssignment" ) ) ; } final String [ ] ids = new String [ coreCount ] ; for ( int i = 0 ; i < coreCount ; i ++ ) { final int slot = i ; Runnable coreStarter = new Runnable ( ) { @ Override public void run ( ) { final String coreName = "core" + slot ; try { ids [ slot ] = controllers [ ( slot % nodeCount ) ] . publishState ( coreName , ACTIVE , sliceCount ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; fail ( ( "register<seq2seq4repair_space>threw<seq2seq4repair_space>exception:" + ( e . getClass ( ) ) ) ) ; } } } ; nodeExecutors [ ( i % nodeCount ) ] . submit ( coreStarter ) ; } for ( int i = 0 ; i < nodeCount ; i ++ ) { nodeExecutors [ i ] . shutdown ( ) ; } for ( int i = 0 ; i < nodeCount ; i ++ ) { while ( ! ( nodeExecutors [ i ] . awaitTermination ( 100 , TimeUnit . MILLISECONDS ) ) ) ; } for ( int i = 0 ; i < 40 ; i ++ ) { reader . updateClusterState ( true ) ; ClusterState state = reader . getClusterState ( ) ; Map < String , Slice > slices = state . getSlices ( "collection1" ) ; int count = 0 ; for ( String name : slices . keySet ( ) ) { count += slices . get ( name ) . getShards ( ) . size ( ) ; } if ( coreCount == count ) break ; Thread . sleep ( 200 ) ; } for ( int i = 0 ; i < 90 ; i ++ ) { int assignedCount = 0 ; for ( int j = 0 ; j < coreCount ; j ++ ) { if ( ( ids [ j ] ) != null ) { assignedCount ++ ; } } if ( coreCount == assignedCount ) { break ; } Thread . sleep ( 500 ) ; } final HashMap < String , AtomicInteger > counters = new HashMap < String , AtomicInteger > ( ) ; for ( int i = 1 ; i < ( sliceCount + 1 ) ; i ++ ) { counters . put ( ( "shard" + i ) , new AtomicInteger ( ) ) ; } for ( int i = 0 ; i < coreCount ; i ++ ) { final AtomicInteger ai = counters . get ( ids [ i ] ) ; assertNotNull ( ( "could<seq2seq4repair_space>not<seq2seq4repair_space>find<seq2seq4repair_space>counter<seq2seq4repair_space>for<seq2seq4repair_space>shard:" + ( ids [ i ] ) ) , ai ) ; ai . incrementAndGet ( ) ; } for ( String counter : counters . keySet ( ) ) { int count = counters . get ( counter ) . intValue ( ) ; int expectedCount = coreCount // sliceCount ; int min = expectedCount - 1 ; int max = expectedCount + 1 ; if ( ( count < min ) || ( count > max ) ) { fail ( ( ( ( ( ( ( ( "Unevenly<seq2seq4repair_space>assigned<seq2seq4repair_space>shard<seq2seq4repair_space>ids,<seq2seq4repair_space>" + counter ) + "<seq2seq4repair_space>had<seq2seq4repair_space>" ) + count ) + ",<seq2seq4repair_space>expected:<seq2seq4repair_space>" ) + min ) + "-" ) + max ) ) ; } } for ( int i = 0 ; i < sliceCount ; i ++ ) { <START_BUG> assertNotNull ( reader . getLeaderUrl ( "collection1" , ( "shard" + ( i + 1 ) ) ) , 15000 ) ; <END_BUG> } } finally { if ( OverseerTest . DEBUG ) { if ( ( controllers [ 0 ] ) != null ) { zkClient . printLayoutToStdOut ( ) ; } } close ( zkClient ) ; close ( overseerClient ) ; close ( reader ) ; for ( int i = 0 ; i < ( controllers . length ) ; i ++ ) if ( ( controllers [ i ] ) != null ) { controllers [ i ] . close ( ) ; } server . shutdown ( ) ; for ( int i = 0 ; i < nodeCount ; i ++ ) { if ( ( nodeExecutors [ i ] ) != null ) { nodeExecutors [ i ] . shutdownNow ( ) ; } } } } private void waitForCollections ( ZkStateReader stateReader , String ... collections ) throws InterruptedException , KeeperException { } @ Test public void testStateChange ( ) throws Exception { } private void verifyStatus ( ZkStateReader reader , String expectedState ) throws InterruptedException { } private void verifyShardLeader ( ZkStateReader reader , String collection , String shard , String expectedCore ) throws InterruptedException , KeeperException { } @ Test public void testOverseerFailure ( ) throws Exception { } private AtomicInteger killCounter = new AtomicInteger ( ) ; private class OverseerRestarter implements Runnable { SolrZkClient overseerClient = null ; public volatile boolean run = true ; private final String zkAddress ; public OverseerRestarter ( String zkAddress ) { } @ Override public void run ( ) { } } @ Test public void testShardLeaderChange ( ) throws Exception { } @ Test public void testDoubleAssignment ( ) throws Exception { } @ Test public void testPlaceholders ( ) throws Exception { } private void close ( OverseerTest . MockZKController mockController ) { } @ Test public void testReplay ( ) throws Exception { }

Fix:
assertNotNull ( reader . getLeaderUrl ( "collection1" , ( "shard" + ( i + 1 ) ) , 15000 ) ) ;