TEST(WriteConcern, NodesString) { BSONObj result; WriteConcern wc; wc.nodes(3); ASSERT_FALSE(wc.hasMode()); ASSERT_EQUALS(wc.nodes(), 3); result = wc.obj(); ASSERT_TRUE(result.hasField("w")); ASSERT_EQUALS(result["w"].Int(), 3); wc.mode(WriteConcern::kMajority); ASSERT_TRUE(wc.hasMode()); ASSERT_EQUALS(wc.mode(), string(WriteConcern::kMajority)); result = wc.obj(); ASSERT_TRUE(result.hasField("w")); ASSERT_EQUALS(result["w"].String(), string(WriteConcern::kMajority)); wc.nodes(5); ASSERT_FALSE(wc.hasMode()); ASSERT_EQUALS(wc.nodes(), 5); result = wc.obj(); ASSERT_TRUE(result.hasField("w")); ASSERT_EQUALS(result["w"].Int(), 5); }
TEST(WriteConcern, Defaults) { WriteConcern wc; ASSERT_FALSE(wc.hasMode()); ASSERT_EQUALS(wc.nodes(), 1); ASSERT_FALSE(wc.journal()); ASSERT_FALSE(wc.fsync()); ASSERT_EQUALS(wc.timeout(), 0); }
TEST(WriteConcern, Chain) { WriteConcern wc = WriteConcern().nodes(2).journal(true); ASSERT_EQUALS(wc.nodes(), 2); ASSERT_FALSE(wc.hasMode()); ASSERT_TRUE(wc.journal()); // should be defaults ASSERT_FALSE(wc.fsync()); ASSERT_EQUALS(wc.timeout(), 0); }