void test_mongo_sync_cmd_custom (void) { mongo_sync_connection *c; bson *cmd; c = test_make_fake_sync_conn (-1, FALSE); cmd = bson_new (); bson_append_int32 (cmd, "getnonce", 1); bson_finish (cmd); ok (mongo_sync_cmd_custom (NULL, "test", cmd) == NULL, "mongo_sync_cmd_custom() fails with a NULL connection"); ok (mongo_sync_cmd_custom (c, NULL, cmd) == NULL, "mongo_sync_cmd_custom() fails with a NULL namespace"); ok (mongo_sync_cmd_custom (c, "test", cmd) == NULL, "mongo_sync_cmd_custom() fails with a bogus FD"); mongo_sync_conn_set_slaveok (c, TRUE); ok (mongo_sync_cmd_custom (c, "test", cmd) == NULL, "mongo_sync_cmd_custom() fails with a bogus FD"); bson_free (cmd); mongo_sync_disconnect (c); test_mongo_sync_cmd_custom_net (); }
void test_mongo_sync_cmd_custom_net_secondary (void) { mongo_sync_connection *conn; bson *cmd; mongo_packet *p; skip (!config.secondary_host, 1, "Secondary server not configured"); conn = mongo_sync_connect (config.secondary_host, config.secondary_port, TRUE); cmd = bson_build (BSON_TYPE_INT32, "getnonce", 1, BSON_TYPE_NONE); bson_finish (cmd); p = mongo_sync_cmd_custom (conn, config.db, cmd); ok (p != NULL, "mongo_sync_cmd_custom() works on the secondary too"); mongo_wire_packet_free (p); bson_free (cmd); mongo_sync_disconnect (conn); endskip; }
void test_mongo_sync_cmd_custom_net (void) { mongo_sync_connection *conn; bson *cmd; mongo_packet *p; begin_network_tests (3); conn = mongo_sync_connect (config.primary_host, config.primary_port, TRUE); mongo_sync_cmd_is_master (conn); mongo_sync_conn_set_auto_reconnect (conn, TRUE); cmd = bson_build (BSON_TYPE_INT32, "getnonce", 1, BSON_TYPE_NONE); bson_finish (cmd); p = mongo_sync_cmd_custom (conn, config.db, cmd); ok (p != NULL, "mongo_sync_cmd_custom() works"); mongo_wire_packet_free (p); shutdown (conn->super.fd, SHUT_RDWR); sleep (3); p = mongo_sync_cmd_custom (conn, config.db, cmd); ok (p != NULL, "mongo_sync_cmd_custom() automatically reconnects"); mongo_wire_packet_free (p); bson_free (cmd); mongo_sync_disconnect (conn); test_mongo_sync_cmd_custom_net_secondary (); end_network_tests (); }
NEOERR* mmg_custom(mmg_conn *db, char *dbname, char *prefix, HDF *outnode, char *command) { mongo_packet *p; mongo_sync_cursor *c; bson *doc; NEOERR *err; MCS_NOT_NULLC(db, dbname, command); mtc_noise("custom %s %s", dbname, command); /* * doc */ doc = mbson_new_from_string(command, true); if (!doc) return nerr_raise(NERR_ASSERT, "build doc custom %s", command); p = mongo_sync_cmd_custom(db->con, dbname, doc); bson_free(doc); if (!p) return nerr_raise(NERR_DB, "sync_cmd_custom: %s %s", command, strerror(errno)); c = mongo_sync_cursor_new(db->con, dbname, p); if (!c) return nerr_raise(NERR_DB, "cursor: %s", strerror(errno)); if (outnode) { if (mongo_sync_cursor_next(c)) { doc = mongo_sync_cursor_get_data(c); if (!doc) return nerr_raise(NERR_DB, "doc: %s", strerror(errno)); err = mbson_export_to_hdf(outnode, doc, prefix, MBSON_EXPORT_TYPE, true); if (err != STATUS_OK) return nerr_pass(err); } else return nerr_raise(NERR_DB, "cursor next: %s", strerror(errno)); } mongo_sync_cursor_free(c); return STATUS_OK; }
void test_func_mongo_sync_oidtest (void) { mongo_sync_connection *conn; bson *boid, *reply = NULL; bson_cursor *c; mongo_packet *p; guint8 *oid; const guint8 *noid; mongo_util_oid_init (0); oid = mongo_util_oid_new (1); boid = bson_new (); bson_append_oid (boid, "driverOIDTest", oid); bson_finish (boid); conn = mongo_sync_connect (config.primary_host, config.primary_port, FALSE); p = mongo_sync_cmd_custom (conn, config.db, boid); ok (p != NULL, "driverOIDTest(OID) custom command works"); mongo_wire_reply_packet_get_nth_document (p, 1, &reply); bson_finish (reply); c = bson_find (reply, "oid"); bson_cursor_get_oid (c, &noid); ok (memcmp (oid, noid, 12) == 0, "driverOIDTest(OID) returns the same OID"); bson_cursor_free (c); mongo_sync_disconnect (conn); mongo_wire_packet_free (p); bson_free (boid); bson_free (reply); }
void test_func_mongo_sync_safe_mode (void) { mongo_sync_connection *conn; const bson *docs[10]; bson *b1, *b2, *b3, *b4, *cmd; mongo_packet *p; gchar *error; mongo_util_oid_init (0); b1 = bson_new (); bson_append_string (b1, "func_mongo_sync_safe_mode", "works", -1); bson_finish (b1); b2 = bson_new (); bson_append_int32 (b2, "int32", 1984); bson_finish (b2); b3 = test_bson_generate_full (); b4 = test_bson_generate_full (); docs[0] = b1; docs[1] = b2; docs[2] = b3; docs[3] = b4; conn = mongo_sync_connect (config.primary_host, config.primary_port, FALSE); /* Test inserts */ mongo_sync_conn_set_safe_mode (conn, FALSE); ok (mongo_sync_cmd_insert_n (conn, config.ns, 4, docs) == TRUE, "mongo_sync_cmd_insert_n() should not fail with safe mode off"); mongo_sync_conn_set_safe_mode (conn, TRUE); ok (mongo_sync_cmd_insert_n (conn, config.ns, 4, docs) == FALSE, "mongo_sync_cmd_insert_n() should fail with safe mode on"); /* Test a custom command */ cmd = bson_new (); bson_append_int32 (cmd, "bogusCommand", 1); bson_finish (cmd); mongo_sync_cmd_reset_error (conn, config.db); mongo_sync_conn_set_safe_mode (conn, FALSE); p = mongo_sync_cmd_custom (conn, config.db, cmd); mongo_sync_cmd_get_last_error (conn, config.db, &error); ok (p == NULL && strcmp (error, "no such cmd: bogusCommand") == 0, "mongo_sync_cmd_custom() with a bogus command fails with safe-mode off"); bson_free (cmd); cmd = bson_new (); bson_append_int32 (cmd, "bogusCommand2", 1); bson_finish (cmd); mongo_sync_cmd_reset_error (conn, config.db); mongo_sync_conn_set_safe_mode (conn, TRUE); p = mongo_sync_cmd_custom (conn, config.db, cmd); mongo_sync_cmd_get_last_error (conn, config.db, &error); ok (p == NULL && strcmp (error, "no such cmd: bogusCommand2") == 0, "mongo_sync_cmd_custom() with a bogus command fails with safe-mode on"); bson_free (cmd); mongo_sync_disconnect (conn); bson_free (b1); bson_free (b2); bson_free (b3); bson_free (b4); }