Package org.apache.solr.client.solrj.impl

Examples of org.apache.solr.client.solrj.impl.LBHttpSolrServer


  public void testSimple() throws Exception {
    String[] s = new String[solr.length];
    for (int i = 0; i < solr.length; i++) {
      s[i] = solr[i].getUrl();
    }
    LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, s);
    lbHttpSolrServer.setAliveCheckInterval(500);
    SolrQuery solrQuery = new SolrQuery("*:*");
    Set<String> names = new HashSet<String>();
    QueryResponse resp = null;
    for (String value : s) {
      resp = lbHttpSolrServer.query(solrQuery);
      assertEquals(10, resp.getResults().getNumFound());
      names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());

    // Kill a server and test again
    solr[1].jetty.stop();
    solr[1].jetty = null;
    names.clear();
    for (String value : s) {
      resp = lbHttpSolrServer.query(solrQuery);
      assertEquals(10, resp.getResults().getNumFound());
      names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(2, names.size());
    assertFalse(names.contains("solr1"));

    // Start the killed server once again
    solr[1].startJetty();
    // Wait for the alive check to complete
    Thread.sleep(1200);
    names.clear();
    for (String value : s) {
      resp = lbHttpSolrServer.query(solrQuery);
      assertEquals(10, resp.getResults().getNumFound());
      names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());
  }
View Full Code Here


    }
    assertEquals(3, names.size());
  }

  public void testTwoServers() throws Exception {
    LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, solr[0].getUrl(), solr[1].getUrl());
    lbHttpSolrServer.setAliveCheckInterval(500);
    SolrQuery solrQuery = new SolrQuery("*:*");
    Set<String> names = new HashSet<String>();
    QueryResponse resp = null;
    solr[0].jetty.stop();
    solr[0].jetty = null;
    resp = lbHttpSolrServer.query(solrQuery);
    String name = resp.getResults().get(0).getFieldValue("name").toString();
    Assert.assertEquals("solr1", name);
    resp = lbHttpSolrServer.query(solrQuery);
    name = resp.getResults().get(0).getFieldValue("name").toString();
    Assert.assertEquals("solr1", name);
    solr[1].jetty.stop();
    solr[1].jetty = null;
    solr[0].startJetty();
    Thread.sleep(1200);
    try {
      resp = lbHttpSolrServer.query(solrQuery);
    } catch(SolrServerException e) {
      // try again after a pause in case the error is lack of time to start server
      Thread.sleep(3000);
      resp = lbHttpSolrServer.query(solrQuery);
    }
    name = resp.getResults().get(0).getFieldValue("name").toString();
    Assert.assertEquals("solr0", name);
  }
View Full Code Here

    }
    HttpClient myHttpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

    myHttpClient.getParams().setParameter("http.connection.timeout", new Integer(100));
    myHttpClient.getParams().setParameter("http.socket.timeout", new Integer(100));
    LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(myHttpClient, s);
    lbHttpSolrServer.setAliveCheckInterval(500);

    // Kill a server and test again
    solr[1].jetty.stop();
    solr[1].jetty = null;

    // query the servers
    for (String value : s)
      lbHttpSolrServer.query(new SolrQuery("*:*"));

    // Start the killed server once again
    solr[1].startJetty();
    // Wait for the alive check to complete
    waitForServer(30000, lbHttpSolrServer, 3, "solr1");
View Full Code Here

  public void testSimple() throws Exception {
    String[] s = new String[solr.length];
    for (int i = 0; i < solr.length; i++) {
      s[i] = solr[i].getUrl();
    }
    LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, s);
    lbHttpSolrServer.setAliveCheckInterval(500);
    SolrQuery solrQuery = new SolrQuery("*:*");
    Set<String> names = new HashSet<String>();
    QueryResponse resp = null;
    for (String value : s) {
      resp = lbHttpSolrServer.query(solrQuery);
      assertEquals(10, resp.getResults().getNumFound());
      names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());

    // Kill a server and test again
    solr[1].jetty.stop();
    solr[1].jetty = null;
    names.clear();
    for (String value : s) {
      resp = lbHttpSolrServer.query(solrQuery);
      assertEquals(10, resp.getResults().getNumFound());
      names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(2, names.size());
    assertFalse(names.contains("solr1"));

    // Start the killed server once again
    solr[1].startJetty();
    // Wait for the alive check to complete
    Thread.sleep(1200);
    names.clear();
    for (String value : s) {
      resp = lbHttpSolrServer.query(solrQuery);
      assertEquals(10, resp.getResults().getNumFound());
      names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());
  }
