Java Code Examples for org.apache.solr.client.solrj.embedded.JettySolrRunner#newClient()

The following examples show how to use org.apache.solr.client.solrj.embedded.JettySolrRunner#newClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDistribPackageStore.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public static void waitForAllNodesHaveFile(MiniSolrCloudCluster cluster, String path, Map expected , boolean verifyContent) throws Exception {
  for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
    String baseUrl = jettySolrRunner.getBaseUrl().toString().replace("/solr", "/api");
    String url = baseUrl + "/node/files" + path + "?wt=javabin&meta=true";
    assertResponseValues(10, new Fetcher(url, jettySolrRunner), expected);

    if(verifyContent) {
      try (HttpSolrClient solrClient = (HttpSolrClient) jettySolrRunner.newClient()) {
        ByteBuffer buf = Utils.executeGET(solrClient.getHttpClient(), baseUrl + "/node/files" + path,
            Utils.newBytesConsumer(Integer.MAX_VALUE));
        assertEquals(
            "d01b51de67ae1680a84a813983b1de3b592fc32f1a22b662fc9057da5953abd1b72476388ba342cad21671cd0b805503c78ab9075ff2f3951fdf75fa16981420",
            DigestUtils.sha512Hex(new ByteBufferInputStream(buf))
        );

      }
    }

  }
}
 
Example 2
Source File: TestPackages.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
private void executeReq(String uri, JettySolrRunner jetty,
                        @SuppressWarnings({"rawtypes"})Utils.InputStreamConsumer parser,
                        @SuppressWarnings({"rawtypes"})Map expected) throws Exception {
  try(HttpSolrClient client = (HttpSolrClient) jetty.newClient()){
    TestDistribPackageStore.assertResponseValues(10,
        () -> {
          Object o = Utils.executeGET(client.getHttpClient(),
              jetty.getBaseUrl() + uri, parser);
          if(o instanceof NavigableObject) return (NavigableObject) o;
          if(o instanceof Map) return new MapWriterMap((Map) o);
          throw new RuntimeException("Unknown response");
        }, expected);

  }
}
 
Example 3
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testOutOfOrderDBQWithInPlaceUpdates() throws Exception {
  createAndWaitForCollection(1,0,2,0);
  assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").indexed());
  assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").stored());
  assertTrue(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").hasDocValues());
  List<UpdateRequest> updates = new ArrayList<>();
  updates.add(simulatedUpdateRequest(null, "id", 1, "title_s", "title0_new", "inplace_updatable_int", 5, "_version_", 1L)); // full update
  updates.add(simulatedDBQ("inplace_updatable_int:5", 3L));
  updates.add(simulatedUpdateRequest(1L, "id", 1, "inplace_updatable_int", 6, "_version_", 2L));
  for (JettySolrRunner solrRunner: getSolrRunner(false)) {
    try (SolrClient client = solrRunner.newClient()) {
      for (UpdateRequest up : updates) {
        up.process(client, collectionName);
      }
    }
  }
  JettySolrRunner oldLeaderJetty = getSolrRunner(true).get(0);
  oldLeaderJetty.stop();
  waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
  waitForLeaderChange(oldLeaderJetty, "shard1");
  oldLeaderJetty.start();
  waitForState("Replica not added", collectionName, activeReplicaCount(0, 2, 0));
  checkRTG(1,1, cluster.getJettySolrRunners());
  SolrDocument doc = cluster.getSolrClient().getById(collectionName,"1");
  assertNotNull(doc.get("title_s"));
}
 
Example 4
Source File: TestDistribPackageStore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void uploadKey(byte[] bytes, String path, MiniSolrCloudCluster cluster) throws Exception {
  JettySolrRunner jetty = cluster.getRandomJetty(random());
  try(HttpSolrClient client = (HttpSolrClient) jetty.newClient()) {
    PackageUtils.uploadKey(bytes, path, Paths.get(jetty.getCoreContainer().getSolrHome()), client);
    Object resp = Utils.executeGET(client.getHttpClient(), jetty.getBaseURLV2().toString() + "/node/files" + path + "?sync=true", null);
    System.out.println("sync resp: "+jetty.getBaseURLV2().toString() + "/node/files" + path + "?sync=true"+" ,is: "+resp);
  }
  waitForAllNodesHaveFile(cluster,path, Utils.makeMap(":files:" + path + ":name", (Predicate<Object>) Objects::nonNull),
      false);
}
 
Example 5
Source File: BasicDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void testStopAndStartCoresInOneInstance() throws Exception {
  JettySolrRunner jetty = jettys.get(0);
  try (final HttpSolrClient httpSolrClient = (HttpSolrClient) jetty.newClient(15000, 60000)) {
    ThreadPoolExecutor executor = null;
    try {
      executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE,
          5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
          new SolrNamedThreadFactory("testExecutor"));
      int cnt = 3;

      // create the cores
      createCollectionInOneInstance(httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt);
    } finally {
      if (executor != null) {
        ExecutorUtil.shutdownAndAwaitTermination(executor);
      }
    }
  }
  
  cloudJettys.get(0).jetty.stop();
  printLayout();

  cloudJettys.get(0).jetty.start();
  cloudClient.getZkStateReader().forceUpdateCollection("multiunload2");
  try {
    cloudClient.getZkStateReader().getLeaderRetry("multiunload2", "shard1", 30000);
  } catch (SolrException e) {
    printLayout();
    throw e;
  }
  
  printLayout();

}
 
