|
24 | 24 | import org.testng.annotations.Test; |
25 | 25 |
|
26 | 26 | import java.io.IOException; |
| 27 | +import java.net.UnknownHostException; |
27 | 28 |
|
28 | 29 | public class MongoTest extends TestCase { |
29 | 30 |
|
@@ -53,6 +54,31 @@ public void testClose_shouldNotReturnUntilCleanupThreadIsFinished() throws Excep |
53 | 54 | assertFalse(mongo._cleaner.isAlive()); |
54 | 55 | } |
55 | 56 |
|
| 57 | + @SuppressWarnings("deprecation") |
| 58 | + @Test |
| 59 | + public void testApplyOptions() throws UnknownHostException { |
| 60 | + MongoOptions options = new MongoOptions(); |
| 61 | + |
| 62 | + // test defaults |
| 63 | + Mongo m = new Mongo("localhost", options); |
| 64 | + assertEquals(ReadPreference.primary(), m.getReadPreference()); |
| 65 | + assertEquals(WriteConcern.NORMAL, m.getWriteConcern()); |
| 66 | + assertEquals(0, m.getOptions() & Bytes.QUERYOPTION_SLAVEOK); |
| 67 | + m.close(); |
| 68 | + |
| 69 | + // test setting options |
| 70 | + options.setReadPreference(ReadPreference.nearest()); |
| 71 | + options.slaveOk = true; |
| 72 | + options.safe = true; |
| 73 | + |
| 74 | + m = new Mongo("localhost", options); |
| 75 | + assertEquals(ReadPreference.nearest(), m.getReadPreference()); |
| 76 | + assertEquals(WriteConcern.SAFE, m.getWriteConcern()); |
| 77 | + assertEquals(Bytes.QUERYOPTION_SLAVEOK, m.getOptions() & Bytes.QUERYOPTION_SLAVEOK); |
| 78 | + m.close(); |
| 79 | + |
| 80 | + } |
| 81 | + |
56 | 82 | @AfterTest |
57 | 83 | public void tearDown() { |
58 | 84 | Mongo.cleanerIntervalMS = _originalCleanerIntervalMs; |
|
0 commit comments