org.apache.solr.client.solrj.embedded.JettySolrRunner Java Examples

The following examples show how to use org.apache.solr.client.solrj.embedded.JettySolrRunner. 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: TestImpersonationWithHadoopAuth.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/HADOOP-9893")
public void testForwarding() throws Exception {
  String collectionName = "forwardingCollection";

  // create collection
  CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1",
      1, 1);
  try (SolrClient solrClient = newSolrClient()) {
    create.process(solrClient);
  }

  // try a command to each node, one of them must be forwarded
  for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
    try (HttpSolrClient client =
             new HttpSolrClient.Builder(jetty.getBaseUrl().toString() + "/" + collectionName).build()) {
      ModifiableSolrParams params = new ModifiableSolrParams();
      params.set("q", "*:*");
      params.set(USER_PARAM, "user");
      client.query(params);
    }
  }
}
 
Example #2
Source File: ForceLeaderTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void bringBackOldLeaderAndSendDoc(String collection, Replica leader, List<Replica> notLeaders, int docid) throws Exception {
  // Bring back the leader which was stopped
  log.info("Bringing back originally killed leader...");
  JettySolrRunner leaderJetty = getJettyOnPort(getReplicaPort(leader));
  getProxyForReplica(leader).reopen();
  leaderJetty.start();
  waitForRecoveriesToFinish(collection, cloudClient.getZkStateReader(), true);
  cloudClient.getZkStateReader().forceUpdateCollection(collection);
  ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
  if (log.isInfoEnabled()) {
    log.info("After bringing back leader: {}", clusterState.getCollection(collection).getSlice(SHARD1));
  }
  int numActiveReplicas = getNumberOfActiveReplicas(clusterState, collection, SHARD1);
  assertEquals(1+notLeaders.size(), numActiveReplicas);
  log.info("Sending doc {}...", docid);
  sendDoc(docid);
  log.info("Committing...");
  cloudClient.commit();
  log.info("Doc {} sent and commit issued", docid);
  assertDocsExistInAllReplicas(notLeaders, collection, docid, docid);
  assertDocsExistInAllReplicas(Collections.singletonList(leader), collection, docid, docid);
}
 
Example #3
Source File: TestPullReplicaErrorHandling.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  System.setProperty("solr.zkclienttimeout", "20000");

  configureCluster(4)
      .addConfig("conf", configset("cloud-minimal"))
      .configure();
  // Add proxies
  proxies = new HashMap<>(cluster.getJettySolrRunners().size());
  jettys = new HashMap<>(cluster.getJettySolrRunners().size());
  for (JettySolrRunner jetty:cluster.getJettySolrRunners()) {
    SocketProxy proxy = new SocketProxy();
    jetty.setProxyPort(proxy.getListenPort());
    cluster.stopJettySolrRunner(jetty);//TODO: Can we avoid this restart
    cluster.startJettySolrRunner(jetty);
    cluster.waitForAllNodes(30);
    proxy.open(jetty.getBaseUrl().toURI());
    if (log.isInfoEnabled()) {
      log.info("Adding proxy for URL: {}. Proxy: {}", jetty.getBaseUrl(), proxy.getUrl());
    }
    proxies.put(proxy.getUrl(), proxy);
    jettys.put(proxy.getUrl(), jetty);
  }
}
 
Example #4
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private List<SolrCore> getSolrCore(boolean isLeader) {
  List<SolrCore> rs = new ArrayList<>();

  CloudSolrClient cloudClient = cluster.getSolrClient();
  DocCollection docCollection = cloudClient.getZkStateReader().getClusterState().getCollection(collectionName);

  for (JettySolrRunner solrRunner : cluster.getJettySolrRunners()) {
    if (solrRunner.getCoreContainer() == null) continue;
    for (SolrCore solrCore : solrRunner.getCoreContainer().getCores()) {
      CloudDescriptor cloudDescriptor = solrCore.getCoreDescriptor().getCloudDescriptor();
      Slice slice = docCollection.getSlice(cloudDescriptor.getShardId());
      Replica replica = docCollection.getReplica(cloudDescriptor.getCoreNodeName());
      if (slice.getLeader().equals(replica) && isLeader) {
        rs.add(solrCore);
      } else if (!slice.getLeader().equals(replica) && !isLeader) {
        rs.add(solrCore);
      }
    }
  }
  return rs;
}
 
