@Test public void testImportAttachment() throws Exception { logger.debug("*** testImportAttachment ***"); byte[] content = copyToBytesFromClasspath( "/test/elasticsearch/plugin/river/mongodb/gridfs/test-attachment.html"); logger.debug("Content in bytes: {}", content.length); GridFS gridFS = new GridFS(mongoDB); GridFSInputFile in = gridFS.createFile(content); in.setFilename("test-attachment.html"); in.setContentType("text/html"); in.save(); in.validate(); String id = in.getId().toString(); logger.debug("GridFS in: {}", in); logger.debug("Document created with id: {}", id); GridFSDBFile out = gridFS.findOne(in.getFilename()); logger.debug("GridFS from findOne: {}", out); out = gridFS.findOne(new ObjectId(id)); logger.debug("GridFS from findOne: {}", out); Assert.assertEquals(out.getId(), in.getId()); Thread.sleep(wait); refreshIndex(); CountResponse countResponse = getNode().client().count(countRequest(getIndex())).actionGet(); logger.debug("Index total count: {}", countResponse.getCount()); assertThat(countResponse.getCount(), equalTo(1l)); countResponse = getNode().client().count(countRequest(getIndex()).query(fieldQuery("_id", id))).actionGet(); logger.debug("Index count for id {}: {}", id, countResponse.getCount()); assertThat(countResponse.getCount(), equalTo(1l)); SearchResponse response = getNode() .client() .prepareSearch(getIndex()) .setQuery(QueryBuilders.queryString("Aliquam")) .execute() .actionGet(); logger.debug("SearchResponse {}", response.toString()); long totalHits = response.getHits().getTotalHits(); logger.debug("TotalHits: {}", totalHits); assertThat(totalHits, equalTo(1l)); gridFS.remove(new ObjectId(id)); Thread.sleep(wait); refreshIndex(); countResponse = getNode().client().count(countRequest(getIndex()).query(fieldQuery("_id", id))).actionGet(); logger.debug("Count after delete request: {}", countResponse.getCount()); assertThat(countResponse.getCount(), equalTo(0L)); }
@Test public void testImportAttachment() throws Exception { logger.debug("*** testImportAttachment ***"); try { // createDatabase(); byte[] content = copyToBytesFromClasspath(TEST_ATTACHMENT_HTML); logger.debug("Content in bytes: {}", content.length); GridFS gridFS = new GridFS(mongoDB); GridFSInputFile in = gridFS.createFile(content); in.setFilename("test-attachment.html"); in.setContentType("text/html"); in.save(); in.validate(); String id = in.getId().toString(); logger.debug("GridFS in: {}", in); logger.debug("Document created with id: {}", id); GridFSDBFile out = gridFS.findOne(in.getFilename()); logger.debug("GridFS from findOne: {}", out); out = gridFS.findOne(new ObjectId(id)); logger.debug("GridFS from findOne: {}", out); Assert.assertEquals(out.getId(), in.getId()); Thread.sleep(wait); refreshIndex(); CountResponse countResponse = getNode().client().count(countRequest(getIndex())).actionGet(); logger.debug("Index total count: {}", countResponse.getCount()); assertThat(countResponse.getCount(), equalTo(1l)); GetResponse getResponse = getNode().client().get(getRequest(getIndex()).id(id)).get(); logger.debug("Get request for id {}: {}", id, getResponse.isExists()); assertThat(getResponse.isExists(), equalTo(true)); // countResponse = // getNode().client().count(countRequest(getIndex()).query(fieldQuery("_id", // id))).actionGet(); // logger.debug("Index count for id {}: {}", id, countResponse.getCount()); // assertThat(countResponse.getCount(), equalTo(1l)); SearchResponse response = getNode() .client() .prepareSearch(getIndex()) .setQuery(QueryBuilders.queryString("Aliquam")) .execute() .actionGet(); logger.debug("SearchResponse {}", response.toString()); long totalHits = response.getHits().getTotalHits(); logger.debug("TotalHits: {}", totalHits); assertThat(totalHits, equalTo(1l)); gridFS.remove(new ObjectId(id)); Thread.sleep(wait); refreshIndex(); getResponse = getNode().client().get(getRequest(getIndex()).id(id)).get(); logger.debug("Get request for id {}: {}", id, getResponse.isExists()); assertThat(getResponse.isExists(), equalTo(false)); // countResponse = // getNode().client().count(countRequest(getIndex()).query(fieldQuery("_id", // id))).actionGet(); // logger.debug("Count after delete request: {}", countResponse.getCount()); // assertThat(countResponse.getCount(), equalTo(0L)); } catch (Throwable t) { logger.error("testImportAttachment failed.", t); Assert.fail("testImportAttachment failed", t); } finally { // cleanUp(); } }