use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.
the class TestTolerantUpdateProcessorRandomCloud method createMiniSolrCloudCluster.
@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();
TestTolerantUpdateProcessorCloud.assertSpinLoopAllJettyAreRunning(cluster);
Map<String, String> collectionProperties = new HashMap<>();
collectionProperties.put("config", "solrconfig-distrib-update-processor-chains.xml");
// string id
collectionProperties.put("schema", "schema15.xml");
CLOUD_CLIENT = cluster.getSolrClient();
CLOUD_CLIENT.setDefaultCollection(COLLECTION_NAME);
CollectionAdminRequest.createCollection(COLLECTION_NAME, configName, numShards, repFactor).setProperties(collectionProperties).process(CLOUD_CLIENT);
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());
ZkStateReader zkStateReader = CLOUD_CLIENT.getZkStateReader();
AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTION_NAME, zkStateReader, true, true, 330);
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.
the class TestTlogReplica method testRecovery.
@SuppressWarnings("unchecked")
public void testRecovery() throws Exception {
boolean useKill = random().nextBoolean();
createAndWaitForCollection(1, 0, 2, 0);
CloudSolrClient cloudClient = cluster.getSolrClient();
new UpdateRequest().add(sdoc("id", "3")).add(sdoc("id", "4")).commit(cloudClient, collectionName);
new UpdateRequest().add(sdoc("id", "5")).process(cloudClient, collectionName);
JettySolrRunner solrRunner = getSolrRunner(false).get(0);
if (useKill) {
ChaosMonkey.kill(solrRunner);
} else {
ChaosMonkey.stop(solrRunner);
}
waitForState("Replica still up", collectionName, activeReplicaCount(0, 1, 0));
new UpdateRequest().add(sdoc("id", "6")).process(cloudClient, collectionName);
ChaosMonkey.start(solrRunner);
waitForState("Replica didn't recover", collectionName, activeReplicaCount(0, 2, 0));
// We skip peerSync, so replica will always trigger commit on leader
// We query only the non-leader replicas, since we haven't opened a new searcher on the leader yet
// Should be immediate
waitForNumDocsInAllReplicas(4, getNonLeaderReplias(collectionName), 0);
// Options are, wait or retry...
for (int i = 0; i < 3; i++) {
UpdateRequest ureq = new UpdateRequest().add(sdoc("id", "7"));
ureq.setParam("collection", collectionName);
ureq.setParam(UpdateRequest.MIN_REPFACT, "2");
NamedList<Object> response = cloudClient.request(ureq);
if ((Integer) ((NamedList<Object>) response.get("responseHeader")).get(UpdateRequest.REPFACT) >= 2) {
break;
}
LOG.info("Min RF not achieved yet. retrying");
}
checkRTG(3, 7, cluster.getJettySolrRunners());
DirectUpdateHandler2.commitOnClose = false;
ChaosMonkey.stop(solrRunner);
waitForState("Replica still up", collectionName, activeReplicaCount(0, 1, 0));
DirectUpdateHandler2.commitOnClose = true;
ChaosMonkey.start(solrRunner);
waitForState("Replica didn't recover", collectionName, activeReplicaCount(0, 2, 0));
checkRTG(3, 7, cluster.getJettySolrRunners());
// Should be immediate
waitForNumDocsInAllReplicas(5, getNonLeaderReplias(collectionName), 0);
cluster.getSolrClient().commit(collectionName);
// Test replica recovery apply buffer updates
Semaphore waitingForBufferUpdates = new Semaphore(0);
Semaphore waitingForReplay = new Semaphore(0);
RecoveryStrategy.testing_beforeReplayBufferingUpdates = () -> {
try {
waitingForReplay.release();
waitingForBufferUpdates.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
fail("Test interrupted: " + e.getMessage());
}
};
if (useKill) {
ChaosMonkey.kill(solrRunner);
} else {
ChaosMonkey.stop(solrRunner);
}
ChaosMonkey.start(solrRunner);
waitingForReplay.acquire();
new UpdateRequest().add(sdoc("id", "8")).add(sdoc("id", "9")).process(cloudClient, collectionName);
waitingForBufferUpdates.release();
RecoveryStrategy.testing_beforeReplayBufferingUpdates = null;
waitForState("Replica didn't recover", collectionName, activeReplicaCount(0, 2, 0));
checkRTG(3, 9, cluster.getJettySolrRunners());
for (SolrCore solrCore : getSolrCore(false)) {
RefCounted<IndexWriter> iwRef = solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null);
assertFalse("IndexWriter at replicas must not see updates ", iwRef.get().hasUncommittedChanges());
iwRef.decref();
}
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.
the class TestTlogReplica method tearDown.
@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());
ChaosMonkey.start(jetty);
}
}
if (cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName) != null) {
LOG.info("tearDown deleting collection");
CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
waitForDeletion(collectionName);
}
super.tearDown();
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.
the class MiniSolrCloudClusterTest method testErrorsInStartup.
@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();
}
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.
the class JettySolrRunnerTest method testRestartPorts.
@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();
}
}
Aggregations