Example #5
Source File: CollectionsAPIDistributedZkTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateNodeSet() throws Exception {
  JettySolrRunner jetty1 = cluster.getRandomJetty(random());
  JettySolrRunner jetty2 = cluster.getRandomJetty(random());

  List<String> baseUrls = ImmutableList.of(jetty1.getBaseUrl().toString(), jetty2.getBaseUrl().toString());

  CollectionAdminRequest.createCollection("nodeset_collection", "conf", 2, 1)
      .setCreateNodeSet(baseUrls.get(0) + "," + baseUrls.get(1))
      .process(cluster.getSolrClient());

  DocCollection collectionState = getCollectionState("nodeset_collection");
  for (Replica replica : collectionState.getReplicas()) {
    String replicaUrl = replica.getCoreUrl();
    boolean matchingJetty = false;
    for (String jettyUrl : baseUrls) {
      if (replicaUrl.startsWith(jettyUrl)) {
        matchingJetty = true;
      }
    }
    if (matchingJetty == false) {
      fail("Expected replica to be on " + baseUrls + " but was on " + replicaUrl);
    }
  }
}
 
Example #6
Source File: MiniSolrCloudClusterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorsInShutdown() throws Exception {

  AtomicInteger jettyIndex = new AtomicInteger();

  MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {
    @Override
    public JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception {
      JettySolrRunner j = super.stopJettySolrRunner(jetty);
      if (jettyIndex.incrementAndGet() == 2)
        throw new IOException("Fake IOException on shutdown!");
      return j;
    }
  };

  Exception ex = expectThrows(Exception.class, cluster::shutdown);
  assertEquals("Error shutting down MiniSolrCloudCluster", ex.getMessage());
  assertEquals("Expected one suppressed exception", 1, ex.getSuppressed().length);
  assertEquals("Fake IOException on shutdown!", ex.getSuppressed()[0].getMessage());
}
 
Example #7
Source File: ChaosMonkey.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void start(List<JettySolrRunner> jettys) throws Exception {
  ExecutorService executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(
      0,
      Integer.MAX_VALUE,
      15, TimeUnit.SECONDS,
      new SynchronousQueue<>(),
      new SolrNamedThreadFactory("ChaosMonkey"),
      false);
  for (JettySolrRunner jetty : jettys) {
    executor.submit(() -> {
      try {
        jetty.start();
      } catch (Exception e) {
        log.error("error starting jetty", e);
        throw new RuntimeException(e);
      }
    });
  }
  ExecutorUtil.shutdownAndAwaitTermination(executor);
}
 
Example #8
Source File: SolrJettyTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static JettySolrRunner createAndStartJetty(String solrHome, String configFile, String schemaFile, String context,
                                          boolean stopAtShutdown, SortedMap<ServletHolder,String> extraServlets)
    throws Exception {
  // creates the data dir

  context = context==null ? "/solr" : context;
  SolrJettyTestBase.context = context;

  JettyConfig jettyConfig = JettyConfig.builder()
      .setContext(context)
      .stopAtShutdown(stopAtShutdown)
      .withServlets(extraServlets)
      .withSSLConfig(sslConfig.buildServerSSLConfig())
      .build();

  Properties nodeProps = new Properties();
  if (configFile != null)
    nodeProps.setProperty("solrconfig", configFile);
  if (schemaFile != null)
    nodeProps.setProperty("schema", schemaFile);
  if (System.getProperty("solr.data.dir") == null && System.getProperty("solr.hdfs.home") == null) {
    nodeProps.setProperty("solr.data.dir", createTempDir().toFile().getCanonicalPath());
  }

  return createAndStartJetty(solrHome, nodeProps, jettyConfig);
}
 
Example #9
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 #10
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * General purpose cluster sanity check...
 * <ol>
 * <li>Upload a config set</li>
 * <li>verifies a collection can be created</li>
 * <li>verifies many things that should succeed/fail when communicating with the cluster according to the specified sslConfig</li>
 * <li>shutdown a server &amp; startup a new one in it's place</li>
 * <li>repeat the verifications of ssl / no-ssl communication</li>
 * <li>create a second collection</li>
 * </ol>
 * @see #CONF_NAME
 * @see #NUM_SERVERS
 */
