public static MongoClient getMongo() throws UnknownHostException, MongoException { return new MongoClient(getMongoServer()); } }
private void removeTestDBs() throws UnknownHostException { log.info("Removing test databases"); MongoClient mongo = TestHelper.getMongo(); for (String dbName : mongo.listDatabaseNames()) { if (dbName.startsWith(TestHelper.TEST_DATABASE_NAME)) { mongo.getDatabase(dbName).drop(); } } }
public static void init() throws IOException { MongoClient mongo = TestHelper.getMongo(); mongo.dropDatabase(TestHelper.TEST_DATABASE_NAME); directory = new DistributedDirectory(new MongoDirectory(mongo, TestHelper.TEST_DATABASE_NAME, STORAGE_TEST_INDEX, false)); }
public MongoConfig getTestMongoConfig() throws PropertyException { HashMap<String, String> settings = new HashMap<>(); settings.put(MongoConfig.DATABASE_NAME, TestHelper.TEST_DATABASE_NAME); settings.put(MongoConfig.MONGO_HOSTS, TestHelper.getMongoServer()); MongoConfig mongoConfig = new MongoConfig(new FakePropertiesReader("test", settings)); return mongoConfig; }
@BeforeClass public static void cleanDatabaseAndInit() throws Exception { MongoClient mongo = TestHelper.getMongo(); mongo.dropDatabase(TestHelper.TEST_DATABASE_NAME); directory = new DistributedDirectory(new MongoDirectory(mongo, TestHelper.TEST_DATABASE_NAME, STORAGE_TEST_INDEX, false)); StandardAnalyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter w = new IndexWriter(directory, config); addDoc(w, "Random perl Title that is long", "id-1"); addDoc(w, "Random java Title that is long", "id-1"); addDoc(w, "MongoDB is awesome", "id-2"); addDoc(w, "This is a long title with nothing interesting", "id-3"); addDoc(w, "Java is awesome", "id-4"); addDoc(w, "Really big fish", "id-5"); w.commit(); w.close(); }
@Test public void test3Api() throws Exception { String hostName = TestHelper.getMongoServer(); String databaseName = TestHelper.TEST_DATABASE_NAME;