org.apache.solr.client.solrj.impl.HttpSolrClient Java Examples

The following examples show how to use org.apache.solr.client.solrj.impl.HttpSolrClient. 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: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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));
  }
}
 
Example #2
Source File: SolrProductSearch.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example #3
Source File: MarcSolrClient.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
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());
  }
}
 
Example #4
Source File: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: TestSolrCloudWithSecureImpersonation.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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);
    }
  }
}
 
Example #6
Source File: TestSolrJ.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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());
    }

  }
 
Example #7
Source File: TestSolrCloudWithSecureImpersonation.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #8
Source File: SolrClientInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #9
Source File: TestDelegationWithHadoopAuth.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example #10
Source File: TestLBHttpSolrClient.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example #11
Source File: SolrSchemalessExampleTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #12
Source File: MCRSolrCategoryDAO.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
protected void solrDelete(MCRCategoryID id, MCRCategory parent) {
    try {
        // remove all descendants and itself
        HttpSolrClient solrClient = MCRSolrClassificationUtil.getCore().getClient();
        List<String> toDelete = MCRSolrSearchUtils.listIDs(solrClient,
            "ancestor:" + MCRSolrClassificationUtil.encodeCategoryId(id));
        toDelete.add(id.toString());
        solrClient.deleteById(toDelete);
        // reindex parent
        MCRSolrClassificationUtil.reindex(parent);
    } catch (Exception exc) {
        LOGGER.error("Solr: unable to delete categories of parent {}", id);
    }
}
 
Example #13
Source File: SolrDao.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #14
Source File: DistributedDebugComponentTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void createThings() throws Exception {
  systemSetPropertySolrDisableShardsWhitelist("true");
  solrHome = createSolrHome();
  createAndStartJetty(solrHome.getAbsolutePath());
  String url = jetty.getBaseUrl().toString();

  collection1 = getHttpSolrClient(url + "/collection1");
  collection2 = getHttpSolrClient(url + "/collection2");
  
  String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
  String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
  shard1 = urlCollection1.replaceAll("https?://", "");
  shard2 = urlCollection2.replaceAll("https?://", "");
  
  //create second core
  try (HttpSolrClient nodeClient = getHttpSolrClient(url)) {
    CoreAdminRequest.Create req = new CoreAdminRequest.Create();
    req.setCoreName("collection2");
    req.setConfigSet("collection1");
    nodeClient.request(req);
  }

  SolrInputDocument doc = new SolrInputDocument();
  doc.setField("id", "1");
  doc.setField("text", "batman");
  collection1.add(doc);
  collection1.commit();
  
  doc.setField("id", "2");
  doc.setField("text", "superman");
  collection2.add(doc);
  collection2.commit();
  
}
 
Example #15
Source File: BasicDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected SolrClient createNewSolrClient(String collection, String baseUrl, int connectionTimeoutMillis, int socketTimeoutMillis) {
  try {
    // setup the server...
    HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection, connectionTimeoutMillis, socketTimeoutMillis);

    return client;
  }
  catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #16
Source File: SolrUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public HttpSolrClient getClientFromUrl(String url, String solrUsername, String solrPassword) {
    if (UtilValidate.isEmpty(solrUsername)) {
        solrUsername = getConnectConfig().getSolrUsername();
        solrPassword = getConnectConfig().getSolrPassword();
    } else if ("_none_".equals(solrUsername)) {
        solrUsername = null;
        solrPassword = null;
    }
    return getClientFromUrlRaw(url, solrUsername, solrPassword);
}
 
Example #17
Source File: HttpShardHandlerFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Deprecated
public ShardHandler getShardHandler(final HttpClient httpClient) {
  // a little hack for backward-compatibility when we are moving from apache http client to jetty client
  return new HttpShardHandler(this, null) {
    @Override
    protected NamedList<Object> request(String url, @SuppressWarnings({"rawtypes"})SolrRequest req) throws IOException, SolrServerException {
      try (SolrClient client = new HttpSolrClient.Builder(url).withHttpClient(httpClient).build()) {
        return client.request(req);
      }
    }
  };
}
 
Example #18
Source File: SolrUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public HttpSolrClient getClientForCore(String core, String solrUsername, String solrPassword) {
    if (UtilValidate.isEmpty(solrUsername)) {
        solrUsername = getConnectConfig().getSolrUsername();
        solrPassword = getConnectConfig().getSolrPassword();
    } else if ("_none_".equals(solrUsername)) {
        solrUsername = null;
        solrPassword = null;
    }
    if (UtilValidate.isNotEmpty(core)) {
        return getClientFromUrlRaw(getSolrCoreUrl(core), solrUsername, solrPassword);
    } else {
        return getClientFromUrlRaw(getSolrDefaultCoreUrl(), solrUsername, solrPassword);
    }
}
 