public static void checkClusterWithCollectionCreations(final MiniSolrCloudCluster cluster,
                                                       final SSLTestConfig sslConfig) throws Exception {

  cluster.uploadConfigSet(SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf"), CONF_NAME);
  
  checkCreateCollection(cluster, "first_collection");
  
  checkClusterJettys(cluster, sslConfig);
  
  // shut down a server
  JettySolrRunner stoppedServer = cluster.stopJettySolrRunner(0);
  cluster.waitForJettyToStop(stoppedServer);
  assertTrue(stoppedServer.isStopped());
  assertEquals(NUM_SERVERS - 1, cluster.getJettySolrRunners().size());
  
  // create a new server
  JettySolrRunner startedServer = cluster.startJettySolrRunner();
  cluster.waitForAllNodes(30);
  assertTrue(startedServer.isRunning());
  assertEquals(NUM_SERVERS, cluster.getJettySolrRunners().size());
  
  checkClusterJettys(cluster, sslConfig);
  
  checkCreateCollection(cluster, "second_collection");
}
 
Example #11
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void waitForLeaderChange(JettySolrRunner oldLeaderJetty, String shardName) {
  waitForState("Expect new leader", collectionName,
      (liveNodes, collectionState) -> {
        Replica leader = collectionState.getLeader(shardName);
        if (leader == null || !leader.isActive(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes())) {
          return false;
        }
        return oldLeaderJetty == null || !leader.getNodeName().equals(oldLeaderJetty.getNodeName());
      }
  );
}
 
Example #12
Source File: TestContentStreamDataSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private JettySolrRunner createAndStartJetty(SolrInstance instance) throws Exception {
  Properties nodeProperties = new Properties();
  nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
  JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), nodeProperties, buildJettyConfig("/solr"));
  jetty.start();
  return jetty;
}
 
Example #13
Source File: OverseerRolesTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDesignatedOverseerRestarts() throws Exception {
  logOverseerState();
  // Remove the OVERSEER role, in case it was already assigned by another test in this suite
  for (String node: OverseerCollectionConfigSetProcessor.getSortedOverseerNodeNames(zkClient())) {
    CollectionAdminRequest.removeRole(node, "overseer").process(cluster.getSolrClient());
  }
  String overseer1 = OverseerCollectionConfigSetProcessor.getLeaderNode(zkClient());
  int counter = 0;
  while (overseer1 == null && counter < 10) {
    overseer1 = OverseerCollectionConfigSetProcessor.getLeaderNode(zkClient());
    Thread.sleep(1000);
  }

  // Setting overseer role to the current overseer
  CollectionAdminRequest.addRole(overseer1, "overseer").process(cluster.getSolrClient());
  waitForNewOverseer(15, overseer1, false);
  JettySolrRunner leaderJetty = getOverseerJetty();

  List<String> nodes = OverseerCollectionConfigSetProcessor.getSortedOverseerNodeNames(zkClient());
  nodes.remove(overseer1); // remove the designated overseer

  logOverseerState();
  // kill the current overseer, and check that the next node in the election queue assumes leadership
  leaderJetty.stop();
  log.info("Killing designated overseer: {}", overseer1);

  // after 5 seconds, bring back dead designated overseer and assert that it assumes leadership "right away",
  // i.e. without any other node assuming leadership before this node becomes leader.
  Thread.sleep(5);
  logOverseerState();
  log.info("Starting back the prioritized overseer..");
  leaderJetty.start();
  waitForNewOverseer(15, overseer1, true); // assert that there is just a single leadership transition
}
 
Example #14
Source File: TestSimClusterStateProvider.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private String addNode() throws Exception {
  JettySolrRunner solr = cluster.startJettySolrRunner();
  cluster.waitForAllNodes(30);
  String nodeId = solr.getNodeName();
  if (simulated) {
    ((SimCloudManager) cloudManager).getSimClusterStateProvider().simAddNode(nodeId);
  }
  return nodeId;
}
 
Example #15
Source File: UnloadDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected SolrCore getFirstCore(String collection, JettySolrRunner jetty) {
  SolrCore solrCore = null;
  for (SolrCore core : jetty.getCoreContainer().getCores()) {
    if (core.getName().startsWith(collection)) {
      solrCore = core;
    }
  }
  return solrCore;
}
 
Example #16
Source File: TestReplicationHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static JettySolrRunner createAndStartJetty(SolrInstance instance) throws Exception {
  FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(instance.getHomeDir(), "solr.xml"));
  Properties nodeProperties = new Properties();
  nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
  JettyConfig jettyConfig = JettyConfig.builder().setContext("/solr").setPort(0).build();
  JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), nodeProperties, jettyConfig);
  jetty.start();
  return jetty;
}
 
