Search in sources :

Example 1 with MiniSolrCloudCluster

use of org.apache.solr.cloud.MiniSolrCloudCluster in project YCSB by brianfrankcooper.

the class SolrClientBaseTest method onlyOnce.

@BeforeClass
public static void onlyOnce() throws Exception {
    Path miniSolrCloudClusterTempDirectory = Files.createTempDirectory("miniSolrCloudCluster");
    miniSolrCloudClusterTempDirectory.toFile().deleteOnExit();
    miniSolrCloudCluster = new MiniSolrCloudCluster(1, miniSolrCloudClusterTempDirectory, JettyConfig.builder().build());
    // Upload Solr configuration
    URL configDir = SolrClientBaseTest.class.getClassLoader().getResource("solr_config");
    assertNotNull(configDir);
    miniSolrCloudCluster.uploadConfigDir(new File(configDir.toURI()), MOCK_TABLE);
}
Also used : Path(java.nio.file.Path) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) File(java.io.File) URL(java.net.URL)

Example 2 with MiniSolrCloudCluster

use of org.apache.solr.cloud.MiniSolrCloudCluster in project lucene-solr by apache.

the class TestCloudSolrClientConnections method testCloudClientCanConnectAfterClusterComesUp.

@Test
public void testCloudClientCanConnectAfterClusterComesUp() throws Exception {
    // Start by creating a cluster with no jetties
    MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(0, createTempDir(), buildJettyConfig("/solr"));
    try {
        CloudSolrClient client = cluster.getSolrClient();
        CollectionAdminRequest.List listReq = new CollectionAdminRequest.List();
        try {
            client.request(listReq);
            fail("Requests to a non-running cluster should throw a SolrException");
        } catch (SolrException e) {
            assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().contains("cluster not found/not ready"));
        }
        cluster.startJettySolrRunner();
        client.connect(20, TimeUnit.SECONDS);
        // should work now!
        client.request(listReq);
    } finally {
        cluster.shutdown();
    }
}
Also used : CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 3 with MiniSolrCloudCluster

use of org.apache.solr.cloud.MiniSolrCloudCluster in project lucene-solr by apache.

the class TestCloudSolrClientConnections method testCloudClientUploads.

@Test
public void testCloudClientUploads() throws Exception {
    Path configPath = getFile("solrj").toPath().resolve("solr/configsets/configset-2/conf");
    MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(0, createTempDir(), buildJettyConfig("/solr"));
    try {
        CloudSolrClient client = cluster.getSolrClient();
        try {
            ((ZkClientClusterStateProvider) client.getClusterStateProvider()).uploadConfig(configPath, "testconfig");
            fail("Requests to a non-running cluster should throw a SolrException");
        } catch (SolrException e) {
            assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().contains("cluster not found/not ready"));
        }
        cluster.startJettySolrRunner();
        client.connect(20, TimeUnit.SECONDS);
        ((ZkClientClusterStateProvider) client.getClusterStateProvider()).uploadConfig(configPath, "testconfig");
        ZkConfigManager configManager = new ZkConfigManager(client.getZkStateReader().getZkClient());
        assertTrue("List of uploaded configs does not contain 'testconfig'", configManager.listConfigs().contains("testconfig"));
    } finally {
        cluster.shutdown();
    }
}
Also used : Path(java.nio.file.Path) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 4 with MiniSolrCloudCluster

use of org.apache.solr.cloud.MiniSolrCloudCluster in project lucene-solr by apache.

the class PingRequestHandlerTest method testPingInClusterWithNoHealthCheck.

public void testPingInClusterWithNoHealthCheck() throws Exception {
    MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), buildJettyConfig("/solr"));
    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
    try {
        assertNotNull(miniCluster.getZkServer());
        List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
        assertEquals(NUM_SERVERS, jettys.size());
        for (JettySolrRunner jetty : jettys) {
            assertTrue(jetty.isRunning());
        }
        // create collection
        String collectionName = "testSolrCloudCollection";
        String configName = "solrCloudCollectionConfig";
        miniCluster.uploadConfigSet(SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf"), configName);
        CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR).process(miniCluster.getSolrClient());
        // Send distributed and non-distributed ping query
        SolrPingWithDistrib reqDistrib = new SolrPingWithDistrib();
        reqDistrib.setDistrib(true);
        SolrPingResponse rsp = reqDistrib.process(cloudSolrClient, collectionName);
        assertEquals(0, rsp.getStatus());
        assertTrue(rsp.getResponseHeader().getBooleanArg(("zkConnected")));
        SolrPing reqNonDistrib = new SolrPing();
        rsp = reqNonDistrib.process(cloudSolrClient, collectionName);
        assertEquals(0, rsp.getStatus());
        assertTrue(rsp.getResponseHeader().getBooleanArg(("zkConnected")));
    } finally {
        miniCluster.shutdown();
    }
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrPing(org.apache.solr.client.solrj.request.SolrPing) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 5 with MiniSolrCloudCluster

use of org.apache.solr.cloud.MiniSolrCloudCluster in project lucene-solr by apache.

the class TestLTROnSolrCloud method setupSolrCluster.

private void setupSolrCluster(int numShards, int numReplicas, int numServers, int maxShardsPerNode) throws Exception {
    JettyConfig jc = buildJettyConfig("/solr");
    jc = JettyConfig.builder(jc).withServlets(extraServlets).build();
    solrCluster = new MiniSolrCloudCluster(numServers, tmpSolrHome.toPath(), jc);
    File configDir = tmpSolrHome.toPath().resolve("collection1/conf").toFile();
    solrCluster.uploadConfigSet(configDir.toPath(), "conf1");
    solrCluster.getSolrClient().setDefaultCollection(COLLECTION);
    createCollection(COLLECTION, "conf1", numShards, numReplicas, maxShardsPerNode);
    indexDocuments(COLLECTION);
    createJettyAndHarness(tmpSolrHome.getAbsolutePath(), solrconfig, schema, "/solr", true, extraServlets);
    loadModelsAndFeatures();
}
Also used : JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) File(java.io.File)

Aggregations

MiniSolrCloudCluster (org.apache.solr.cloud.MiniSolrCloudCluster)10 File (java.io.File)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 URL (java.net.URL)2 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 SolrException (org.apache.solr.common.SolrException)2 JettyConfig (org.apache.solr.client.solrj.embedded.JettyConfig)1 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)1 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)1 SolrPing (org.apache.solr.client.solrj.request.SolrPing)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrPingResponse (org.apache.solr.client.solrj.response.SolrPingResponse)1 ZkConfigManager (org.apache.solr.common.cloud.ZkConfigManager)1