Example #19
Source File: SolrUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public HttpSolrClient getClientFromUrlRaw(String url, String solrUsername, String solrPassword) {
    final String cacheKey = (solrUsername != null) ? (url + ":" + solrUsername + ":" + solrPassword) : url;
    if (defaultClientCacheKey.equals(cacheKey)) {
        if (Debug.verboseOn()) Debug.logVerbose("Solr: Using default solr " + connectConfig.makeClientLogDesc(url,  solrUsername), module);
        return defaultClient;
    }

    HttpSolrClient client = clientCache.get(cacheKey);
    if (client == null) {
        synchronized(this) {
            client = clientCache.get(cacheKey);
            if (client == null) {
                client = NewSolrClientFactory.makeClient(connectConfig, url, solrUsername, solrPassword);
                // use immutable map pattern for performance (the map only ever contains a few entries)
                Map<String, HttpSolrClient> newCache = new HashMap<>(clientCache);
                newCache.put(cacheKey, client);
                clientCache = Collections.unmodifiableMap(newCache);
            } else {
                if (Debug.verboseOn()) Debug.logVerbose("Solr: Using cached solr " + connectConfig.makeClientLogDesc(url,  solrUsername), module);
            }
        }
    } else {
        if (Debug.verboseOn()) Debug.logVerbose("Solr: Using cached solr " + connectConfig.makeClientLogDesc(url,  solrUsername), module);
    }
    return client;
}
 
Example #20
Source File: MCRSolrCommands.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@MCRCommand(
    syntax = "rebuild solr metadata and content index in core {0}",
    help = "rebuilds metadata and content index in Solr for core with the id {0}",
    order = 110)
public static void rebuildMetadataAndContentIndex(String coreID) throws Exception {
    MCRSolrCore core = getCore(coreID);
    HttpSolrClient client = core.getClient();
    MCRSolrIndexer.rebuildMetadataIndex(client);
    MCRSolrIndexer.rebuildContentIndex(client);
    MCRSolrIndexer.optimize(client);
}
 
Example #21
Source File: TestCloudPhrasesIdentificationComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@AfterClass
private static void afterClass() throws Exception {
  if (null != CLOUD_CLIENT) {
    CLOUD_CLIENT.close();
    CLOUD_CLIENT = null;
  }
  for (HttpSolrClient client : CLIENTS) {
    client.close();
  }
  CLIENTS.clear();
}
 
Example #22
Source File: TestCloudPseudoReturnFields.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@AfterClass
private static void afterClass() throws Exception {
  if (null != CLOUD_CLIENT) {
    CLOUD_CLIENT.close();
    CLOUD_CLIENT = null;
  }
  for (HttpSolrClient client : CLIENTS) {
    client.close();
  }
  CLIENTS.clear();
}
 
Example #23
Source File: TestCloudJSONFacetJoinDomain.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@AfterClass
private static void afterClass() throws Exception {
  if (null != CLOUD_CLIENT) {
    CLOUD_CLIENT.close();
    CLOUD_CLIENT = null;
  }
  for (HttpSolrClient client : CLIENTS) {
    client.close();
  }
  CLIENTS.clear();
}
 
Example #24
Source File: SolrUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static CachedSolrClientFactory create(SolrConnectConfig connectConfig) {
    String defaultClientCacheKey = (connectConfig.getSolrUsername() != null) ?
            (connectConfig.getSolrCoreUrl() + ":" + connectConfig.getSolrUsername() + ":" + connectConfig.getSolrPassword())
            : connectConfig.getSolrCoreUrl();
    HttpSolrClient defaultClient = NewSolrClientFactory.makeClient(connectConfig, connectConfig.getSolrCoreUrl(),
            connectConfig.getSolrUsername(), connectConfig.getSolrPassword());
    return new CachedSolrClientFactory(connectConfig, defaultClientCacheKey, defaultClient);
}
 
Example #25
Source File: TopicStream.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void getPersistedCheckpoints() throws IOException {
  ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
  Slice[] slices = CloudSolrStream.getSlices(checkpointCollection, zkStateReader, false);

  ClusterState clusterState = zkStateReader.getClusterState();
  Set<String> liveNodes = clusterState.getLiveNodes();

  OUTER:
  for(Slice slice : slices) {
    Collection<Replica> replicas = slice.getReplicas();
    for(Replica replica : replicas) {
      if(replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())){
        HttpSolrClient httpClient = streamContext.getSolrClientCache().getHttpSolrClient(replica.getCoreUrl());
        try {
          SolrDocument doc = httpClient.getById(id);
          if(doc != null) {
            @SuppressWarnings({"unchecked"})
            List<String> checkpoints = (List<String>)doc.getFieldValue("checkpoint_ss");
            for (String checkpoint : checkpoints) {
              String[] pair = checkpoint.split("~");
              this.checkpoints.put(pair[0], Long.parseLong(pair[1]));
            }
          }
        } catch (Exception e) {
          throw new IOException(e);
        }
        break OUTER;
      }
    }
  }
}
 
Example #26
Source File: SolrSpewer.java    From extract with MIT License 5 votes vote down vote up
@Override
public void close() throws IOException {

	// Commit any remaining files if auto-committing is enabled.
	if (commitThreshold > 0) {
		commitPending(0);
	}

	client.close();
	if (client instanceof HttpSolrClient) {
		((CloseableHttpClient) ((HttpSolrClient) client).getHttpClient()).close();
	}
}
 
Example #27
Source File: BasicDistributedZkTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected String getBaseUrl(SolrClient client) {
  String url2 = ((HttpSolrClient) client).getBaseURL()
      .substring(
          0,
          ((HttpSolrClient) client).getBaseURL().length()
              - DEFAULT_COLLECTION.length() -1);
  return url2;
}
 
Example #28
Source File: ZookeeperReadAPITest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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;
        });
  }
}
 
Example #29
Source File: TestRestoreCore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static SolrClient createNewSolrClient(int port) {
  try {
    // setup the client...
    final String baseUrl = buildUrl(port, context);
    HttpSolrClient client = getHttpSolrClient(baseUrl, 15000, 60000);
    return client;
  }
  catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #30
Source File: SolrExampleTests.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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());
  }

}