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

The following examples show how to use org.apache.solr.client.solrj.embedded.JettySolrRunner#getBaseUrl() . 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: 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 2
Source File: TestStressCloudBlindAtomicUpdates.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
@SuppressWarnings({"unchecked"})
private static void createMiniSolrCloudCluster() throws Exception {
  // NOTE: numDocsToCheck uses atLeast, so nightly & multiplier are alreayd a factor in index size
  // no need to redundently factor them in here as well
  DOC_ID_INCR = TestUtil.nextInt(random(), 1, 7);
  
  NUM_THREADS = atLeast(3);
  EXEC_SERVICE = ExecutorUtil.newMDCAwareFixedThreadPool
    (NUM_THREADS, new SolrNamedThreadFactory(DEBUG_LABEL));
  
  // at least 2, but don't go crazy on nightly/test.multiplier with "atLeast()"
  final int numShards = TEST_NIGHTLY ? 5 : 2; 
  final int repFactor = 2; 
  final int numNodes = numShards * repFactor;
 
  final String configName = DEBUG_LABEL + "_config-set";
  final Path configDir = Paths.get(TEST_HOME(), "collection1", "conf");
  
  configureCluster(numNodes).addConfig(configName, configDir).configure();

  CLOUD_CLIENT = cluster.getSolrClient();
  CLOUD_CLIENT.setDefaultCollection(COLLECTION_NAME);

  CollectionAdminRequest.createCollection(COLLECTION_NAME, configName, numShards, repFactor)
      .withProperty("config", "solrconfig-tlog.xml")
      .withProperty("schema", "schema-minimal-atomic-stress.xml")
      .process(CLOUD_CLIENT);

  waitForRecoveriesToFinish(CLOUD_CLIENT);

  CLIENTS.clear();
  for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
    assertNotNull("Cluster contains null jetty?", jetty);
    final URL baseUrl = jetty.getBaseUrl();
    assertNotNull("Jetty has null baseUrl: " + jetty.toString(), baseUrl);
    CLIENTS.add(getHttpSolrClient(baseUrl + "/" + COLLECTION_NAME + "/"));
  }

  // sanity check no one broke the assumptions we make about our schema
  checkExpectedSchemaType( map("name","long",
                               "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Long.class),
                               "multiValued",Boolean.FALSE,
                               "indexed",Boolean.FALSE,
                               "stored",Boolean.FALSE,
                               "docValues",Boolean.FALSE) );
}
 
Example 3
Source File: TestTolerantUpdateProcessorRandomCloud.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void createMiniSolrCloudCluster() throws Exception {
  
  final String configName = "solrCloudCollectionConfig";
  final File configDir = new File(TEST_HOME() + File.separator + "collection1" + File.separator + "conf");

  final int numShards = TestUtil.nextInt(random(), 2, TEST_NIGHTLY ? 5 : 3);
  final int repFactor = TestUtil.nextInt(random(), 2, TEST_NIGHTLY ? 5 : 3);
  // at least one server won't have any replicas
  final int numServers = 1 + (numShards * repFactor);

  log.info("Configuring cluster: servers={}, shards={}, repfactor={}", numServers, numShards, repFactor);
  configureCluster(numServers)
    .addConfig(configName, configDir.toPath())
    .configure();
  
  Map<String, String> collectionProperties = new HashMap<>();
  collectionProperties.put("config", "solrconfig-distrib-update-processor-chains.xml");
  collectionProperties.put("schema", "schema15.xml"); // string id 

  CLOUD_CLIENT = cluster.getSolrClient();
  CLOUD_CLIENT.setDefaultCollection(COLLECTION_NAME);

  CollectionAdminRequest.createCollection(COLLECTION_NAME, configName, numShards, repFactor)
      .setProperties(collectionProperties)
      .process(CLOUD_CLIENT);

  cluster.waitForActiveCollection(COLLECTION_NAME, numShards, numShards * repFactor);
  
  if (NODE_CLIENTS != null) {
    for (HttpSolrClient client : NODE_CLIENTS) {
      client.close();
    }
  }
  NODE_CLIENTS = new ArrayList<HttpSolrClient>(numServers);
  
  for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
    URL jettyURL = jetty.getBaseUrl();
    NODE_CLIENTS.add(getHttpSolrClient(jettyURL.toString() + "/" + COLLECTION_NAME + "/"));
  }
  assertEquals(numServers, NODE_CLIENTS.size());
  
}