下面列出了org.apache.zookeeper.KeeperException.SessionExpiredException#org.apache.solr.client.solrj.impl.HttpSolrClient 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testArbitraryJsonIndexing() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.deleteByQuery("*:*");
client.commit();
assertNumFound("*:*", 0); // make sure it got in
// two docs, one with uniqueKey, another without it
String json = "{\"id\":\"abc1\", \"name\": \"name1\"} {\"name\" : \"name2\"}";
HttpClient httpClient = client.getHttpClient();
HttpPost post = new HttpPost(client.getBaseURL() + "/update/json/docs");
post.setHeader("Content-Type", "application/json");
post.setEntity(new InputStreamEntity(
new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), -1));
HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext());
Utils.consumeFully(response.getEntity());
assertEquals(200, response.getStatusLine().getStatusCode());
client.commit();
assertNumFound("*:*", 2);
}
@Before
public void setup() throws Exception {
builder = new HttpSolrClient.Builder().withBaseSolrUrl("http://solr-server:8983/solr/collection");
enhancedInstance = new EnhanceHttpSolrClient(builder);
when(instance.getCollection()).thenReturn("collection");
when(instance.getRemotePeer()).thenReturn("solr-server:8983");
enhancedInstance.setSkyWalkingDynamicField(instance);
header = new NamedList<Object>();
header.add("status", 0);
header.add("QTime", 5);
// Config.Plugin.SolrJ.TRACE_STATEMENT = true;
// Config.Plugin.SolrJ.TRACE_OPS_PARAMS = true;
}
public void doCommitPerf() throws Exception {
try (HttpSolrClient client = getHttpSolrClient("http://127.0.0.1:8983/solr")) {
final RTimer timer = new RTimer();
for (int i = 0; i < 10000; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", Integer.toString(i % 13));
client.add(doc);
client.commit(true, true, true);
}
System.out.println("TIME: " + timer.getTime());
}
}
public void indexDuplumKey(String id, Map<String, Object> objectMap)
throws IOException, SolrServerException {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", id);
for (Map.Entry<String, Object> entry : objectMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value != null) {
if (!key.endsWith("_sni") && !key.endsWith("_ss"))
key += "_ss";
document.addField(key, value);
}
}
try {
UpdateResponse response = solr.add(document);
} catch (HttpSolrClient.RemoteSolrException ex) {
System.err.printf("document: %s", document);
System.err.printf("Commit exception: %s%n", ex.getMessage());
}
}
public static Map<String, Object> reloadSolrSecurityAuthorizations(DispatchContext dctx, Map<String, Object> context) {
if (!SolrUtil.isSystemInitialized()) { // NOTE: this must NOT use SolrUtil.isSolrLocalWebappPresent() anymore
return ServiceUtil.returnFailure("Solr not enabled or system not ready");
}
try {
HttpSolrClient client = SolrUtil.getAdminHttpSolrClientFromUrl(SolrUtil.getSolrWebappUrl());
//ModifiableSolrParams params = new ModifiableSolrParams();
//// this is very sketchy, I don't think ModifiableSolrParams were meant for this
//params.set("set-user-role", (String) null);
//SolrRequest<?> request = new GenericSolrRequest(METHOD.POST, CommonParams.AUTHZ_PATH, params);
SolrRequest<?> request = new DirectJsonRequest(CommonParams.AUTHZ_PATH,
"{\"set-user-role\":{}}"); // "{\"set-user-role\":{\"dummy\":\"dummy\"}}"
client.request(request);
Debug.logInfo("Solr: reloadSolrSecurityAuthorizations: invoked reload", module);
return ServiceUtil.returnSuccess();
} catch (Exception e) {
Debug.logError("Solr: reloadSolrSecurityAuthorizations: error: " + e.getMessage(), module);
return ServiceUtil.returnError("Error reloading Solr security authorizations: " + e.getMessage());
}
}
private long renewDelegationToken(final String token, final int expectedStatusCode,
final String user, HttpSolrClient client) throws Exception {
DelegationTokenRequest.Renew renew = new DelegationTokenRequest.Renew(token) {
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
params.set(PseudoAuthenticator.USER_NAME, user);
return params;
}
@Override
public Set<String> getQueryParams() {
Set<String> queryParams = super.getQueryParams();
queryParams.add(PseudoAuthenticator.USER_NAME);
return queryParams;
}
};
try {
DelegationTokenResponse.Renew renewResponse = renew.process(client);
assertEquals(HttpStatus.SC_OK, expectedStatusCode);
return renewResponse.getExpirationTime();
} catch (BaseHttpSolrClient.RemoteSolrException ex) {
assertEquals(expectedStatusCode, ex.code());
return -1;
}
}
@Test
public void testForwarding() throws Exception {
String collectionName = "forwardingCollection";
miniCluster.uploadConfigSet(TEST_PATH().resolve("collection1/conf"), "conf1");
create1ShardCollection(collectionName, "conf1", miniCluster);
// try a command to each node, one of them must be forwarded
for (JettySolrRunner jetty : miniCluster.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);
}
}
}
@Test
public void testCloudInfoInCoreStatus() throws IOException, SolrServerException {
String collectionName = "corestatus_test";
CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2)
.process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
cluster.waitForActiveCollection(collectionName, 2, 4);
String nodeName = (String) response._get("success[0]/key", null);
String corename = (String) response._get(asList("success", nodeName, "core"), null);
try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient);
assertEquals(collectionName, status._get(asList("status", corename, "cloud", "collection"), null));
assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null));
assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null));
}
}
@BeforeClass
public static void startup() throws Exception {
HdfsTestUtil.checkAssumptions();
System.setProperty("authenticationPlugin", HttpParamDelegationTokenPlugin.class.getName());
System.setProperty(KerberosPlugin.DELEGATION_TOKEN_ENABLED, "true");
System.setProperty("solr.kerberos.cookie.domain", "127.0.0.1");
Map<String, String> impSettings = getImpersonatorSettings();
for (Map.Entry<String, String> entry : impSettings.entrySet()) {
System.setProperty(entry.getKey(), entry.getValue());
}
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
SolrRequestParsers.DEFAULT.setAddRequestHeadersToContext(true);
System.setProperty("collectionsHandler", ImpersonatorCollectionsHandler.class.getName());
miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), buildJettyConfig("/solr"));
JettySolrRunner runner = miniCluster.getJettySolrRunners().get(0);
solrClient = new HttpSolrClient.Builder(runner.getBaseUrl().toString()).build();
}
private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerException {
List<SolrInputDocument> docs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
doc.addField("name", solrInstance.name);
docs.add(doc);
}
SolrResponseBase resp;
try (HttpSolrClient client = getHttpSolrClient(solrInstance.getUrl(), httpClient)) {
resp = client.add(docs);
assertEquals(0, resp.getStatus());
resp = client.commit();
assertEquals(0, resp.getStatus());
}
}
@Override
protected void index_specific(int serverNumber, Object... fields)
throws Exception {
SolrInputDocument doc = new SolrInputDocument();
for (int i = 0; i < fields.length; i += 2) {
doc.addField((String) (fields[i]), fields[i + 1]);
}
controlClient.add(doc);
HttpSolrClient client = (HttpSolrClient) clients
.get(serverNumber);
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
// ureq.setParam("update.chain", DISTRIB_UPDATE_CHAIN);
ureq.process(client);
}
protected SolrClient createNewSolrClient(String coreName, int port) {
try {
// setup the server...
String baseUrl = buildUrl(port);
String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + coreName;
HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT, 60000);
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
private void mapReplicasToClients() throws KeeperException, InterruptedException {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
cloudClient.getZkStateReader().forceUpdateCollection(DEFAULT_COLLECTION);
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
Replica leader = null;
Slice shard1 = clusterState.getCollection(DEFAULT_COLLECTION).getSlice(SHARD1);
leader = shard1.getLeader();
String leaderBaseUrl = zkStateReader.getBaseUrlForNodeName(leader.getNodeName());
for (int i=0; i<clients.size(); i++) {
if (((HttpSolrClient)clients.get(i)).getBaseURL().startsWith(leaderBaseUrl))
LEADER = clients.get(i);
}
NONLEADERS = new ArrayList<>();
for (Replica rep: shard1.getReplicas()) {
if (rep.equals(leader)) {
continue;
}
String baseUrl = zkStateReader.getBaseUrlForNodeName(rep.getNodeName());
for (int i=0; i<clients.size(); i++) {
if (((HttpSolrClient)clients.get(i)).getBaseURL().startsWith(baseUrl))
NONLEADERS.add(clients.get(i));
}
}
assertNotNull(LEADER);
assertEquals(2, NONLEADERS.size());
}
private SolrClient createSolrClient() {
if(logger.isDebugEnabled()) {
logger.debug("HttpClientBuilder = {}", HttpClientUtil.getHttpClientBuilder(), new Exception());
}
final ModifiableSolrParams clientParams = new ModifiableSolrParams();
SolrClient solrClient = null;
Mode mode = Mode.parse(configuration.get(SOLR_MODE));
switch (mode) {
case CLOUD:
final CloudSolrClient cloudServer = new CloudSolrClient.Builder()
.withLBHttpSolrClientBuilder(
new LBHttpSolrClient.Builder()
.withHttpSolrClientBuilder(new HttpSolrClient.Builder().withInvariantParams(clientParams))
.withBaseSolrUrls(configuration.get(HTTP_URLS))
)
.withZkHost(getZookeeperURLs(configuration))
.sendUpdatesOnlyToShardLeaders()
.build();
cloudServer.connect();
solrClient = cloudServer;
logger.info("Created solr client using Cloud based configuration.");
break;
case HTTP:
clientParams.add(HttpClientUtil.PROP_ALLOW_COMPRESSION, configuration.get(HTTP_ALLOW_COMPRESSION).toString());
clientParams.add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, configuration.get(HTTP_CONNECTION_TIMEOUT).toString());
clientParams.add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, configuration.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString());
clientParams.add(HttpClientUtil.PROP_MAX_CONNECTIONS, configuration.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString());
final HttpClient client = HttpClientUtil.createClient(clientParams);
solrClient = new LBHttpSolrClient.Builder()
.withHttpClient(client)
.withBaseSolrUrls(configuration.get(HTTP_URLS))
.build();
logger.info("Created solr client using HTTP based configuration.");
break;
default:
throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode);
}
return solrClient;
}
/**
* uses distrib=false RTG requests to verify that the specified docId can be found using the
* specified solr client
*/
private void assertDocExists(final String clientName, final HttpSolrClient client, final String docId) throws Exception {
final QueryResponse rsp = (new QueryRequest(params("qt", "/get",
"id", docId,
"_trace", clientName,
"distrib", "false")))
.process(client, COLLECTION);
assertEquals(0, rsp.getStatus());
String match = JSONTestUtil.matchObj("/id", rsp.getResponse().get("doc"), docId);
assertTrue("Doc with id=" + docId + " not found in " + clientName
+ " due to: " + match + "; rsp="+rsp, match == null);
}
@Test
public void test() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/cores");
int which = r.nextInt(clients.size());
HttpSolrClient client = (HttpSolrClient)clients.get(which);
String previousBaseURL = client.getBaseURL();
// Strip /collection1 step from baseURL - requests fail otherwise
client.setBaseURL(previousBaseURL.substring(0, previousBaseURL.lastIndexOf("/")));
@SuppressWarnings({"rawtypes"})
NamedList namedListResponse = client.request(request);
client.setBaseURL(previousBaseURL); // Restore baseURL
@SuppressWarnings({"rawtypes"})
NamedList status = (NamedList)namedListResponse.get("status");
@SuppressWarnings({"rawtypes"})
NamedList collectionStatus = (NamedList)status.getVal(0);
String collectionSchema = (String)collectionStatus.get(CoreAdminParams.SCHEMA);
// Make sure the upgrade to managed schema happened
assertEquals("Schema resource name differs from expected name", "managed-schema", collectionSchema);
SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 30000);
try {
// Make sure "DO NOT EDIT" is in the content of the managed schema
String fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/managed-schema");
assertTrue("Managed schema is missing", fileContent.contains("DO NOT EDIT"));
// Make sure the original non-managed schema is no longer in ZooKeeper
assertFileNotInZooKeeper(zkClient, "/solr/configs/conf1", "schema.xml");
// Make sure the renamed non-managed schema is present in ZooKeeper
fileContent = getFileContentFromZooKeeper(zkClient, "/solr/configs/conf1/schema.xml.bak");
assertTrue("schema file doesn't contain '<schema'", fileContent.contains("<schema"));
} finally {
if (zkClient != null) {
zkClient.close();
}
}
}
private void commitOnLeader(String leaderUrl) throws SolrServerException,
IOException {
try (HttpSolrClient client = new HttpSolrClient.Builder(leaderUrl)
.withConnectionTimeout(30000)
.build()) {
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams());
ureq.getParams().set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
ureq.getParams().set(UpdateParams.OPEN_SEARCHER, false);
ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true).process(
client);
}
}
public String add(HttpSolrClient client) throws SolrServerException, IOException {
List<SolrInputDocument> docs = new ArrayList<>();
for (int i = 0; i < 100; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
docs.add(doc);
}
client.add(collection, docs);
return "Success";
}
private BootstrapStatus getBoostrapStatus() throws InterruptedException {
try {
Replica leader = state.getClient().getZkStateReader().getLeaderRetry(targetCollection, shard, 30000); // assume same shard exists on target
String leaderCoreUrl = leader.getCoreUrl();
HttpClient httpClient = state.getClient().getLbClient().getHttpClient();
try (HttpSolrClient client = new HttpSolrClient.Builder(leaderCoreUrl).withHttpClient(httpClient).build()) {
@SuppressWarnings({"rawtypes"})
NamedList response = sendCdcrCommand(client, CdcrParams.CdcrAction.BOOTSTRAP_STATUS);
String status = (String) response.get(RESPONSE_STATUS);
BootstrapStatus bootstrapStatus = BootstrapStatus.valueOf(status.toUpperCase(Locale.ROOT));
if (bootstrapStatus == BootstrapStatus.RUNNING) {
return BootstrapStatus.RUNNING;
} else if (bootstrapStatus == BootstrapStatus.COMPLETED) {
return BootstrapStatus.COMPLETED;
} else if (bootstrapStatus == BootstrapStatus.FAILED) {
return BootstrapStatus.FAILED;
} else if (bootstrapStatus == BootstrapStatus.NOTFOUND) {
log.warn("Bootstrap process was not found on target collection: {} shard: {}, leader: {}", targetCollection, shard, leaderCoreUrl);
return BootstrapStatus.NOTFOUND;
} else if (bootstrapStatus == BootstrapStatus.CANCELLED) {
return BootstrapStatus.CANCELLED;
} else {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Unknown status: " + status + " returned by BOOTSTRAP_STATUS command");
}
}
} catch (Exception e) {
log.error("Exception during bootstrap status request", e);
return BootstrapStatus.UNKNOWN;
}
}
private void doSolrRequest(HttpSolrClient client,
@SuppressWarnings({"rawtypes"})SolrRequest request,
int expectedStatusCode) throws Exception {
try {
client.request(request);
assertEquals(HttpStatus.SC_OK, expectedStatusCode);
} catch (BaseHttpSolrClient.RemoteSolrException ex) {
assertEquals(expectedStatusCode, ex.code());
}
}
/**
* Query the real-time get handler for a specific doc by ID to verify it
* exists in the provided server, using distrib=false so it doesn't route to another replica.
*/
@SuppressWarnings("rawtypes")
protected void assertDocExists(HttpSolrClient solr, String coll, String docId) throws Exception {
NamedList rsp = realTimeGetDocId(solr, docId);
String match = JSONTestUtil.matchObj("/id", rsp.get("doc"), docId);
assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL()
+ " due to: " + match + "; rsp="+rsp, match == null);
}
private void cancelDelegationToken(String token, int expectedStatusCode, HttpSolrClient client)
throws Exception {
DelegationTokenRequest.Cancel cancel = new DelegationTokenRequest.Cancel(token);
try {
cancel.process(client);
assertEquals(HttpStatus.SC_OK, expectedStatusCode);
} catch (BaseHttpSolrClient.RemoteSolrException ex) {
assertEquals(expectedStatusCode, ex.code());
}
}
/**
* This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
* Tests that do not wish to have any randomized behavior should use the
* {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
*/
public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient, ResponseParser responseParser) {
return new Builder(url)
.withHttpClient(httpClient)
.withResponseParser(responseParser)
.build();
}
private void assertDocExists(HttpSolrClient solr, String coll, String docId) throws Exception {
@SuppressWarnings({"rawtypes"})
NamedList rsp = realTimeGetDocId(solr, docId);
String match = JSONTestUtil.matchObj("/id", rsp.get("doc"), docId);
assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL()
+ " due to: " + match + "; rsp="+rsp, match == null);
}
public static boolean isSolrWebappPingOk(HttpSolrClient client) throws Exception {
try {
return isSolrWebappPingOkRaw(client);
} catch(Exception e) {
// FIXME: we are not supposed to catch this, but in current setup with Tomcat
// solr can't handle the incomplete loading 503 and throws exception, so have no choice
// but because this is only a Ping, we can usually assume this means not yet loaded...
// NOTE: This case also occurs currently if connect/socket timeout
Debug.logInfo("Solr: isSolrWebappPingOk: Solr webapp not pingable. Cause: " + e.toString(), module);
return false;
}
}
/**
* Fetches the list of files in a given index commit point and updates internal list of files to download.
*/
@SuppressWarnings({"unchecked"})
private void fetchFileList(long gen) throws IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(COMMAND, CMD_GET_FILE_LIST);
params.set(TLOG_FILES, downloadTlogFiles);
params.set(GENERATION, String.valueOf(gen));
params.set(CommonParams.WT, JAVABIN);
params.set(CommonParams.QT, ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params);
// TODO modify to use shardhandler
try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl)
.withHttpClient(myHttpClient)
.withConnectionTimeout(connTimeout)
.withSocketTimeout(soTimeout)
.build()) {
@SuppressWarnings({"rawtypes"})
NamedList response = client.request(req);
List<Map<String, Object>> files = (List<Map<String,Object>>) response.get(CMD_GET_FILE_LIST);
if (files != null)
filesToDownload = Collections.synchronizedList(files);
else {
filesToDownload = Collections.emptyList();
log.error("No files to download for index generation: {}", gen);
}
files = (List<Map<String,Object>>) response.get(CONF_FILES);
if (files != null)
confFilesToDownload = Collections.synchronizedList(files);
files = (List<Map<String, Object>>) response.get(TLOG_FILES);
if (files != null) {
tlogFilesToDownload = Collections.synchronizedList(files);
}
} catch (SolrServerException e) {
throw new IOException(e);
}
}
private void changeUrlOnError(Exception e) {
if (e instanceof ConnectException) {
clientIndex++;
if (clientIndex > clients.size() - 1) {
clientIndex = 0;
}
cusc.shutdownNow();
cusc = new ErrorLoggingConcurrentUpdateSolrClient.Builder(((HttpSolrClient) clients.get(clientIndex)).getBaseURL())
.withHttpClient(httpClient)
.withQueueSize(30)
.withThreadCount(3)
.build();
}
}
@Test
public void testZkread() throws Exception {
URL baseUrl = cluster.getJettySolrRunner(0).getBaseUrl();
String basezk = baseUrl.toString().replace("/solr", "/api") + "/cluster/zk/data";
String basezkls = baseUrl.toString().replace("/solr", "/api") + "/cluster/zk/ls";
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) {
Object o = Utils.executeGET(client.getHttpClient(),
basezk + "/security.json",
Utils.JSONCONSUMER);
assertNotNull(o);
o = Utils.executeGET(client.getHttpClient(),
basezkls + "/configs",
Utils.JSONCONSUMER);
assertEquals("0", String.valueOf(getObjectByPath(o, true, split(":/configs:_default:dataLength", ':'))));
assertEquals("0", String.valueOf(getObjectByPath(o, true, split(":/configs:conf:dataLength", ':'))));
o = Utils.executeGET(client.getHttpClient(),
basezk + "/configs",
Utils.JSONCONSUMER);
assertTrue(((Map)o).containsKey("/configs"));
assertNull(((Map)o).get("/configs"));
byte[] bytes = new byte[1024 * 5];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) random().nextInt(128);
}
cluster.getZkClient().create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT, true);
Utils.executeGET(client.getHttpClient(),
basezk + "/configs/_default/testdata",
is -> {
byte[] newBytes = new byte[bytes.length];
is.read(newBytes);
for (int i = 0; i < newBytes.length; i++) {
assertEquals(bytes[i], newBytes[i]);
}
return null;
});
}
}
/**
* DO NOT CALL! use Spring instead.
* @param geocoder_conf geocoder's configuration object.
*/
public SolrDao(GeocoderConfiguration geocoder_conf)
{
geocoder = new CachedGeocoder(new NominatimGeocoder(geocoder_conf));
solrClient = new HttpSolrClient("");
solrClient.setConnectionTimeout(INNER_TIMEOUT);
solrClient.setSoTimeout(INNER_TIMEOUT);
}
@Test
@Monster("Only useful to verify the performance of serialization+ deserialization")
// ant -Dtestcase=SolrExampleBinaryTest -Dtests.method=testQueryPerf -Dtests.monster=true test
public void testQueryPerf() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.deleteByQuery("*:*");
client.commit();
ArrayList<SolrInputDocument> docs = new ArrayList<>();
int id = 0;
docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "apple", "cat", "a", "inStock", true, "popularity", 12, "price", .017));
docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "lg", "cat", "a", "inStock", false, "popularity", 13, "price", 16.04));
docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "samsung", "cat", "a", "inStock", true, "popularity", 14, "price", 12.34));
docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "lg", "cat", "b", "inStock", false, "popularity", 24, "price", 51.39));
docs.add(makeTestDoc("id", id++, "features", "aaa", "manu", "nokia", "cat", "b", "inStock", true, "popularity", 28, "price", 131.39));
docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "a", "inStock", false, "popularity", 32));
docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "htc", "cat", "a", "inStock", true, "popularity", 31, "price", 131.39));
docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "apple", "cat", "b", "inStock", false, "popularity", 36));
docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "lg", "cat", "b", "inStock", true, "popularity", 37, "price", 1.39));
docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "b", "inStock", false, "popularity", 38, "price", 47.98));
docs.add(makeTestDoc("id", id++, "features", "bbb", "manu", "ztc", "cat", "b", "inStock", true, "popularity", -38));
docs.add(makeTestDoc("id", id++, "cat", "b")); // something not matching all fields
client.add(docs);
client.commit();
//this sets the cache
QueryResponse rsp = getSolrClient().query(new SolrQuery("*:*").setRows(20));
RTimer timer = new RTimer();
int count = 10000;
log.info("Started perf test....");
for(int i=0;i< count; i++){
rsp = getSolrClient().query(new SolrQuery("*:*").setRows(20));
}
if (log.isInfoEnabled()) {
log.info("time taken to execute {} queries is {} ms", count, timer.getTime());
}
}