@Test
  @SuppressWarnings("deprecation")
  public void testToClientOptions() throws UnknownHostException {
    MongoOptions options = new MongoOptions();
    options.description = "my client";
    options.fsync = true;
    options.readPreference = ReadPreference.secondary();
    options.requiredReplicaSetName = "test";
    options.cursorFinalizerEnabled = false;
    options.alwaysUseMBeans = true;
    options.connectTimeout = 100;
    options.maxWaitTime = 500;
    options.socketKeepAlive = true;
    options.threadsAllowedToBlockForConnectionMultiplier = 10;

    MongoClientOptions clientOptions = options.toClientOptions();

    assertEquals(options.requiredReplicaSetName, clientOptions.getRequiredReplicaSetName());
    assertEquals(options.description, clientOptions.getDescription());
    assertEquals(WriteConcern.ACKNOWLEDGED.withFsync(true), clientOptions.getWriteConcern());
    assertEquals(0, clientOptions.getMinConnectionsPerHost());
    assertEquals(10, clientOptions.getConnectionsPerHost());
    assertEquals(100, clientOptions.getConnectTimeout());
    assertEquals(500, clientOptions.getMaxWaitTime());
    assertEquals(ReadPreference.secondary(), clientOptions.getReadPreference());
    assertEquals(10, clientOptions.getThreadsAllowedToBlockForConnectionMultiplier());
    assertTrue(clientOptions.isSocketKeepAlive());
    assertFalse(clientOptions.isSslEnabled());
    assertEquals(options.dbDecoderFactory, clientOptions.getDbDecoderFactory());
    assertEquals(options.dbEncoderFactory, clientOptions.getDbEncoderFactory());
    assertEquals(15, clientOptions.getLocalThreshold());
    assertTrue(clientOptions.isAlwaysUseMBeans());
    assertFalse(clientOptions.isCursorFinalizerEnabled());
  }
  /**
   * Method invoked when a {@link MongoSession} needs to be created.
   *
   * @param username the username to use for authentication. NOTE: Please use a dummy user if you
   *     have disabled Mongo authentication
   * @param password the password to use for authentication. NOTE: Please use a dummy password if
   *     you have disabled Mongo authentication
   * @param database Name of the database
   * @return the newly created {@link MongoSession}
   * @throws org.mule.api.ConnectionException
   */
  @Connect
  public void connect(
      @ConnectionKey String username,
      @Password String password,
      @Optional @Default("test") String database)
      throws ConnectionException {
    DB db = null;
    try {
      MongoOptions options = new MongoOptions();

      if (connectionsPerHost != null) {
        options.connectionsPerHost = connectionsPerHost;
      }
      if (threadsAllowedToBlockForConnectionMultiplier != null) {
        options.threadsAllowedToBlockForConnectionMultiplier =
            threadsAllowedToBlockForConnectionMultiplier;
      }
      if (maxWaitTime != null) {
        options.maxWaitTime = maxWaitTime;
      }
      if (connectTimeout != null) {
        options.connectTimeout = connectTimeout;
      }
      if (socketTimeout != null) {
        options.socketTimeout = socketTimeout;
      }
      if (autoConnectRetry != null) {
        options.autoConnectRetry = autoConnectRetry;
      }
      if (slaveOk != null) {
        options.slaveOk = slaveOk;
      }
      if (safe != null) {
        options.safe = safe;
      }
      if (w != null) {
        options.w = w;
      }
      if (wtimeout != null) {
        options.wtimeout = wtimeout;
      }
      if (fsync != null) {
        options.fsync = fsync;
      }
      if (database != null) {
        this.database = database;
      }

      mongo = getOrCreateMongoInstance(host, port, options);
      db = getDatabase(mongo, username, password, database);
    } catch (MongoException me) {
      throw new ConnectionException(ConnectionExceptionCode.UNKNOWN, null, me.getMessage());
    } catch (UnknownHostException e) {
      throw new ConnectionException(ConnectionExceptionCode.UNKNOWN_HOST, null, e.getMessage());
    }
    this.client = new MongoClientImpl(db);
  }
 static {
   updaterIntervalMS =
       Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalMS", "5000"));
   slaveAcceptableLatencyMS =
       Integer.parseInt(System.getProperty("com.mongodb.slaveAcceptableLatencyMS", "15"));
   inetAddrCacheMS = Integer.parseInt(System.getProperty("com.mongodb.inetAddrCacheMS", "300000"));
   _mongoOptions.connectTimeout =
       Integer.parseInt(System.getProperty("com.mongodb.updaterConnectTimeoutMS", "20000"));
   _mongoOptions.socketTimeout =
       Integer.parseInt(System.getProperty("com.mongodb.updaterSocketTimeoutMS", "20000"));
 }
 static {
   updaterIntervalMS =
       Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalMS", "5000"));
   updaterIntervalNoMasterMS =
       Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalNoMasterMS", "10"));
   slaveAcceptableLatencyMS =
       Integer.parseInt(System.getProperty("com.mongodb.slaveAcceptableLatencyMS", "15"));
   inetAddrCacheMS = Integer.parseInt(System.getProperty("com.mongodb.inetAddrCacheMS", "300000"));
   latencySmoothFactor =
       Float.parseFloat(System.getProperty("com.mongodb.latencySmoothFactor", "4"));
   _mongoOptionsDefaults.connectTimeout =
       Integer.parseInt(System.getProperty("com.mongodb.updaterConnectTimeoutMS", "20000"));
   _mongoOptionsDefaults.socketTimeout =
       Integer.parseInt(System.getProperty("com.mongodb.updaterSocketTimeoutMS", "20000"));
 }
  @Test
  @SuppressWarnings("deprecation")
  public void testCopy() throws Exception {

    MongoOptions options = new MongoOptions();

    options.connectionsPerHost = 100;
    options.threadsAllowedToBlockForConnectionMultiplier = 101;
    options.maxWaitTime = 102;
    options.connectTimeout = 103;
    options.socketTimeout = 104;
    options.socketKeepAlive = true;
    options.safe = true;
    options.w = 106;
    options.wtimeout = 107;
    options.fsync = true;
    options.j = false;
    options.dbDecoderFactory = null;
    options.dbEncoderFactory = null;
    options.description = "cool";
    options.readPreference = ReadPreference.secondary();
    options.cursorFinalizerEnabled = true;
    options.socketFactory = SSLSocketFactory.getDefault();
    options.alwaysUseMBeans = true;
    options.requiredReplicaSetName = "set1";

    MongoOptions copy = options.copy();
    assertEquals(options.connectionsPerHost, copy.connectionsPerHost);
    assertEquals(
        options.threadsAllowedToBlockForConnectionMultiplier,
        copy.threadsAllowedToBlockForConnectionMultiplier);
    assertEquals(options.maxWaitTime, copy.maxWaitTime);
    assertEquals(options.connectTimeout, copy.connectTimeout);
    assertEquals(options.socketTimeout, copy.socketTimeout);
    assertEquals(options.socketKeepAlive, copy.socketKeepAlive);
    assertEquals(options.safe, copy.safe);
    assertEquals(options.w, copy.w);
    assertEquals(options.wtimeout, copy.wtimeout);
    assertEquals(options.fsync, copy.fsync);
    assertEquals(options.j, copy.j);
    assertEquals(options.dbDecoderFactory, copy.dbDecoderFactory);
    assertEquals(options.dbEncoderFactory, copy.dbEncoderFactory);
    assertEquals(options.description, copy.description);
    assertEquals(options.readPreference, copy.readPreference);
    assertEquals(options.alwaysUseMBeans, copy.alwaysUseMBeans);
    assertEquals(options.socketFactory, copy.socketFactory);
    assertEquals(options.requiredReplicaSetName, copy.requiredReplicaSetName);
  }