Example 6
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void checkRTG(int from, int to, List<JettySolrRunner> solrRunners) throws Exception{
  for (JettySolrRunner solrRunner: solrRunners) {
    try (SolrClient client = solrRunner.newClient()) {
      for (int i = from; i <= to; i++) {
        SolrQuery query = new SolrQuery();
        query.set("distrib", false);
        query.setRequestHandler("/get");
        query.set("id",i);
        QueryResponse res = client.query(collectionName, query);
        assertNotNull("Can not find doc "+ i + " in " + solrRunner.getBaseUrl(),res.getResponse().get("doc"));
      }
    }
  }
}
 
Example 7
Source File: RemoteQueryErrorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

  CollectionAdminRequest.createCollection("collection", "conf", 2, 1).process(cluster.getSolrClient());

  for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
    try (SolrClient client = jetty.newClient()) {
      SolrException e = expectThrows(SolrException.class, () -> {
        client.add("collection", new SolrInputDocument());
      });
      assertThat(e.getMessage(), containsString("Document is missing mandatory uniqueKey field: id"));
    }
  }

}
 
Example 8
Source File: UnloadDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void testUnloadLotsOfCores() throws Exception {
  JettySolrRunner jetty = jettys.get(0);
  try (final HttpSolrClient adminClient = (HttpSolrClient) jetty.newClient(15000, 60000)) {
    int numReplicas = atLeast(3);
    ThreadPoolExecutor executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE,
        5, TimeUnit.SECONDS, new SynchronousQueue<>(),
        new SolrNamedThreadFactory("testExecutor"));
    try {
      // create the cores
      createCollectionInOneInstance(adminClient, jetty.getNodeName(), executor, "multiunload", 2, numReplicas);
    } finally {
      ExecutorUtil.shutdownAndAwaitTermination(executor);
    }

    executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
        TimeUnit.SECONDS, new SynchronousQueue<>(),
        new SolrNamedThreadFactory("testExecutor"));
    try {
      for (int j = 0; j < numReplicas; j++) {
        final int freezeJ = j;
        executor.execute(() -> {
          Unload unloadCmd = new Unload(true);
          unloadCmd.setCoreName("multiunload" + freezeJ);
          try {
            adminClient.request(unloadCmd);
          } catch (SolrServerException | IOException e) {
            throw new RuntimeException(e);
          }
        });
        Thread.sleep(random().nextInt(50));
      }
    } finally {
      ExecutorUtil.shutdownAndAwaitTermination(executor);
    }
  }
}