Search in sources :

Example 6 with IndexAlreadyExistsException

use of org.elasticsearch.indices.IndexAlreadyExistsException in project elasticsearch-river-couchdb by elastic.

the class CouchdbRiverIntegrationTest method launchTest.

private void launchTest(XContentBuilder river, final Integer numDocs, InjectorHook injectorHook) throws IOException, InterruptedException {
    logger.info("  -> Checking couchdb running");
    CouchDBClient.checkCouchDbRunning();
    logger.info("  -> Creating test database [{}]", getDbName());
    CouchDBClient.dropAndCreateTestDatabase(getDbName());
    logger.info("  -> Put [{}] documents", numDocs);
    for (int i = 0; i < numDocs; i++) {
        CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
    }
    logger.info("  -> Put [{}] documents done", numDocs);
    if (injectorHook != null) {
        logger.info("  -> Injecting extra data");
        injectorHook.inject();
    }
    logger.info("  -> Create river");
    try {
        createIndex(getDbName());
    } catch (IndexAlreadyExistsException e) {
    // No worries. We already created the index before
    }
    index("_river", getDbName(), "_meta", river);
    logger.info("  -> Wait for some docs");
    assertThat(awaitBusy(new Predicate<Object>() {

        public boolean apply(Object obj) {
            try {
                refresh();
                SearchResponse response = client().prepareSearch(getDbName()).get();
                logger.info("  -> got {} docs in {} index", response.getHits().totalHits(), getDbName());
                return response.getHits().totalHits() == numDocs;
            } catch (IndexMissingException e) {
                return false;
            }
        }
    }, 1, TimeUnit.MINUTES), equalTo(true));
}
Also used : IndexAlreadyExistsException(org.elasticsearch.indices.IndexAlreadyExistsException) IndexMissingException(org.elasticsearch.indices.IndexMissingException) Predicate(org.elasticsearch.common.base.Predicate) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

IndexAlreadyExistsException (org.elasticsearch.indices.IndexAlreadyExistsException)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 Predicate (org.elasticsearch.common.base.Predicate)3 IndexMissingException (org.elasticsearch.indices.IndexMissingException)3 IOException (java.io.IOException)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 ElasticsearchIntegrationTest (org.elasticsearch.test.ElasticsearchIntegrationTest)2 Test (org.junit.Test)2 FeedException (com.rometools.rome.io.FeedException)1 MalformedURLException (java.net.MalformedURLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 PutMappingRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest)1 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)1 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1