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

The following examples show how to use org.apache.solr.client.solrj.embedded.JettySolrRunner#isRunning() . 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: TestPullReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void tearDown() throws Exception {
  for (JettySolrRunner jetty:cluster.getJettySolrRunners()) {
    if (!jetty.isRunning()) {
      log.warn("Jetty {} not running, probably some bad test. Starting it", jetty.getLocalPort());
      jetty.start();
    }
  }
  if (cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName) != null) {
    log.info("tearDown deleting collection");
    CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
    log.info("Collection deleted");
    waitForDeletion(collectionName);
  }
  super.tearDown();
}
 
Example 2
Source File: AutoAddReplicasIntegrationTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** 
 * {@link MiniSolrCloudCluster#waitForNode} Doesn't check isRunning first, and we don't want to 
 * use {@link MiniSolrCloudCluster#waitForAllNodes} because we don't want to waste cycles checking 
 * nodes we aren't messing with  
 */
private void waitForNodeLive(final JettySolrRunner jetty)
  throws InterruptedException, TimeoutException, IOException {
  if (log.isInfoEnabled()) {
    log.info("waitForNodeLive: {}/{}", jetty.getNodeName(), jetty.getLocalPort());
  }
  
  TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
  while(!timeout.hasTimedOut()) {
    if (jetty.isRunning()) {
      break;
    }
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      // ignore
    }
  }
  if (timeout.hasTimedOut()) {
    throw new TimeoutException("Waiting for Jetty to stop timed out");
  }
  cluster.waitForNode(jetty, 30);
}
 
Example 3
Source File: SolrITInitializer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Starts jetty if its not already running
 */
protected static void start(JettySolrRunner jsr) throws Exception
{
    if (!jsr.isRunning())
    {
        jsr.start();
    }
}
 
Example 4
Source File: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void waitForAllWarmingSearchers() throws InterruptedException {
  log.info("waitForAllWarmingSearchers");
  for (JettySolrRunner jetty:jettys) {
    if (!jetty.isRunning()) {
      continue;
    }
    for (SolrCore core:jetty.getCoreContainer().getCores()) {
      waitForWarming(core);
    }
  }
}
 
Example 5
Source File: JettySolrRunnerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestartPorts() throws Exception {

  Path solrHome = createTempDir();
  Files.write(solrHome.resolve("solr.xml"), MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML.getBytes(Charset.defaultCharset()));

  JettyConfig config = JettyConfig.builder().build();

  JettySolrRunner jetty = new JettySolrRunner(solrHome.toString(), config);
  try {
    jetty.start();

    URL url = jetty.getBaseUrl();
    int usedPort = url.getPort();

    jetty.stop();
    jetty.start();

    assertEquals("After restart, jetty port should be the same", usedPort, jetty.getBaseUrl().getPort());

    jetty.stop();
    jetty.start(false);

    assertThat("After restart, jetty port should be different", jetty.getBaseUrl().getPort(), not(usedPort));
  }
  finally {
    if (jetty.isRunning())
      jetty.stop();
  }

}
 
Example 6
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
  for (JettySolrRunner jetty:cluster.getJettySolrRunners()) {
    if (!jetty.isRunning()) {
      log.warn("Jetty {} not running, probably some bad test. Starting it", jetty.getLocalPort());
      jetty.start();
    }
  }
  if (cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName) != null) {
    log.info("tearDown deleting collection");
    CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
    waitForDeletion(collectionName);
  }
  super.tearDown();
}
 
Example 7
Source File: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected void waitForReplicationFromReplicas(String collectionName, ZkStateReader zkStateReader, TimeOut timeout) throws KeeperException, InterruptedException, IOException {
  log.info("waitForReplicationFromReplicas: {}", collectionName);
  zkStateReader.forceUpdateCollection(collectionName);
  DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
  Map<String, CoreContainer> containers = new HashMap<>();
  for (JettySolrRunner runner:jettys) {
    if (!runner.isRunning()) {
      continue;
    }
    containers.put(runner.getNodeName(), runner.getCoreContainer());
  }
  for(Slice s:collection.getSlices()) {
    Replica leader = zkStateReader.getLeaderRetry(collectionName, s.getName(), (int)timeout.timeLeft(TimeUnit.MILLISECONDS));
    long leaderIndexVersion = -1;
    while (!timeout.hasTimedOut()) {
      leaderIndexVersion = getIndexVersion(leader);
      if (leaderIndexVersion >= 0) {
        break;
      }
      Thread.sleep(1000);
    }
    if (timeout.hasTimedOut()) {
      fail("Unable to get leader indexVersion");
    }
    for (Replica pullReplica:s.getReplicas(EnumSet.of(Replica.Type.PULL,Replica.Type.TLOG))) {
      if (!zkStateReader.getClusterState().liveNodesContain(pullReplica.getNodeName())) {
        continue;
      }
      while (true) {
        long replicaIndexVersion = getIndexVersion(pullReplica); 
        if (leaderIndexVersion == replicaIndexVersion) {
          if (log.isInfoEnabled()) {
            log.info("Leader replica's version ({}) in sync with replica({}): {} == {}"
                , leader.getName(), pullReplica.getName(), leaderIndexVersion, replicaIndexVersion);
          }
          
          // Make sure the host is serving the correct version
          try (SolrCore core = containers.get(pullReplica.getNodeName()).getCore(pullReplica.getCoreName())) {
            RefCounted<SolrIndexSearcher> ref = core.getRegisteredSearcher();
            try {
              SolrIndexSearcher searcher = ref.get();
              String servingVersion = searcher.getIndexReader().getIndexCommit().getUserData().get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
              if (Long.parseLong(servingVersion) == replicaIndexVersion) {
                break;
              } else {
                if (log.isInfoEnabled()) {
                  log.info("Replica {} has the correct version replicated, but the searcher is not ready yet. Replicated version: {}, Serving version: {}"
                      , pullReplica.getName(), replicaIndexVersion, servingVersion);
                }
              }
            } finally {
              if (ref != null) ref.decref();
            }
          }
        } else {
          if (timeout.hasTimedOut()) {
            logReplicaTypesReplicationInfo(collectionName, zkStateReader);
            fail(String.format(Locale.ROOT, "Timed out waiting for replica %s (%d) to replicate from leader %s (%d)", pullReplica.getName(), replicaIndexVersion, leader.getName(), leaderIndexVersion));
          }
          if (leaderIndexVersion > replicaIndexVersion) {
            if (log.isInfoEnabled()) {
              log.info("{} version is {} and leader's is {}, will wait for replication"
                  , pullReplica.getName(), replicaIndexVersion, leaderIndexVersion);
            }
          } else {
            if (log.isInfoEnabled()) {
              log.info("Leader replica's version ({}) is lower than pull replica({}): {} < {}"
                  , leader.getName(), pullReplica.getName(), leaderIndexVersion, replicaIndexVersion);
            }
          }
        }
        Thread.sleep(1000);
      }
    }
  }
}