Search in sources :

Example 41 with SolrClient

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();
}
Also used : RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrClient(org.apache.solr.client.solrj.SolrClient) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) Create(org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create) ConfigSetAdminResponse(org.apache.solr.client.solrj.response.ConfigSetAdminResponse) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Example 42 with SolrClient

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();
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) BasicAuthIntegrationTest(org.apache.solr.security.BasicAuthIntegrationTest) Test(org.junit.Test)

Example 43 with SolrClient

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"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient)

Example 44 with SolrClient

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);
        }
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ArrayList(java.util.ArrayList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with SolrClient

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) ResponseParser(org.apache.solr.client.solrj.ResponseParser) SolrClient(org.apache.solr.client.solrj.SolrClient) InputStream(java.io.InputStream) NamedList(org.apache.solr.common.util.NamedList) Reader(java.io.Reader) IOException(java.io.IOException)

Aggregations

SolrClient (org.apache.solr.client.solrj.SolrClient)172 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)105 Test (org.junit.Test)67 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)38 ArrayList (java.util.ArrayList)36 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)31 SolrQuery (org.apache.solr.client.solrj.SolrQuery)28 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)28 SolrInputDocument (org.apache.solr.common.SolrInputDocument)28 IOException (java.io.IOException)24 NamedList (org.apache.solr.common.util.NamedList)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)18 SolrException (org.apache.solr.common.SolrException)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)17 Map (java.util.Map)16 Replica (org.apache.solr.common.cloud.Replica)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)15 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)14 SolrDocument (org.apache.solr.common.SolrDocument)14 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)13