Example #17
Source File: SolrITInitializer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a JettySolrRunner (if one didn't exist already). DOES NOT START IT.
 */
protected static JettySolrRunner createJetty(String jettyKey, boolean basicAuth) throws Exception
{
    if (jettyContainers.containsKey(jettyKey))
    {
        return jettyContainers.get(jettyKey);
    }
    else
    {
        Path jettySolrHome = testDir.toPath().resolve(jettyKey);
        seedSolrHome(jettySolrHome);
        return createJetty(jettySolrHome.toFile(), null, null, false, 0, getSchemaFile(), basicAuth);
    }
}
 
Example #18
Source File: SolrJettyTestBase.java    From extract with MIT License 5 votes vote down vote up
@BeforeClass
public static void beforeSolrJettyTestBase() throws Exception {
	final File origSolrHome = new File(SolrJettyTestBase.class.getResource("/solr").toURI());
	final File tempSolrHome = tempSolrFolder.getRoot();
	final File tempSolrData = tempSolrFolder.newFolder("data");

	FileUtils.copyDirectory(origSolrHome, tempSolrHome);

	final JettyConfig jettyConfig = JettyConfig.builder()
		.setContext("/solr")
		.setPort(8888)
		.stopAtShutdown(true)
		.build();

	final Properties nodeProperties = new Properties();

	nodeProperties.setProperty("solr.data.dir", tempSolrData.getCanonicalPath());
	nodeProperties.setProperty("coreRootDirectory", tempSolrHome.toString());
	nodeProperties.setProperty("configSetBaseDir", tempSolrHome.toString());

	System.setProperty("jetty.testMode", "true");

	jetty = new JettySolrRunner(tempSolrHome.toString(), nodeProperties, jettyConfig);
	jetty.start();

	client = createNewSolrClient();
}
 
Example #19
Source File: TestRestoreCore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static JettySolrRunner createAndStartJetty(TestReplicationHandler.SolrInstance instance) throws Exception {
  FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(instance.getHomeDir(), "solr.xml"));
  Properties nodeProperties = new Properties();
  nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
  JettyConfig jettyConfig = JettyConfig.builder().setContext("/solr").setPort(0).build();
  JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), nodeProperties, jettyConfig);
  jetty.start();
  return jetty;
}
 
Example #20
Source File: TestContainerPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void waitForAllNodesToSync(MiniSolrCloudCluster cluster, String path, Map<String,Object> expected) throws Exception {
  for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
    String baseUrl = jettySolrRunner.getBaseUrl().toString().replace("/solr", "/api");
    String url = baseUrl + path + "?wt=javabin";
    TestDistribPackageStore.assertResponseValues(10, new Fetcher(url, jettySolrRunner), expected);
  }
}
 
Example #21
Source File: TestUtilizeNode.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of replicas for the specified collection hosted on the specified node
 * and then asserts that it there is at least one
 */
private void assertSomeReplicas(String prefix, String collectionName, JettySolrRunner jettyNode) throws IOException {
                              
  final List<Replica> replicas = getReplicaList(collectionName, jettyNode);
  assertTrue(prefix + " " + jettyNode.getNodeName() + " => " + replicas,
             0 < replicas.size());
}
 
Example #22
Source File: BaseCdcrDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Restart a server.
 */
protected void restartServer(CloudJettyRunner server) throws Exception {
  // it seems we need to set the collection property to have the jetty properly restarted
  System.setProperty("collection", server.collection);
  JettySolrRunner jetty = server.jetty;
  jetty.stop();
  jetty.start();
  System.clearProperty("collection");
  waitForRecoveriesToFinish(server.collection, true);
  updateMappingsFromZk(server.collection); // must update the mapping as the core node name might have changed
}
 
Example #23
Source File: MiniSolrCloudClusterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testErrorsInStartup() throws Exception {

  AtomicInteger jettyIndex = new AtomicInteger();

  MiniSolrCloudCluster cluster = null;
  try {
    cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {
      @Override
      public JettySolrRunner startJettySolrRunner(String name, String context, JettyConfig config) throws Exception {
        if (jettyIndex.incrementAndGet() != 2)
          return super.startJettySolrRunner(name, context, config);
        throw new IOException("Fake exception on startup!");
      }
    };
    fail("Expected an exception to be thrown from MiniSolrCloudCluster");
  }
  catch (Exception e) {
    assertEquals("Error starting up MiniSolrCloudCluster", e.getMessage());
    assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);
    assertEquals("Fake exception on startup!", e.getSuppressed()[0].getMessage());
  }
  finally {
    if (cluster != null)
      cluster.shutdown();
  }
}
 
