@Test public void testRenameAttribute() throws Throwable { logger.debug("Start testRenameAttribute"); try { logger.debug("Create river {}", getRiver()); String script = "ctx.document.score2 = ctx.document.score; delete ctx.document.score;"; super.createRiver( "/test/elasticsearch/plugin/river/mongodb/script/test-mongodb-river-with-script.json", getRiver(), String.valueOf(getMongoPort1()), String.valueOf(getMongoPort2()), String.valueOf(getMongoPort3()), getDatabase(), getCollection(), script, getIndex(), getDatabase()); String mongoDocument = copyToStringFromClasspath( "/test/elasticsearch/plugin/river/mongodb/script/test-simple-mongodb-document.json"); DBObject dbObject = (DBObject) JSON.parse(mongoDocument); WriteResult result = mongoCollection.insert(dbObject); Thread.sleep(wait); String id = dbObject.get("_id").toString(); logger.info("WriteResult: {}", result.toString()); refreshIndex(); ActionFuture<IndicesExistsResponse> response = getNode().client().admin().indices().exists(new IndicesExistsRequest(getIndex())); assertThat(response.actionGet().isExists(), equalTo(true)); SearchResponse sr = getNode() .client() .prepareSearch(getIndex()) .setQuery(fieldQuery("_id", id)) .execute() .actionGet(); logger.debug("SearchResponse {}", sr.toString()); long totalHits = sr.getHits().getTotalHits(); logger.debug("TotalHits: {}", totalHits); assertThat(totalHits, equalTo(1l)); assertThat(sr.getHits().getHits()[0].sourceAsMap().containsKey("score2"), equalTo(true)); mongoCollection.remove(dbObject); } catch (Throwable t) { logger.error("testRenameAttribute failed.", t); t.printStackTrace(); throw t; } finally { super.deleteRiver(); super.deleteIndex(); } }
@Test public void testIgnoreScript() throws Throwable { logger.debug("Start testIgnoreScript"); try { logger.debug("Create river {}", getRiver()); String script = "ctx.ignore = true;"; super.createRiver( "/test/elasticsearch/plugin/river/mongodb/script/test-mongodb-river-with-script.json", getRiver(), String.valueOf(getMongoPort1()), String.valueOf(getMongoPort2()), String.valueOf(getMongoPort3()), getDatabase(), getCollection(), script, getIndex(), getDatabase()); String mongoDocument = copyToStringFromClasspath( "/test/elasticsearch/plugin/river/mongodb/script/test-simple-mongodb-document.json"); DBObject dbObject = (DBObject) JSON.parse(mongoDocument); WriteResult result = mongoCollection.insert(dbObject); Thread.sleep(wait); logger.info("WriteResult: {}", result.toString()); refreshIndex(); ActionFuture<IndicesExistsResponse> response = getNode().client().admin().indices().exists(new IndicesExistsRequest(getIndex())); assertThat(response.actionGet().isExists(), equalTo(true)); CountResponse countResponse = getNode().client().count(countRequest(getIndex())).actionGet(); logger.info("Document count: {}", countResponse.getCount()); assertThat(countResponse.getCount(), equalTo(0l)); mongoCollection.remove(dbObject); } catch (Throwable t) { logger.error("testIgnoreScript failed.", t); t.printStackTrace(); throw t; } finally { super.deleteRiver(); super.deleteIndex(); } }
@BeforeClass public void createDatabase() { logger.debug("createDatabase {}", getDatabase()); try { mongoDB = getMongo().getDB(getDatabase()); mongoDB.setWriteConcern(WriteConcern.REPLICAS_SAFE); super.createRiver( "/test/elasticsearch/plugin/river/mongodb/gridfs/test-gridfs-mongodb-river.json"); ActionFuture<IndicesExistsResponse> response = getNode().client().admin().indices().exists(new IndicesExistsRequest(getIndex())); assertThat(response.actionGet().isExists(), equalTo(true)); logger.info("Start createCollection"); mongoCollection = mongoDB.createCollection(getCollection(), null); Assert.assertNotNull(mongoCollection); } catch (Throwable t) { logger.error("createDatabase failed.", t); } }
@AfterClass public void cleanUp() { super.deleteRiver(); logger.info("Drop database " + mongoDB.getName()); mongoDB.dropDatabase(); }