Examples of CloudSolrServer


Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

    String originalUser = getAuthenticatedUser();
    try {
      setAuthenticationUser(solrUserName);
      try {
        QueryRequest request = populateCollectionAdminParams(adminOp, collectionName);
        CloudSolrServer solrServer = createNewCloudSolrServer();
        try {
          NamedList<Object> result = solrServer.request(request);
          if (adminOp.compareTo(CollectionAction.CREATE) == 0) {
            // Wait for collection creation to complete.
            waitForRecoveriesToFinish(collectionName, solrServer, false);
          }
        } finally {
          solrServer.shutdown();
        }

        fail("The specified user: " + solrUserName + " shouldn't get admin access for " + adminOp);
      } catch (Exception exception) {
        assertTrue("Expected " + SENTRY_ERROR_MSG + " in " + exception.toString(),
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

      if (runAsAdmin == true) {
        // Authenticate as user "admin"
        setAuthenticationUser(ADMIN_USER);
      }

      CloudSolrServer cloudSolrServer = getCloudSolrServer(collectionName);
      assertNotNull("Solr query shouldn't be null.", solrQueryStr);
      SolrDocumentList solrDocs = null;
      try {
        SolrQuery query = new SolrQuery(solrQueryStr);
        QueryResponse response = cloudSolrServer.query(query);
        solrDocs = response.getResults();
        return solrDocs;
      } finally {
        cloudSolrServer.shutdown();
      }
    } finally {
      setAuthenticationUser(originalUser);
    }
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

   * @param collectionName - Name of the collection
   * @return instance of CloudSolrServer
   * @throws MalformedURLException
   */
  protected CloudSolrServer getCloudSolrServer(String collectionName) throws MalformedURLException {
    CloudSolrServer cloudSolrServer = new CloudSolrServer(miniSolrCloudCluster.getZkServer().getZkAddress(),
        RANDOM.nextBoolean());
    cloudSolrServer.setDefaultCollection(collectionName);
    cloudSolrServer.connect();
    return cloudSolrServer;
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

    zkController.getZkClient().makePath(ZkController.CONFIGS_ZKNODE + "/"
      + CONF_DIR_IN_ZK + "/" + nameInZk, new File(file), false, true);
  }

  protected CloudSolrServer createNewCloudSolrServer() throws Exception {
    CloudSolrServer css = new CloudSolrServer(miniSolrCloudCluster.getZkServer().getZkAddress());
    css.connect();
    return css;
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

      // documents returned
      doc.addField(AUTH_FIELD, "docLevel_role");

      docs.add(doc);
    }
    CloudSolrServer server = getCloudSolrServer(collectionName);
    try {
      server.add(docs);
      server.commit(true, true);

      // queries
      SolrQuery query = new SolrQuery();
      query.setQuery("*:*");

      // as admin  -- should get the other half
      setAuthenticationUser("admin");
      QueryResponse  rsp = server.query(query);
      SolrDocumentList docList = rsp.getResults();
      assertEquals(NUM_DOCS / 2, docList.getNumFound());
      for (SolrDocument doc : docList) {
        String id = doc.getFieldValue("id").toString();
        assertEquals(1, Long.valueOf(id) % 2);
      }

      if (checkNonAdminUsers) {
        // as junit -- should get half the documents
        setAuthenticationUser("junit");
        rsp = server.query(query);
        docList = rsp.getResults();
        assertEquals(NUM_DOCS / 2, docList.getNumFound());
        for (SolrDocument doc : docList) {
          String id = doc.getFieldValue("id").toString();
          assertEquals(0, Long.valueOf(id) % 2);
        }

        // as docLevel -- should get all
        setAuthenticationUser("docLevel");
        rsp = server.query(query);
        assertEquals(NUM_DOCS, rsp.getResults().getNumFound());
      }
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

    String collectionName = "docLevelCollection";
    setupCollectionWithDocSecurity(collectionName);

    try {
      createDocsAndQuerySimple(collectionName, true);
      CloudSolrServer server = getCloudSolrServer(collectionName);
      try {
        // test filter queries work as AND -- i.e. user can't avoid doc-level
        // checks by prefixing their own filterQuery
        setAuthenticationUser("junit");
        String fq = URLEncoder.encode(" {!raw f=" + AUTH_FIELD + " v=docLevel_role}");
        String path = "/" + collectionName + "/select?q=*:*&fq="+fq;
        String retValue = makeHttpRequest(server, "GET", path, null, null);
        assertTrue(retValue.contains("numFound=\"" + NUM_DOCS / 2 + "\" "));

        // test that user can't inject an "OR" into the query
        final String syntaxErrorMsg = "org.apache.solr.search.SyntaxError: Cannot parse";
        fq = URLEncoder.encode(" {!raw f=" + AUTH_FIELD + " v=docLevel_role} OR ");
        path = "/" + collectionName + "/select?q=*:*&fq="+fq;
        retValue = makeHttpRequest(server, "GET", path, null, null);
        assertTrue(retValue.contains(syntaxErrorMsg));

        // same test, prefix OR this time
        fq = URLEncoder.encode(" OR {!raw f=" + AUTH_FIELD + " v=docLevel_role}");
        path = "/" + collectionName + "/select?q=*:*&fq="+fq;
        retValue = makeHttpRequest(server, "GET", path, null, null);
        assertTrue(retValue.contains(syntaxErrorMsg));
      } finally {
        server.shutdown();
      }
    } finally {
      deleteCollection(collectionName);
    }
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

      // make sure our factors give us interesting results --
      // that some docs only have all roles and some only have junit
      assert(totalOnlyAllRolesAdded > 0);
      assert(totalJunitAdded > totalAllRolesAdded);

      CloudSolrServer server = getCloudSolrServer(collectionName);
      try {
        server.add(docs);
        server.commit(true, true);

        // queries
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");

        // as admin  -- should only get all roles token documents
        setAuthenticationUser("admin");
        QueryResponse rsp = server.query(query);
        SolrDocumentList docList = rsp.getResults();
        assertEquals(totalAllRolesAdded, docList.getNumFound());
        for (SolrDocument doc : docList) {
          String id = doc.getFieldValue("id").toString();
          assertEquals(0, Long.valueOf(id) % allRolesFactor);
        }

        // as junit -- should get junit added + onlyAllRolesAdded
        setAuthenticationUser("junit");
        rsp = server.query(query);
        docList = rsp.getResults();
        assertEquals(totalJunitAdded + totalOnlyAllRolesAdded, docList.getNumFound());
        for (SolrDocument doc : docList) {
          String id = doc.getFieldValue("id").toString();
          boolean addedJunit = (Long.valueOf(id) % junitFactor) == 0;
          boolean onlyAllRoles = !addedJunit && (Long.valueOf(id) % allRolesFactor) == 0;
          assertEquals(true, addedJunit || onlyAllRoles);
        }
      } finally {
        server.shutdown();
      }
    } finally {
      deleteCollection(collectionName);
    }
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

   * "expectedQueryDocs" after deletion.
   */
  private void deleteByQueryTest(String collectionName, String deleteUser,
      String deleteByQueryStr, String queryUser, int expectedQueryDocs) throws Exception {
    createDocsAndQuerySimple(collectionName, true);
    CloudSolrServer server = getCloudSolrServer(collectionName);
    try {
      SolrQuery query = new SolrQuery();
      query.setQuery("*:*");

      setAuthenticationUser(deleteUser);
      server.deleteByQuery(deleteByQueryStr);
      server.commit();
      QueryResponse rsp =  server.query(query);
      long junitResults = rsp.getResults().getNumFound();
      assertEquals(0, junitResults);

      setAuthenticationUser(queryUser);
      rsp =  server.query(query);
      long docLevelResults = rsp.getResults().getNumFound();
      assertEquals(expectedQueryDocs, docLevelResults);
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

    }
  }

  private void deleteByIdTest(String collectionName) throws Exception {
    createDocsAndQuerySimple(collectionName, true);
    CloudSolrServer server = getCloudSolrServer(collectionName);
    try {
      SolrQuery query = new SolrQuery();
      query.setQuery("*:*");

      setAuthenticationUser("junit");
      List<String> allIds = new ArrayList<String>(NUM_DOCS);
      for (int i = 0; i < NUM_DOCS; ++i) {
        allIds.add(Long.toString(i));
      }
      server.deleteById(allIds);
      server.commit();

      QueryResponse rsp =  server.query(query);
      long junitResults = rsp.getResults().getNumFound();
      assertEquals(0, junitResults);

      setAuthenticationUser("docLevel");
      rsp =  server.query(query);
      long docLevelResults = rsp.getResults().getNumFound();
      assertEquals(0, docLevelResults);
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

Examples of org.apache.solr.client.solrj.impl.CloudSolrServer

    }
  }

  private void updateDocsTest(String collectionName) throws Exception {
    createDocsAndQuerySimple(collectionName, true);
    CloudSolrServer server = getCloudSolrServer(collectionName);
    try {
      setAuthenticationUser("junit");
      String docIdStr = Long.toString(1);

      // verify we can't view one of the odd documents
      SolrQuery query = new SolrQuery();
      query.setQuery("id:"+docIdStr);
      QueryResponse rsp = server.query(query);
      assertEquals(0, rsp.getResults().getNumFound());

      // overwrite the document that we can't see
      ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
      SolrInputDocument doc = new SolrInputDocument();
      doc.addField("id", docIdStr);
      doc.addField("description", "description" + docIdStr);
      doc.addField(AUTH_FIELD, "junit_role");
      docs.add(doc);
      server.add(docs);
      server.commit();

      // verify we can now view the document
      rsp = server.query(query);
      assertEquals(1, rsp.getResults().getNumFound());
    } finally {
      server.shutdown();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.