Example #24
Source File: LeaderTragicEventTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testOtherReplicasAreNotActive() throws Exception {
  final String collection = "collection2";
  cluster.getSolrClient().setDefaultCollection(collection);
  int numReplicas = random().nextInt(2) + 1;
  // won't do anything if leader is the only one active replica in the shard
  CollectionAdminRequest
      .createCollection(collection, "config", 1, numReplicas)
      .process(cluster.getSolrClient());
  cluster.waitForActiveCollection(collection, 1, numReplicas);

  try {
    JettySolrRunner otherReplicaJetty = null;
    if (numReplicas == 2) {
      Slice shard = getCollectionState(collection).getSlice("shard1");
      otherReplicaJetty = cluster.getReplicaJetty(getNonLeader(shard));
      if (log.isInfoEnabled()) {
        log.info("Stop jetty node : {} state:{}", otherReplicaJetty.getBaseUrl(), getCollectionState(collection));
      }
      otherReplicaJetty.stop();
      cluster.waitForJettyToStop(otherReplicaJetty);
      waitForState("Timeout waiting for replica get down", collection, (liveNodes, collectionState) -> getNonLeader(collectionState.getSlice("shard1")).getState() != Replica.State.ACTIVE);
    }

    Replica oldLeader = corruptLeader(collection, new ArrayList<>());

    if (otherReplicaJetty != null) {
      otherReplicaJetty.start();
      cluster.waitForNode(otherReplicaJetty, 30);
    }

    Replica leader = getCollectionState(collection).getSlice("shard1").getLeader();
    assertEquals(leader.getName(), oldLeader.getName());
  } finally {
    CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
  }
}
 
Example #25
Source File: CollectionsAPIDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void checkInstanceDirs(JettySolrRunner jetty) throws IOException {
  CoreContainer cores = jetty.getCoreContainer();
  Collection<SolrCore> theCores = cores.getCores();
  for (SolrCore core : theCores) {
    // look for core props file
    Path instancedir = core.getInstancePath();
    assertTrue("Could not find expected core.properties file", Files.exists(instancedir.resolve("core.properties")));

    Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve(core.getName());

    assertTrue("Expected: " + expected + "\nFrom core stats: " + instancedir, Files.isSameFile(expected, instancedir));
  }
}
 
Example #26
Source File: HealthCheckHandlerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testHealthCheckV2Api() throws Exception {
  V2Response res = new V2Request.Builder("/node/health").build().process(cluster.getSolrClient());
  assertEquals(0, res.getStatus());
  assertEquals(CommonParams.OK, res.getResponse().get(CommonParams.STATUS));

  // add a new node for the purpose of negative testing
  JettySolrRunner newJetty = cluster.startJettySolrRunner();
  try (HttpSolrClient httpSolrClient = getHttpSolrClient(newJetty.getBaseUrl().toString())) {

    // postive check that our (new) "healthy" node works with direct http client
    assertEquals(CommonParams.OK, new V2Request.Builder("/node/health").build().process(httpSolrClient).
        getResponse().get(CommonParams.STATUS));

    // now "break" our (new) node
    newJetty.getCoreContainer().getZkController().getZkClient().close();

    // negative check of our (new) "broken" node that we deliberately put into an unhealth state
    BaseHttpSolrClient.RemoteSolrException e = expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () ->
    {
      new V2Request.Builder("/node/health").build().process(httpSolrClient);
    });
    assertTrue(e.getMessage(), e.getMessage().contains("Host Unavailable"));
    assertEquals(SolrException.ErrorCode.SERVICE_UNAVAILABLE.code, e.code());
  } finally {
    newJetty.stop();
  }
}
 
Example #27
Source File: ChaosMonkey.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void causeConnectionLoss(JettySolrRunner jetty) {
  CoreContainer cores = jetty.getCoreContainer();
  if (cores != null) {
    monkeyLog("Will cause connection loss on " + jetty.getLocalPort());
    SolrZkClient zkClient = cores.getZkController().getZkClient();
    zkClient.getSolrZooKeeper().closeCnxn();
  }
}
 
Example #28
Source File: HttpPartitionTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Overrides the parent implementation to install a SocketProxy in-front of the Jetty server.
 */
@Override
public JettySolrRunner createJetty(File solrHome, String dataDir,
    String shardList, String solrConfigOverride, String schemaOverride, Replica.Type replicaType)
    throws Exception
{
  return createProxiedJetty(solrHome, dataDir, shardList, solrConfigOverride, schemaOverride, replicaType);
}
 
Example #29
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 #30
Source File: TestReplicationHandlerBackup.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static JettySolrRunner createAndStartJetty(TestReplicationHandler.SolrInstance instance) throws Exception {
  FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(instance.getHomeDir(), "solr.xml"));
  Properties nodeProperties = new Properties();
  nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
  JettyConfig jettyConfig = JettyConfig.builder().setContext("/solr").setPort(0).build();
  JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), nodeProperties, jettyConfig);
  jetty.start();
  return jetty;
}