@Test @SuppressWarnings("deprecation") public void testGetWriteConcern() { MongoOptions options = new MongoOptions(); assertEquals(WriteConcern.NORMAL, options.getWriteConcern()); options.reset(); options.safe = true; assertEquals(WriteConcern.SAFE, options.getWriteConcern()); options.reset(); options.w = 3; assertEquals(new WriteConcern(3), options.getWriteConcern()); options.reset(); options.wtimeout = 3000; assertEquals( WriteConcern.ACKNOWLEDGED.withWTimeout(3000, TimeUnit.MILLISECONDS), options.getWriteConcern()); options.reset(); options.fsync = true; assertEquals(WriteConcern.ACKNOWLEDGED.withFsync(true), options.getWriteConcern()); options.reset(); options.j = true; assertEquals(WriteConcern.ACKNOWLEDGED.withJournal(true), options.getWriteConcern()); }
@Test public void testMongoSingletonWithPropertyPlaceHolders() throws Exception { assertTrue(ctx.containsBean("mongo")); MongoFactoryBean mfb = (MongoFactoryBean) ctx.getBean("&mongo"); String host = (String) getField(mfb, "host"); Integer port = (Integer) getField(mfb, "port"); assertEquals("127.0.0.1", host); assertEquals(new Integer(27017), port); Mongo mongo = mfb.getObject(); MongoOptions mongoOpts = mongo.getMongoOptions(); assertEquals(8, mongoOpts.connectionsPerHost); assertEquals(1000, mongoOpts.connectTimeout); assertEquals(1500, mongoOpts.maxWaitTime); assertEquals(true, mongoOpts.autoConnectRetry); assertEquals(1500, mongoOpts.socketTimeout); assertEquals(4, mongoOpts.threadsAllowedToBlockForConnectionMultiplier); assertEquals(true, mongoOpts.socketKeepAlive); assertEquals(true, mongoOpts.fsync); assertEquals(true, mongoOpts.slaveOk); assertEquals(1, mongoOpts.getWriteConcern().getW()); assertEquals(0, mongoOpts.getWriteConcern().getWtimeout()); assertEquals(true, mongoOpts.getWriteConcern().fsync()); }