View Full Code Here

    }
    assertEquals(3, names.size());
  }

  public void testTwoServers() throws Exception {
    LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, solr[0].getUrl(), solr[1].getUrl());
    lbHttpSolrServer.setAliveCheckInterval(500);
    SolrQuery solrQuery = new SolrQuery("*:*");
    Set<String> names = new HashSet<String>();
    QueryResponse resp = null;
    solr[0].jetty.stop();
    solr[0].jetty = null;
    resp = lbHttpSolrServer.query(solrQuery);
    String name = resp.getResults().get(0).getFieldValue("name").toString();
    Assert.assertEquals("solr1", name);
    resp = lbHttpSolrServer.query(solrQuery);
    name = resp.getResults().get(0).getFieldValue("name").toString();
    Assert.assertEquals("solr1", name);
    solr[1].jetty.stop();
    solr[1].jetty = null;
    solr[0].startJetty();
    Thread.sleep(1200);
    try {
      resp = lbHttpSolrServer.query(solrQuery);
    } catch(SolrServerException e) {
      // try again after a pause in case the error is lack of time to start server
      Thread.sleep(3000);
      resp = lbHttpSolrServer.query(solrQuery);
    }
    name = resp.getResults().get(0).getFieldValue("name").toString();
    Assert.assertEquals("solr0", name);
  }
View Full Code Here

      // LBHttpSolrServer - denoted by "loadbalance" in properties
    } else if (solrJServerType.toString().toLowerCase().equals("loadbalance")) {
      LOG.info("Using LBHttpSolrServer Solrj implementation.");
      String[] solrUrlElements = StringUtils.split(solrServerUrl);
      try {
        this.adminServer = new LBHttpSolrServer(solrUrlElements);
      } catch (MalformedURLException e) {
        e.printStackTrace();
      }
      try {
        this.server = new LBHttpSolrServer( solrUrlElements + "/" + mapping.getCoreName() );
      } catch (MalformedURLException e) {
        e.printStackTrace();
      }
    }
    if (autoCreateSchema) {
View Full Code Here

  private static LBHttpSolrServer cloneLBHttpSolrServer(SolrServer solrServer, String core) {
    if (solrServer == null) {
      return null;
    }

    LBHttpSolrServer clone = null;
    try {
      if (VersionUtil.isSolr3XAvailable()) {
        clone = cloneSolr3LBHttpServer(solrServer, core);
      } else if (VersionUtil.isSolr4XAvailable()) {
        clone = cloneSolr4LBHttpServer(solrServer, core);
      }
    } catch (Exception e) {
      throw new BeanInstantiationException(solrServer.getClass(), "Cannot create instace of " + solrServer.getClass()
          + ". ", e);
    }
    Object o = readField(solrServer, "interval");
    if (o != null) {
      clone.setAliveCheckInterval(Integer.valueOf(o.toString()).intValue());
    }
    return clone;
  }
View Full Code Here

    String[] servers = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
      servers[i] = appendCoreToBaseUrl(list.get(i).toString(), core);
    }
    return new LBHttpSolrServer(servers);
  }
View Full Code Here

    Boolean isInternalCient = readField(solrServer, "clientIsInternal");

    if (isInternalCient != null && !isInternalCient) {
      HttpClient clientToUse = readAndCloneHttpClient(solrServer);
      return new LBHttpSolrServer(clientToUse, servers);
    }
    return new LBHttpSolrServer(servers);
  }
View Full Code Here

    this.setSolrServer(httpSolrServer);
  }

  private void createLoadBalancedHttpSolrServer() {
    try {
      LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(StringUtils.split(this.url, SERVER_URL_SEPARATOR));
      if (timeout != null) {
        lbHttpSolrServer.setConnectionTimeout(timeout.intValue());
      }
      this.setSolrServer(lbHttpSolrServer);
    } catch (MalformedURLException e) {
      throw new IllegalArgumentException("Unable to create Load Balanced Http Solr Server", e);
    }
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.impl.LBHttpSolrServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.