/* ****************************************************************************
*
* setWriteConcern -
*/
bool setWriteConcern
(
  DBClientBase*        connection,
  const WriteConcern&  wc,
  std::string*         err
)
{
  LM_T(LmtMongo, ("setWritteConcern(): '%d'", wc.nodes()));

  try
  {
    connection->setWriteConcern(wc);
    LM_I(("Database Operation Successful (setWriteConcern: %d)", wc.nodes()));
  }
  catch (const std::exception &e)
  {
    // FIXME: include wc.nodes() in the output message, + operator doesn't work with integers
    std::string msg = std::string("setWritteConcern(): ") + /*wc.nodes() +*/
      " - exception: " + e.what();
    *err = "Database Error (" + msg + ")";
    LM_E((err->c_str()));
    return false;
  }
  catch (...)
  {
    // FIXME: include wc.nodes() in the output message, + operator doesn't work with integers
    std::string msg = std::string("setWritteConcern(): ") + /*wc.nodes() + */
      " - exception: generic";
    *err = "Database Error (" + msg + ")";
    LM_E((err->c_str()));
    return false;
  }

  return true;
}
    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, NeedsGLE) {
        WriteConcern wc;
        ASSERT_TRUE(wc.requiresConfirmation());

        wc.nodes(0);
        ASSERT_FALSE(wc.requiresConfirmation());

        wc.nodes(3);
        ASSERT_TRUE(wc.requiresConfirmation());
    }
 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);
    }
    TEST(WriteConcern, DefaultToBSON) {
        BSONObj result;

        WriteConcern wc;
        ASSERT_EQUALS(wc.nodes(), 1);
        result = wc.obj();
        ASSERT_FALSE(result.hasField("w"));
        ASSERT_FALSE(result.hasField("j"));
        ASSERT_FALSE(result.hasField("fsync"));
        ASSERT_FALSE(result.hasField("wtimeout"));
    }