use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.
the class TestConfigSetsAPIZkFailure method testCreateZkFailure.
@Test
public void testCreateZkFailure() throws Exception {
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final Map<String, String> oldProps = ImmutableMap.of("immutable", "true");
setupBaseConfigSet(BASE_CONFIGSET_NAME, oldProps);
SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
try {
ZkConfigManager configManager = new ZkConfigManager(zkClient);
assertFalse(configManager.configExists(CONFIGSET_NAME));
Create create = new Create();
create.setBaseConfigSetName(BASE_CONFIGSET_NAME).setConfigSetName(CONFIGSET_NAME);
try {
ConfigSetAdminResponse response = create.process(solrClient);
Assert.fail("Expected solr exception");
} catch (RemoteSolrException se) {
// partial creation should have been cleaned up
assertFalse(configManager.configExists(CONFIGSET_NAME));
assertEquals(SolrException.ErrorCode.SERVER_ERROR.code, se.code());
}
} finally {
zkClient.close();
}
solrClient.close();
}
use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.
the class TestConfigSetsAPI method testUploadErrors.
@Test
public void testUploadErrors() throws Exception {
final SolrClient solrClient = getHttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
ByteBuffer emptyData = ByteBuffer.allocate(0);
// Checking error when no configuration name is specified in request
Map map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD&wt=json", emptyData, null, null);
assertNotNull(map);
long statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status"));
assertEquals(400l, statusCode);
SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null);
// Create dummy config files in zookeeper
zkClient.makePath("/configs/myconf", true);
zkClient.create("/configs/myconf/firstDummyFile", "first dummy content".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true);
zkClient.create("/configs/myconf/anotherDummyFile", "second dummy content".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true);
// Checking error when configuration name specified already exists
map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD&wt=json&name=myconf", emptyData, null, null);
assertNotNull(map);
statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status"));
assertEquals(400l, statusCode);
assertTrue("Expected file doesnt exist in zk. It's possibly overwritten", zkClient.exists("/configs/myconf/firstDummyFile", true));
assertTrue("Expected file doesnt exist in zk. It's possibly overwritten", zkClient.exists("/configs/myconf/anotherDummyFile", true));
zkClient.close();
solrClient.close();
}
use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.
the class TestConfigSetsAPI method scriptRequest.
public void scriptRequest(String collection) throws SolrServerException, IOException {
SolrClient client = solrCluster.getSolrClient();
SolrInputDocument doc = sdoc("id", "4055", "subject", "Solr");
client.add(collection, doc);
client.commit(collection);
assertEquals("42", client.query(collection, params("q", "*:*")).getResults().get(0).get("script_added_i"));
}
use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.
the class DistributedDebugComponentTest method testRandom.
@Test
public void testRandom() throws Exception {
final int NUM_ITERS = atLeast(50);
for (int i = 0; i < NUM_ITERS; i++) {
SolrClient client = random().nextBoolean() ? collection1 : collection2;
SolrQuery q = new SolrQuery();
q.set("distrib", "true");
q.setFields("id", "text");
boolean shard1Results = random().nextBoolean();
boolean shard2Results = random().nextBoolean();
String qs = "_query_with_no_results_";
if (shard1Results) {
qs += " OR batman";
}
if (shard2Results) {
qs += " OR superman";
}
q.setQuery(qs);
Set<String> shards = new HashSet<String>(Arrays.asList(shard1, shard2));
if (random().nextBoolean()) {
shards.remove(shard1);
shard1Results = false;
} else if (random().nextBoolean()) {
shards.remove(shard2);
shard2Results = false;
}
q.set("shards", StringUtils.join(shards, ","));
List<String> debug = new ArrayList<String>(10);
boolean all = false;
final boolean timing = random().nextBoolean();
final boolean query = random().nextBoolean();
final boolean results = random().nextBoolean();
final boolean track = random().nextBoolean();
if (timing) {
debug.add("timing");
}
if (query) {
debug.add("query");
}
if (results) {
debug.add("results");
}
if (track) {
debug.add("track");
}
if (debug.isEmpty()) {
debug.add("true");
all = true;
}
q.set("debug", (String[]) debug.toArray(new String[debug.size()]));
QueryResponse r = client.query(q);
try {
assertDebug(r, all || track, "track");
assertDebug(r, all || query, "rawquerystring");
assertDebug(r, all || query, "querystring");
assertDebug(r, all || query, "parsedquery");
assertDebug(r, all || query, "parsedquery_toString");
assertDebug(r, all || query, "QParser");
assertDebug(r, all || results, "explain");
assertDebug(r, all || timing, "timing");
} catch (AssertionError e) {
throw new AssertionError(q.toString() + ": " + e.getMessage(), e);
}
}
}
use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.
the class ShowFileRequestHandlerTest method testGetRawFile.
public void testGetRawFile() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
//assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
QueryRequest request = new QueryRequest(params("file", "managed-schema"));
request.setPath("/admin/file");
final AtomicBoolean readFile = new AtomicBoolean();
request.setResponseParser(new ResponseParser() {
@Override
public String getWriterType() {
//unfortunately this gets put onto params wt=mock but it apparently has no effect
return "mock";
}
@Override
public NamedList<Object> processResponse(InputStream body, String encoding) {
try {
if (body.read() >= 0)
readFile.set(true);
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public NamedList<Object> processResponse(Reader reader) {
//TODO
throw new UnsupportedOperationException("TODO unimplemented");
}
});
//runs request
client.request(request);
//request.process(client); but we don't have a NamedList response
assertTrue(readFile.get());
}
Aggregations