Search in sources :

Example 91 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class TestCollectionStateWatchers method testPredicateFailureTimesOut.

@Test
public void testPredicateFailureTimesOut() throws Exception {
    CloudSolrClient client = cluster.getSolrClient();
    expectThrows(TimeoutException.class, () -> {
        client.waitForState("nosuchcollection", 1, TimeUnit.SECONDS, ((liveNodes, collectionState) -> false));
    });
    waitFor("Watchers for collection should be removed after timeout", 1, TimeUnit.SECONDS, () -> client.getZkStateReader().getStateWatchers("nosuchcollection").isEmpty());
}
Also used : AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) BeforeClass(org.junit.BeforeClass) MethodHandles(java.lang.invoke.MethodHandles) SolrCloudTestCase(org.apache.solr.cloud.SolrCloudTestCase) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Callable(java.util.concurrent.Callable) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Future(java.util.concurrent.Future) ExecutorUtil(org.apache.solr.common.util.ExecutorUtil) ExecutorService(java.util.concurrent.ExecutorService) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Before(org.junit.Before) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Test(org.junit.Test)

Example 92 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class TestHdfsCloudBackupRestore method testConfigBackupOnly.

protected void testConfigBackupOnly(String configName, String collectionName) throws Exception {
    String backupName = "configonlybackup";
    CloudSolrClient solrClient = cluster.getSolrClient();
    CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collectionName, backupName).setRepositoryName(getBackupRepoName()).setIndexBackupStrategy(CollectionAdminParams.NO_INDEX_BACKUP_STRATEGY);
    backup.process(solrClient);
    Map<String, String> params = new HashMap<>();
    params.put("location", "/backup");
    params.put("solr.hdfs.home", hdfsUri + "/solr");
    HdfsBackupRepository repo = new HdfsBackupRepository();
    repo.init(new NamedList<>(params));
    BackupManager mgr = new BackupManager(repo, solrClient.getZkStateReader());
    URI baseLoc = repo.createURI("/backup");
    Properties props = mgr.readBackupProperties(baseLoc, backupName);
    assertNotNull(props);
    assertEquals(collectionName, props.getProperty(COLLECTION_NAME_PROP));
    assertEquals(backupName, props.getProperty(BACKUP_NAME_PROP));
    assertEquals(configName, props.getProperty(COLL_CONF));
    DocCollection collectionState = mgr.readCollectionState(baseLoc, backupName, collectionName);
    assertNotNull(collectionState);
    assertEquals(collectionName, collectionState.getName());
    URI configDirLoc = repo.resolve(baseLoc, backupName, ZK_STATE_DIR, CONFIG_STATE_DIR, configName);
    assertTrue(repo.exists(configDirLoc));
    Collection<String> expected = Arrays.asList(BACKUP_PROPS_FILE, ZK_STATE_DIR);
    URI backupLoc = repo.resolve(baseLoc, backupName);
    String[] dirs = repo.listAll(backupLoc);
    for (String d : dirs) {
        assertTrue(expected.contains(d));
    }
}
Also used : HashMap(java.util.HashMap) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) HdfsBackupRepository(org.apache.solr.core.backup.repository.HdfsBackupRepository) Properties(java.util.Properties) BackupManager(org.apache.solr.core.backup.BackupManager) URI(java.net.URI) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 93 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class TestLeaderElectionWithEmptyReplica method test.

