Buggy code:
cloudClient . setDefaultCollection ( "collection2" ) ; cloudClient . add ( doc6 ) ; cloudClient . add ( doc7 ) ; cloudClient . commit ( ) ; createAlias ( "testalias" , "collection1" ) ; SolrQuery query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; QueryResponse res = cloudClient . query ( query ) ; assertEquals ( 3 , res . getResults ( ) . getNumFound ( ) ) ; query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; JettySolrRunner jetty = jettys . get ( random ( ) . nextInt ( jettys . size ( ) ) ) ; int port = jetty . getLocalPort ( ) ; HttpSolrClient client = new HttpSolrClient ( ( ( buildUrl ( port ) ) + "//testalias" ) ) ; res = client . query ( query ) ; assertEquals ( 3 , res . getResults ( ) . getNumFound ( ) ) ; client . shutdown ( ) ; client = null ; query = new SolrQuery ( "*:*" ) ; jetty = jettys . get ( random ( ) . nextInt ( jettys . size ( ) ) ) ; port = jetty . getLocalPort ( ) ; client = new HttpSolrClient ( ( ( buildUrl ( port ) ) + "//testalias" ) ) ; res = client . query ( query ) ; assertEquals ( 3 , res . getResults ( ) . getNumFound ( ) ) ; client . shutdown ( ) ; client = null ; createAlias ( "testalias" , "collection2,collection1" ) ; CloudSolrClient cloudSolrClient = new CloudSolrClient ( zkServer . getZkAddress ( ) , random ( ) . nextBoolean ( ) ) ; cloudSolrClient . setParallelUpdates ( random ( ) . nextBoolean ( ) ) ; query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; res = cloudSolrClient . query ( query ) ; assertEquals ( 5 , res . getResults ( ) . getNumFound ( ) ) ; query = new SolrQuery ( "*:*" ) ; cloudSolrClient . setDefaultCollection ( "testalias" ) ; res = cloudSolrClient . query ( query ) ; cloudSolrClient . shutdown ( ) ; assertEquals ( 5 , res . getResults ( ) . getNumFound ( ) ) ; query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; jetty = jettys . get ( random ( ) . nextInt ( jettys . size ( ) ) ) ; port = jetty . getLocalPort ( ) ; client = new HttpSolrClient ( ( ( buildUrl ( port ) ) + "//testalias" ) ) ; res = client . query ( query ) ; assertEquals ( 5 , res . getResults ( ) . getNumFound ( ) ) ; query = new SolrQuery ( "*:*" ) ; jetty = jettys . get ( random ( ) . nextInt ( jettys . size ( ) ) ) ; port = jetty . getLocalPort ( ) ; client = new HttpSolrClient ( ( ( buildUrl ( port ) ) + "//testalias" ) ) ; res = client . query ( query ) ; assertEquals ( 5 , res . getResults ( ) . getNumFound ( ) ) ; client . shutdown ( ) ; client = null ; createAlias ( "testalias" , "collection2" ) ; query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; res = cloudClient . query ( query ) ; assertEquals ( 2 , res . getResults ( ) . getNumFound ( ) ) ; createAlias ( "testalias" , "collection1,collection2" ) ; query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; res = cloudClient . query ( query ) ; assertEquals ( 5 , res . getResults ( ) . getNumFound ( ) ) ; query = new SolrQuery ( "*:*" ) ; HttpSolrClient httpclient = new HttpSolrClient ( ( ( getBaseUrl ( ( ( HttpSolrClient ) ( clients . get ( 0 ) ) ) ) ) + "//testalias" ) ) ; res = httpclient . query ( query ) ; assertEquals ( 5 , res . getResults ( ) . getNumFound ( ) ) ; httpclient . shutdown ( ) ; httpclient = null ; createAlias ( "testalias" , "collection2" ) ; createAlias ( "testalias2" , "collection2" ) ; httpclient = new HttpSolrClient ( ( ( getBaseUrl ( ( ( HttpSolrClient ) ( clients . get ( 0 ) ) ) ) ) + "//testalias" ) ) ; SolrInputDocument doc8 = getDoc ( id , 11 , i1 , ( - 600 ) , tlong , 600 , t1 , "humpty<seq2seq4repair_space>dumpy4<seq2seq4repair_space>sat<seq2seq4repair_space>on<seq2seq4repair_space>a<seq2seq4repair_space>walls" ) ; httpclient . add ( doc8 ) ; httpclient . commit ( ) ; <START_BUG> res = client . query ( query ) ; <END_BUG> assertEquals ( 3 , res . getResults ( ) . getNumFound ( ) ) ; httpclient . shutdown ( ) ; httpclient = null ; createAlias ( "testalias" , "collection2,collection1" ) ; query = new SolrQuery ( "*:*" ) ; query . set ( "collection" , "testalias" ) ; res = cloudClient . query ( query ) ; assertEquals ( 6 , res . getResults ( ) . getNumFound ( ) ) ; deleteAlias ( "testalias" ) ; deleteAlias ( "testalias2" ) ; boolean sawException = false ; try { res = cloudClient . query ( query ) ; } catch ( SolrException e ) { sawException = true ; } assertTrue ( sawException ) ; } private void createAlias ( String alias , String collections ) throws IOException , SolrServerException { } private void deleteAlias ( String alias ) throws IOException , SolrServerException { } protected void indexDoc ( List < CloudJettyRunner > skipServers , Object ... fields ) throws IOException , SolrServerException { } }

Fix:
res = httpclient . query ( query ) ;