use of org.elasticsearch.indices.IndexMissingException in project elasticsearch-river-couchdb by elastic.
the class CouchdbRiverIntegrationTest method testScriptingParentChild_51.
/**
* Test case for #51: https://github.com/elasticsearch/elasticsearch-river-couchdb/issues/51
*/
@Test
public void testScriptingParentChild_51() throws IOException, InterruptedException, ExecutionException {
prepareCreate(getDbName()).addMapping("region", jsonBuilder().startObject().startObject("region").endObject().endObject().string()).addMapping("campus", jsonBuilder().startObject().startObject("campus").startObject("_parent").field("type", "region").endObject().endObject().endObject().string()).get();
launchTest(jsonBuilder().startObject().field("type", "couchdb").startObject("couchdb").field("script", "ctx._type = ctx.doc.type; if (ctx._type == 'campus') { ctx._parent = ctx.doc.parent_id; }").endObject().endObject(), 0, new InjectorHook() {
@Override
public void inject() {
try {
putDocument(getDbName(), "1", "type", "region", "name", "bretagne");
putDocument(getDbName(), "2", "type", "campus", "name", "enib", "parent_id", "1");
} catch (IOException e) {
logger.error("Error while injecting documents");
}
}
});
// Check that docs are indexed by the river
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() == 2;
} catch (IndexMissingException e) {
return false;
}
}
}, 1, TimeUnit.MINUTES), equalTo(true));
SearchResponse response = client().prepareSearch(getDbName()).setQuery(QueryBuilders.hasChildQuery("campus", QueryBuilders.matchQuery("name", "enib"))).get();
assertThat(response.getHits().getTotalHits(), is(1L));
assertThat(response.getHits().getAt(0).getType(), is("region"));
assertThat(response.getHits().getAt(0).getId(), is("1"));
}
use of org.elasticsearch.indices.IndexMissingException in project elasticsearch-river-couchdb by elastic.
the class CouchdbRiverIntegrationTest method testCreateCouchdbDatabaseWhileRunning_17.
/**
* Test case for #17: https://github.com/elasticsearch/elasticsearch-river-couchdb/issues/17
*/
@Test
public void testCreateCouchdbDatabaseWhileRunning_17() throws IOException, InterruptedException {
final int nbDocs = between(50, 300);
logger.info(" -> Checking couchdb running");
CouchDBClient.checkCouchDbRunning();
logger.info(" -> Create index");
try {
createIndex(getDbName());
} catch (IndexAlreadyExistsException e) {
// No worries. We already created the index before
}
logger.info(" -> Create river");
index("_river", getDbName(), "_meta", jsonBuilder().startObject().field("type", "couchdb").endObject());
// Check that the river is started
assertThat(awaitBusy(new Predicate<Object>() {
public boolean apply(Object obj) {
try {
refresh();
GetResponse response = get("_river", getDbName(), "_status");
return response.isExists();
} catch (IndexMissingException e) {
return false;
}
}
}, 5, TimeUnit.SECONDS), equalTo(true));
logger.info(" -> Creating test database [{}]", getDbName());
CouchDBClient.dropAndCreateTestDatabase(getDbName());
logger.info(" -> Inserting [{}] docs in couchdb", nbDocs);
for (int i = 0; i < nbDocs; i++) {
CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
}
// Check that docs are still processed by the river
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() == nbDocs;
} catch (IndexMissingException e) {
return false;
}
}
}, 1, TimeUnit.MINUTES), equalTo(true));
}
use of org.elasticsearch.indices.IndexMissingException in project elasticsearch-river-couchdb by elastic.
the class CouchdbRiverIntegrationTest method testClosingWhileIndexing_66.
/**
* Test case for #66: https://github.com/elasticsearch/elasticsearch-river-couchdb/issues/66
*/
@Test
public void testClosingWhileIndexing_66() throws IOException, InterruptedException {
final int nbDocs = 10;
logger.info(" -> Checking couchdb running");
CouchDBClient.checkCouchDbRunning();
logger.info(" -> Creating test database [{}]", getDbName());
CouchDBClient.dropAndCreateTestDatabase(getDbName());
logger.info(" -> Inserting [{}] docs in couchdb", nbDocs);
for (int i = 0; i < nbDocs; i++) {
CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
}
logger.info(" -> Create index");
try {
createIndex(getDbName());
} catch (IndexAlreadyExistsException e) {
// No worries. We already created the index before
}
logger.info(" -> Create river");
index("_river", getDbName(), "_meta", jsonBuilder().startObject().field("type", "couchdb").startObject("couchdb").field("script", "for (int x = 0; x < 10000000; x++) { x*x*x } ;").endObject().startObject("index").field("flush_interval", "100ms").endObject().endObject());
// Check that docs are indexed by the river
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() == nbDocs;
} catch (IndexMissingException e) {
return false;
}
}
}, 1, TimeUnit.MINUTES), equalTo(true));
logger.info(" -> Inserting [{}] docs in couchdb", nbDocs);
for (int i = nbDocs; i < 2 * nbDocs; i++) {
CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
}
// Check that docs are still processed by the river
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() > nbDocs;
} catch (IndexMissingException e) {
return false;
}
}
}, 10, TimeUnit.SECONDS), equalTo(true));
logger.info(" -> Remove river while injecting");
client().prepareDelete("_river", getDbName(), "_meta").get();
logger.info(" -> Inserting [{}] docs in couchdb", nbDocs);
for (int i = 2 * nbDocs; i < 3 * nbDocs; i++) {
CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
}
// Check that docs are indexed by the river
boolean foundAllDocs = 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() == 3 * nbDocs;
} catch (IndexMissingException e) {
return false;
}
}
}, 10, TimeUnit.SECONDS);
// We should not have 30 documents at the end as we removed the river immediately after having
// injecting 10 more docs in couchdb
assertThat("We should not have 30 documents as the river is supposed to have been stopped!", foundAllDocs, is(false));
// We expect seeing a line in logs like:
// [WARN ][org.elasticsearch.river.couchdb] [node_0] [couchdb][elasticsearch_couch_test_test_closing_while_indexing_66] river was closing while trying to index document [elasticsearch_couch_test_test_closing_while_indexing_66/elasticsearch_couch_test_test_closing_while_indexing_66/11]. Operation skipped.
}
use of org.elasticsearch.indices.IndexMissingException in project elasticsearch-river-couchdb by elastic.
the class CouchdbRiverIntegrationTest method runAttachmentTest.
private void runAttachmentTest(boolean disabled) throws IOException, InterruptedException {
// Create the river
launchTest(jsonBuilder().startObject().field("type", "couchdb").startObject("couchdb").field("host", CouchDBClient.host).field("port", CouchDBClient.port).field("db", getDbName()).field("ignore_attachments", disabled).endObject().endObject(), 0, new InjectorHook() {
@Override
public void inject() {
try {
putDocumentWithAttachments(getDbName(), "1", new ImmutableList.Builder<String>().add("foo", "bar").build(), "text-in-english.txt", "God save the queen!", "text-in-french.txt", "Allons enfants !");
} catch (IOException e) {
logger.error("Error while injecting attachments");
}
}
});
// Check that docs are indexed by the river
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() == 1;
} catch (IndexMissingException e) {
return false;
}
}
}, 1, TimeUnit.MINUTES), equalTo(true));
SearchResponse response = client().prepareSearch(getDbName()).addField("_attachments.text-in-english.txt.content_type").addField("_attachments.text-in-french.txt.content_type").get();
assertThat(response.getHits().getAt(0).field("_attachments.text-in-english.txt.content_type"), disabled ? nullValue() : notNullValue());
assertThat(response.getHits().getAt(0).field("_attachments.text-in-french.txt.content_type"), disabled ? nullValue() : notNullValue());
if (!disabled) {
assertThat(response.getHits().getAt(0).field("_attachments.text-in-english.txt.content_type").getValue().toString(), is("text/plain"));
assertThat(response.getHits().getAt(0).field("_attachments.text-in-french.txt.content_type").getValue().toString(), is("text/plain"));
}
}
use of org.elasticsearch.indices.IndexMissingException in project titan by thinkaurelius.
the class ElasticSearchIndex method clearStorage.
@Override
public void clearStorage() throws StorageException {
try {
try {
client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();
// We wait for one second to let ES delete the river
Thread.sleep(1000);
} catch (IndexMissingException e) {
// Index does not exist... Fine
}
} catch (Exception e) {
throw new PermanentStorageException("Could not delete index " + indexName, e);
} finally {
close();
}
}
Aggregations