@Test
public void test() throws Exception {
    CloudSolrClient solrClient = cluster.getSolrClient();
    solrClient.setDefaultCollection(COLLECTION_NAME);
    for (int i = 0; i < 10; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", String.valueOf(i));
        solrClient.add(doc);
    }
    solrClient.commit();
    // find the leader node
    Replica replica = solrClient.getZkStateReader().getLeaderRetry(COLLECTION_NAME, "shard1");
    JettySolrRunner replicaJetty = null;
    List<JettySolrRunner> jettySolrRunners = cluster.getJettySolrRunners();
    for (JettySolrRunner jettySolrRunner : jettySolrRunners) {
        int port = jettySolrRunner.getBaseUrl().getPort();
        if (replica.getStr(BASE_URL_PROP).contains(":" + port)) {
            replicaJetty = jettySolrRunner;
            break;
        }
    }
    // kill the leader
    ChaosMonkey.kill(replicaJetty);
    // add a replica (asynchronously)
    CollectionAdminRequest.AddReplica addReplica = CollectionAdminRequest.addReplicaToShard(COLLECTION_NAME, "shard1");
    String asyncId = addReplica.processAsync(solrClient);
    // wait a bit
    Thread.sleep(1000);
    // bring the old leader node back up
    ChaosMonkey.start(replicaJetty);
    // wait until everyone is active
    solrClient.waitForState(COLLECTION_NAME, DEFAULT_TIMEOUT, TimeUnit.SECONDS, (n, c) -> DocCollection.isFullyActive(n, c, 1, 2));
    // now query each replica and check for consistency
    assertConsistentReplicas(solrClient, solrClient.getZkStateReader().getClusterState().getSlice(COLLECTION_NAME, "shard1"));
    // sanity check that documents still exist
    QueryResponse response = solrClient.query(new SolrQuery("*:*"));
    assertEquals("Indexed documents not found", 10, response.getResults().getNumFound());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Test(org.junit.Test)

Example 94 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class TestSegmentSorting method createCollection.

@Before
public void createCollection() throws Exception {
    final String collectionName = testName.getMethodName();
    final CloudSolrClient cloudSolrClient = cluster.getSolrClient();
    final Map<String, String> collectionProperties = new HashMap<>();
    collectionProperties.put(CoreDescriptor.CORE_CONFIG, "solrconfig-sortingmergepolicyfactory.xml");
    CollectionAdminRequest.Create cmd = CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR).setProperties(collectionProperties);
    if (random().nextBoolean()) {
        assertTrue(cmd.process(cloudSolrClient).isSuccess());
    } else {
        // async
        assertEquals(RequestStatusState.COMPLETED, cmd.processAndWait(cloudSolrClient, 30));
    }
    ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
    cloudSolrClient.setDefaultCollection(collectionName);
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HashMap(java.util.HashMap) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Before(org.junit.Before)

Example 95 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class TestMiniSolrCloudCluster method testCollectionCreateWithoutCoresThenDelete.

@Test
public void testCollectionCreateWithoutCoresThenDelete() throws Exception {
    final String collectionName = "testSolrCloudCollectionWithoutCores";
    final MiniSolrCloudCluster miniCluster = createMiniSolrCloudCluster();
    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
    try {
        assertNotNull(miniCluster.getZkServer());
        assertFalse(miniCluster.getJettySolrRunners().isEmpty());
        // create collection
        final String asyncId = (random().nextBoolean() ? null : "asyncId(" + collectionName + ".create)=" + random().nextInt());
        createCollection(miniCluster, collectionName, OverseerCollectionMessageHandler.CREATE_NODE_SET_EMPTY, asyncId, null, null);
        try (SolrZkClient zkClient = new SolrZkClient(miniCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
            ZkStateReader zkStateReader = new ZkStateReader(zkClient)) {
            zkStateReader.createClusterStateWatchersAndUpdate();
            // wait for collection to appear
            AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
            // check the collection's corelessness
            {
                int coreCount = 0;
                for (Map.Entry<String, Slice> entry : zkStateReader.getClusterState().getSlicesMap(collectionName).entrySet()) {
                    coreCount += entry.getValue().getReplicasMap().entrySet().size();
                }
                assertEquals(0, coreCount);
            }
        }
    } finally {
        miniCluster.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Test(org.junit.Test)

Aggregations

CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)134 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)38 SolrQuery (org.apache.solr.client.solrj.SolrQuery)29 HashMap (java.util.HashMap)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)25 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)24 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)24 Slice (org.apache.solr.common.cloud.Slice)24 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)22 List (java.util.List)21 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)20 Map (java.util.Map)19 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)19 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)19 NamedList (org.apache.solr.common.util.NamedList)18 Replica (org.apache.solr.common.cloud.Replica)17 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 SolrRequest (org.apache.solr.client.solrj.SolrRequest)15 DocCollection (org.apache.solr.common.cloud.DocCollection)14