@Test @SuppressWarnings("deprecation") public void testGetterSetters() throws Exception { MongoOptions options = new MongoOptions(); options.setConnectionsPerHost(100); options.setThreadsAllowedToBlockForConnectionMultiplier(101); options.setMaxWaitTime(102); options.setConnectTimeout(103); options.setSocketTimeout(104); options.setSocketKeepAlive(true); options.setSafe(true); options.setW(106); options.setWtimeout(107); options.setFsync(true); options.setJ(false); options.setDbDecoderFactory(null); options.setDbEncoderFactory(null); options.setDescription("very cool"); options.setReadPreference(ReadPreference.secondary()); options.setSocketFactory(SSLSocketFactory.getDefault()); options.setAlwaysUseMBeans(true); options.setCursorFinalizerEnabled(false); options.requiredReplicaSetName = "set1"; assertEquals(options.getConnectionsPerHost(), 100); assertEquals(options.getThreadsAllowedToBlockForConnectionMultiplier(), 101); assertEquals(options.getMaxWaitTime(), 102); assertEquals(options.getConnectTimeout(), 103); assertEquals(options.getSocketTimeout(), 104); assertEquals(options.isSocketKeepAlive(), true); assertEquals(options.isSafe(), true); assertEquals(options.getW(), 106); assertEquals(options.getWtimeout(), 107); assertEquals(options.isFsync(), true); assertEquals(options.isJ(), false); assertEquals(options.getDbDecoderFactory(), null); assertEquals(options.getDbEncoderFactory(), null); assertEquals(options.getDescription(), "very cool"); assertEquals(options.getReadPreference(), ReadPreference.secondary()); assertEquals(options.isAlwaysUseMBeans(), true); assertEquals(options.getSocketFactory(), options.socketFactory); assertEquals(options.isCursorFinalizerEnabled(), false); assertEquals(options.getRequiredReplicaSetName(), "set1"); }
private void init(String dbPrefix) { try { mongoReplicaProps = new ArrayList<ServerAddress>(); // mongoReplicaProps.add(new ServerAddress("mongodb1.qa.sg1.hike.in", 27017)); mongoReplicaProps.add(new ServerAddress("10.0.1.141", 27017)); mongoReplicaProps.add(new ServerAddress("10.0.1.141", 27017)); MongoOptions options = new MongoOptions(); options.autoConnectRetry = true; options.readPreference = ReadPreference.primaryPreferred(); options.setThreadsAllowedToBlockForConnectionMultiplier(50); options.setConnectionsPerHost(100); options.slaveOk = true; mongo = new Mongo(mongoReplicaProps, options); userDB = mongo.getDB("userdb"); } catch (Exception e) { e.printStackTrace(); } }