@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");
  }
Ejemplo n.º 2
0
  @SuppressWarnings("deprecation")
  @Test
  public void testApplyOptions() throws UnknownHostException {
    MongoOptions options = new MongoOptions();

    // test defaults
    Mongo m = new Mongo("localhost", options);
    assertEquals(ReadPreference.primary(), m.getReadPreference());
    assertEquals(WriteConcern.NORMAL, m.getWriteConcern());
    assertEquals(0, m.getOptions() & Bytes.QUERYOPTION_SLAVEOK);
    m.close();

    // test setting options
    options.setReadPreference(ReadPreference.nearest());
    options.slaveOk = true;
    options.safe = true;

    m = new Mongo("localhost", options);
    assertEquals(ReadPreference.nearest(), m.getReadPreference());
    assertEquals(WriteConcern.SAFE, m.getWriteConcern());
    assertEquals(Bytes.QUERYOPTION_SLAVEOK, m.getOptions() & Bytes.QUERYOPTION_SLAVEOK);
    m.close();
  }