private void testJoins(String toColl, String fromColl, Integer toDocId, boolean isScoresTest) throws SolrServerException, IOException { // verify the join with fromIndex works final String fromQ = "match_s:c^2"; CloudSolrClient client = cluster.getSolrClient(); { final String joinQ = "{!join " + anyScoreMode(isScoresTest) + "from=join_s fromIndex=" + fromColl + " to=join_s}" + fromQ; QueryRequest qr = new QueryRequest(params("collection", toColl, "q", joinQ, "fl", "id,get_s,score")); QueryResponse rsp = new QueryResponse(client.request(qr), client); SolrDocumentList hits = rsp.getResults(); assertTrue("Expected 1 doc, got " + hits, hits.getNumFound() == 1); SolrDocument doc = hits.get(0); assertEquals(toDocId, doc.getFirstValue("id")); assertEquals("b", doc.getFirstValue("get_s")); assertScore(isScoresTest, doc); } // negative test before creating an alias checkAbsentFromIndex(fromColl, toColl, isScoresTest); // create an alias for the fromIndex and then query through the alias String alias = fromColl + "Alias"; CollectionAdminRequest.CreateAlias request = CollectionAdminRequest.createAlias(alias, fromColl); request.process(client); { final String joinQ = "{!join " + anyScoreMode(isScoresTest) + "from=join_s fromIndex=" + alias + " to=join_s}" + fromQ; final QueryRequest qr = new QueryRequest(params("collection", toColl, "q", joinQ, "fl", "id,get_s,score")); final QueryResponse rsp = new QueryResponse(client.request(qr), client); final SolrDocumentList hits = rsp.getResults(); assertTrue("Expected 1 doc", hits.getNumFound() == 1); SolrDocument doc = hits.get(0); assertEquals(toDocId, doc.getFirstValue("id")); assertEquals("b", doc.getFirstValue("get_s")); assertScore(isScoresTest, doc); } // negative test after creating an alias checkAbsentFromIndex(fromColl, toColl, isScoresTest); { // verify join doesn't work if no match in the "from" index final String joinQ = "{!join " + (anyScoreMode(isScoresTest)) + "from=join_s fromIndex=" + fromColl + " to=join_s}match_s:d"; final QueryRequest qr = new QueryRequest(params("collection", toColl, "q", joinQ, "fl", "id,get_s,score")); final QueryResponse rsp = new QueryResponse(client.request(qr), client); final SolrDocumentList hits = rsp.getResults(); assertTrue("Expected no hits", hits.getNumFound() == 0); } }
private void testSolrJAPICalls() throws Exception { SolrServer server = createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0))); CollectionAdminResponse response; Map<String, NamedList<Integer>> coresStatus; Map<String, NamedList<Integer>> nodesStatus; response = CollectionAdminRequest.createCollection( "solrj_collection", 2, 2, null, null, "conf1", "myOwnField", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); coresStatus = response.getCollectionCoresStatus(); assertEquals(4, coresStatus.size()); for (int i = 0; i < 4; i++) { NamedList<Integer> status = coresStatus.get("solrj_collection_shard" + (i / 2 + 1) + "_replica" + (i % 2 + 1)); assertEquals(0, (int) status.get("status")); assertTrue(status.get("QTime") > 0); } response = CollectionAdminRequest.createCollection("solrj_implicit", "shardA,shardB", "conf1", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); coresStatus = response.getCollectionCoresStatus(); assertEquals(2, coresStatus.size()); response = CollectionAdminRequest.createShard("solrj_implicit", "shardC", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); coresStatus = response.getCollectionCoresStatus(); assertEquals(1, coresStatus.size()); assertEquals(0, (int) coresStatus.get("solrj_implicit_shardC_replica1").get("status")); response = CollectionAdminRequest.deleteShard("solrj_implicit", "shardC", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); nodesStatus = response.getCollectionNodesStatus(); assertEquals(1, nodesStatus.size()); response = CollectionAdminRequest.deleteCollection("solrj_implicit", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); nodesStatus = response.getCollectionNodesStatus(); assertEquals(2, nodesStatus.size()); response = CollectionAdminRequest.createCollection("conf1", 4, "conf1", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); response = CollectionAdminRequest.reloadCollection("conf1", server); assertEquals(0, response.getStatus()); response = CollectionAdminRequest.createAlias("solrj_alias", "conf1,solrj_collection", server); assertEquals(0, response.getStatus()); response = CollectionAdminRequest.deleteAlias("solrj_alias", server); assertEquals(0, response.getStatus()); response = CollectionAdminRequest.splitShard("conf1", "shard1", server); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); coresStatus = response.getCollectionCoresStatus(); assertEquals(0, (int) coresStatus.get("conf1_shard1_0_replica1").get("status")); assertEquals(0, (int) coresStatus.get("conf1_shard1_0_replica1").get("status")); response = CollectionAdminRequest.deleteCollection("conf1", server); assertEquals(0, response.getStatus()); nodesStatus = response.getCollectionNodesStatus(); assertTrue(response.isSuccess()); assertEquals(4, nodesStatus.size()); response = CollectionAdminRequest.deleteCollection("solrj_collection", server); assertEquals(0, response.getStatus()); nodesStatus = response.getCollectionNodesStatus(); assertTrue(response.isSuccess()); assertEquals(4, nodesStatus.size()); }