Skip to content
Browse files

CDRIVER-175 Implement default write acknowledgement with new MongoCli…

…ent class

mongo_replica_set_client renamed with "replica_set" replacing "replset" uniformly - the "replset" functions are deprecated
  • Loading branch information...
1 parent 189f142 commit ebe1d59298a297e8777f452b8873a7e7c5a9178d @gjmurakami-10gen gjmurakami-10gen committed Nov 26, 2012
View
8 HISTORY.md
@@ -4,19 +4,21 @@
2012-11-19
** API CHANGE **
-In version 0.7, mongo_client and mongo_replset_client are the connection functions,
+In version 0.7, mongo_client and mongo_replica_set_client are the connection functions,
replacing the deprecated functions mongo_connect and mongo_replset_connect, respectively.
-The mongo_client and mongo_replset_client functions now have a default write concern
+The mongo_client and mongo_replica_set_client functions now have a default write concern
specifying the acknowledgement of writes.
Please see the Write Concern document for explicit details.
+The term "replica_set" replaces "replset" consistently,
+and the functions containing "replset" are deprecated.
BCON (BSON C Object Notation) provides JSON-like (or BSON-like) initializers in C
and readable, and maintainable data-driven definition of BSON documents.
Other features and fixes include:
* support for Unix domain sockets
-* three memory leaks in library code
+* three memory leak fixes in library code
* proper cursor termination at the end of a set of large documents
* mongo_get_primary initialization to avoid memory overrun
* Mac dynamic library linking
View
2 SConstruct
@@ -293,5 +293,5 @@ AlwaysBuild(test_alias)
# Run replica set test only
repl_testEnv = benchmarkEnv.Clone()
-repl_tests = ["replica_set"]
+repl_tests = ["replica_set", "replset"]
run_tests("test", repl_tests, repl_testEnv, "repl_test")
View
10 docs/source/sphinx/source/connections.rst
@@ -83,15 +83,15 @@ Here's how you go about that:
mongo conn[1];
int result;
- mongo_replset_init( conn, "rs-dc-1" );
- mongo_replset_add_seed( conn, '10.4.3.1', 27017 );
- mongo_replset_add_seed( conn, '10.4.3.2', 27017 );
+ mongo_replica_set_init( conn, "rs-dc-1" );
+ mongo_replica_set_add_seed( conn, '10.4.3.1', 27017 );
+ mongo_replica_set_add_seed( conn, '10.4.3.2', 27017 );
- result = mongo_replset_client( conn );
+ result = mongo_replica_set_client( conn );
First we initiaize the connection object, providing the name of the replica set,
in this case, "rs-dc-1." Next, we add two seed nodes. Finally, we connect
-by pass the connection to ``mongo_replset_client``.
+by pass the connection to ``mongo_replica_set_client``.
As with the basic connection, we'll want to check for any errors on connect. Notice
that there are two more error conditions we check for:
View
8 docs/source/sphinx/source/tutorial.rst
@@ -103,11 +103,11 @@ then you add seed nodes, and finally you connect. Here's an example:
int main() {
mongo conn[1];
- mongo_replset_init( conn, "shard1" );
- mongo_replset_add_seed( conn, "10.4.3.22", 27017 );
- mongo_replset_add_seed( conn, "10.4.3.32", 27017 );
+ mongo_replica_set_init( conn, "shard1" );
+ mongo_replica_set_add_seed( conn, "10.4.3.22", 27017 );
+ mongo_replica_set_add_seed( conn, "10.4.3.32", 27017 );
- status = mongo_replset_client( conn );
+ status = mongo_replica_set_client( conn );
if( status != MONGO_OK ) {
/* Check conn->err for error code. */
View
6 docs/source/sphinx/source/write_concern.rst
@@ -1,7 +1,7 @@
Write Concern
=============
-The ``mongo_client`` and ``mongo_replset_client`` functions set a default write concern
+The ``mongo_client`` and ``mongo_replica_set_client`` functions set a default write concern
at the top level specifying acknowledged writes.
In addition to reporting write errors, write concern also allows you to ensure
@@ -12,10 +12,10 @@ Or for very-high write performance, write concern can specify writes without ack
This is recommended only for cases that can tolerate the potential loss of a few writes
such as logging, analytics, etc.
-The old ``mongo_connect`` and ``mongo_replset_connect`` functions have a default write concern
+The old ``mongo_connect`` and ``mongo_replica_set_connect`` functions have a default write concern
where writes are unacknowledged.
They are deprecated and temporarily available for backward compatibility to smooth transition to
-the ``mongo_client`` and ``mongo_replset_client`` functions.
+the ``mongo_client`` and ``mongo_replica_set_client`` functions.
Implementation and API
----------------------
View
94 src/mongo.c
@@ -70,7 +70,7 @@ MONGO_EXPORT int mongo_get_socket(mongo* conn) {
MONGO_EXPORT int mongo_get_host_count(mongo* conn) {
- mongo_replset* r = conn->replset;
+ mongo_replica_set* r = conn->replica_set;
mongo_host_port* hp;
int count = 0;
if (!r) return 0;
@@ -81,7 +81,7 @@ MONGO_EXPORT int mongo_get_host_count(mongo* conn) {
MONGO_EXPORT const char* mongo_get_host(mongo* conn, int i) {
- mongo_replset* r = conn->replset;
+ mongo_replica_set* r = conn->replica_set;
mongo_host_port* hp;
int count = 0;
if (!r) return 0;
@@ -435,22 +435,27 @@ MONGO_EXPORT int mongo_connect( mongo *conn , const char *host, int port ) {
return ret;
}
-MONGO_EXPORT void mongo_replset_init( mongo *conn, const char *name ) {
+MONGO_EXPORT void mongo_replica_set_init( mongo *conn, const char *name ) {
mongo_init( conn );
- conn->replset = bson_malloc( sizeof( mongo_replset ) );
- conn->replset->primary_connected = 0;
- conn->replset->seeds = NULL;
- conn->replset->hosts = NULL;
- conn->replset->name = ( char * )bson_malloc( strlen( name ) + 1 );
- memcpy( conn->replset->name, name, strlen( name ) + 1 );
+ conn->replica_set = bson_malloc( sizeof( mongo_replica_set ) );
+ conn->replica_set->primary_connected = 0;
+ conn->replica_set->seeds = NULL;
+ conn->replica_set->hosts = NULL;
+ conn->replica_set->name = ( char * )bson_malloc( strlen( name ) + 1 );
+ memcpy( conn->replica_set->name, name, strlen( name ) + 1 );
conn->primary = bson_malloc( sizeof( mongo_host_port ) );
conn->primary->host[0] = '\0';
conn->primary->next = NULL;
}
-static void mongo_replset_add_node( mongo_host_port **list, const char *host, int port ) {
+MONGO_EXPORT void mongo_replset_init( mongo *conn, const char *name ) {
+ fprintf(stderr, "WARNING: mongo_replset_init() is deprecated, please use mongo_replica_set_init()\n");
+ mongo_replica_set_init( conn, name );
+}
+
+static void mongo_replica_set_add_node( mongo_host_port **list, const char *host, int port ) {
mongo_host_port *host_port = bson_malloc( sizeof( mongo_host_port ) );
host_port->port = port;
host_port->next = NULL;
@@ -466,7 +471,7 @@ static void mongo_replset_add_node( mongo_host_port **list, const char *host, in
}
}
-static void mongo_replset_free_list( mongo_host_port **list ) {
+static void mongo_replica_set_free_list( mongo_host_port **list ) {
mongo_host_port *node = *list;
mongo_host_port *prev;
@@ -479,8 +484,13 @@ static void mongo_replset_free_list( mongo_host_port **list ) {
*list = NULL;
}
+MONGO_EXPORT void mongo_replica_set_add_seed( mongo *conn, const char *host, int port ) {
+ mongo_replica_set_add_node( &conn->replica_set->seeds, host, port );
+}
+
MONGO_EXPORT void mongo_replset_add_seed( mongo *conn, const char *host, int port ) {
- mongo_replset_add_node( &conn->replset->seeds, host, port );
+ fprintf(stderr, "WARNING: mongo_replset_add_seed() is deprecated, please use mongo_replica_set_add_seed()\n");
+ mongo_replica_set_add_node( &conn->replica_set->seeds, host, port );
}
void mongo_parse_host( const char *host_string, mongo_host_port *host_port ) {
@@ -508,7 +518,7 @@ void mongo_parse_host( const char *host_string, mongo_host_port *host_port ) {
host_port->port = MONGO_DEFAULT_PORT;
}
-static void mongo_replset_check_seed( mongo *conn ) {
+static void mongo_replica_set_check_seed( mongo *conn ) {
bson out;
bson hosts;
const char *data;
@@ -536,7 +546,7 @@ static void mongo_replset_check_seed( mongo *conn ) {
if( host_port ) {
mongo_parse_host( host_string, host_port );
- mongo_replset_add_node( &conn->replset->hosts,
+ mongo_replica_set_add_node( &conn->replica_set->hosts,
host_port->host, host_port->port );
bson_free( host_port );
@@ -557,7 +567,7 @@ static void mongo_replset_check_seed( mongo *conn ) {
/* Find out whether the current connected node is master, and
* verify that the node's replica set name matched the provided name
*/
-static int mongo_replset_check_host( mongo *conn ) {
+static int mongo_replica_set_check_host( mongo *conn ) {
bson out;
bson_iterator it;
@@ -577,7 +587,7 @@ static int mongo_replset_check_host( mongo *conn ) {
if( bson_find( &it, &out, "setName" ) ) {
set_name = bson_iterator_string( &it );
- if( strcmp( set_name, conn->replset->name ) != 0 ) {
+ if( strcmp( set_name, conn->replica_set->name ) != 0 ) {
bson_destroy( &out );
conn->err = MONGO_CONN_BAD_SET_NAME;
return MONGO_ERROR;
@@ -588,15 +598,15 @@ static int mongo_replset_check_host( mongo *conn ) {
bson_destroy( &out );
if( ismaster ) {
- conn->replset->primary_connected = 1;
+ conn->replica_set->primary_connected = 1;
} else {
mongo_env_close_socket( conn->sock );
}
return MONGO_OK;
}
-MONGO_EXPORT int mongo_replset_client( mongo *conn ) {
+MONGO_EXPORT int mongo_replica_set_client( mongo *conn ) {
int res = 0;
mongo_host_port *node;
@@ -607,33 +617,33 @@ MONGO_EXPORT int mongo_replset_client( mongo *conn ) {
/* First iterate over the seed nodes to get the canonical list of hosts
* from the replica set. Break out once we have a host list.
*/
- node = conn->replset->seeds;
+ node = conn->replica_set->seeds;
while( node != NULL ) {
res = mongo_env_socket_connect( conn, ( const char * )&node->host, node->port );
if( res == MONGO_OK ) {
- mongo_replset_check_seed( conn );
- if( conn->replset->hosts )
+ mongo_replica_set_check_seed( conn );
+ if( conn->replica_set->hosts )
break;
}
node = node->next;
}
/* Iterate over the host list, checking for the primary node. */
- if( !conn->replset->hosts ) {
+ if( !conn->replica_set->hosts ) {
conn->err = MONGO_CONN_NO_PRIMARY;
return MONGO_ERROR;
} else {
- node = conn->replset->hosts;
+ node = conn->replica_set->hosts;
while( node != NULL ) {
res = mongo_env_socket_connect( conn, ( const char * )&node->host, node->port );
if( res == MONGO_OK ) {
- if( mongo_replset_check_host( conn ) != MONGO_OK )
+ if( mongo_replica_set_check_host( conn ) != MONGO_OK )
return MONGO_ERROR;
/* Primary found, so return. */
- else if( conn->replset->primary_connected ) {
+ else if( conn->replica_set->primary_connected ) {
strncpy( conn->primary->host, node->host, strlen( node->host ) + 1 );
conn->primary->port = node->port;
return MONGO_OK;
@@ -658,8 +668,8 @@ MONGO_EXPORT int mongo_replset_client( mongo *conn ) {
MONGO_EXPORT int mongo_replset_connect( mongo *conn ) {
int ret;
- fprintf(stderr, "WARNING: mongo_replset_connect() is deprecated, please use mongo_replset_client()\n");
- ret = mongo_replset_client( conn );
+ fprintf(stderr, "WARNING: mongo_replset_connect() is deprecated, please use mongo_replica_set_client()\n");
+ ret = mongo_replica_set_client( conn );
mongo_set_write_concern( conn, 0 );
return ret;
}
@@ -676,11 +686,11 @@ MONGO_EXPORT int mongo_reconnect( mongo *conn ) {
int res;
mongo_disconnect( conn );
- if( conn->replset ) {
- conn->replset->primary_connected = 0;
- mongo_replset_free_list( &conn->replset->hosts );
- conn->replset->hosts = NULL;
- res = mongo_replset_connect( conn );
+ if( conn->replica_set ) {
+ conn->replica_set->primary_connected = 0;
+ mongo_replica_set_free_list( &conn->replica_set->hosts );
+ conn->replica_set->hosts = NULL;
+ res = mongo_replica_set_client( conn );
return res;
} else
return mongo_env_socket_connect( conn, conn->primary->host, conn->primary->port );
@@ -700,10 +710,10 @@ MONGO_EXPORT void mongo_disconnect( mongo *conn ) {
if( ! conn->connected )
return;
- if( conn->replset ) {
- conn->replset->primary_connected = 0;
- mongo_replset_free_list( &conn->replset->hosts );
- conn->replset->hosts = NULL;
+ if( conn->replica_set ) {
+ conn->replica_set->primary_connected = 0;
+ mongo_replica_set_free_list( &conn->replica_set->hosts );
+ conn->replica_set->hosts = NULL;
}
mongo_env_close_socket( conn->sock );
@@ -715,12 +725,12 @@ MONGO_EXPORT void mongo_disconnect( mongo *conn ) {
MONGO_EXPORT void mongo_destroy( mongo *conn ) {
mongo_disconnect( conn );
- if( conn->replset ) {
- mongo_replset_free_list( &conn->replset->seeds );
- mongo_replset_free_list( &conn->replset->hosts );
- bson_free( conn->replset->name );
- bson_free( conn->replset );
- conn->replset = NULL;
+ if( conn->replica_set ) {
+ mongo_replica_set_free_list( &conn->replica_set->seeds );
+ mongo_replica_set_free_list( &conn->replica_set->hosts );
+ bson_free( conn->replica_set->name );
+ bson_free( conn->replica_set );
+ conn->replica_set = NULL;
}
bson_free( conn->primary );
View
36 src/mongo.h
@@ -158,11 +158,11 @@ typedef struct {
mongo_host_port *hosts; /**< List of host/ports given by the replica set */
char *name; /**< Name of the replica set. */
bson_bool_t primary_connected; /**< Primary node connection status. */
-} mongo_replset;
+} mongo_replica_set;
typedef struct mongo {
mongo_host_port *primary; /**< Primary connection info. */
- mongo_replset *replset; /**< replset object if connected to a replica set. */
+ mongo_replica_set *replica_set; /**< replica_set object if connected to a replica set. */
int sock; /**< Socket file descriptor. */
int flags; /**< Flags on this connection object. */
int conn_timeout_ms; /**< Connection timeout in milliseconds. */
@@ -226,7 +226,8 @@ MONGO_EXPORT void mongo_init( mongo *conn );
MONGO_EXPORT int mongo_client( mongo *conn , const char *host, int port );
/**
- * DEPRECATED. Connect to a single MongoDB server.
+ * DEPRECATED - use mongo_client.
+ * Connect to a single MongoDB server.
*
* @param conn a mongo object.
* @param host a numerical network address or a network hostname.
@@ -239,6 +240,16 @@ MONGO_EXPORT int mongo_connect( mongo *conn , const char *host, int port );
/**
* Set up this connection object for connecting to a replica set.
+ * To connect, pass the object to mongo_replica_set_connect().
+ *
+ * @param conn a mongo object.
+ * @param name the name of the replica set to connect to.
+ * */
+MONGO_EXPORT void mongo_replica_set_init( mongo *conn, const char *name );
+
+/**
+ * DEPRECATED - use mongo_replica_set_init.
+ * Set up this connection object for connecting to a replica set.
* To connect, pass the object to mongo_replset_connect().
*
* @param conn a mongo object.
@@ -255,6 +266,18 @@ MONGO_EXPORT void mongo_replset_init( mongo *conn, const char *name );
* @param host a numerical network address or a network hostname.
* @param port the port to connect to.
*/
+MONGO_EXPORT void mongo_replica_set_add_seed( mongo *conn, const char *host, int port );
+
+/**
+ * DEPRECATED - use mongo_replica_set_add_seed.
+ * Add a seed node to the replica set connection object.
+ *
+ * You must specify at least one seed node before connecting to a replica set.
+ *
+ * @param conn a mongo object.
+ * @param host a numerical network address or a network hostname.
+ * @param port the port to connect to.
+ */
MONGO_EXPORT void mongo_replset_add_seed( mongo *conn, const char *host, int port );
/**
@@ -281,17 +304,18 @@ MONGO_EXPORT int mongo_validate_ns( mongo *conn, const char *ns );
* Connect to a replica set.
*
* Before passing a connection object to this function, you must already have called
- * mongo_set_replset and mongo_replset_add_seed.
+ * mongo_set_replica_set and mongo_replica_set_add_seed.
*
* @param conn a mongo object.
*
* @return MONGO_OK or MONGO_ERROR on failure. On failure, a constant of type
* mongo_conn_return_t will be set on the conn->err field.
*/
-MONGO_EXPORT int mongo_replset_client( mongo *conn );
+MONGO_EXPORT int mongo_replica_set_client( mongo *conn );
/**
- * DEPRECATED. Connect to a replica set.
+ * DEPRECATED - use mongo_replica_set_client.
+ * Connect to a replica set.
*
* Before passing a connection object to this function, you must already have called
* mongo_set_replset and mongo_replset_add_seed.
View
34 test/replica_set_test.c
@@ -22,13 +22,13 @@ int test_connect_deprecated( const char *set_name ) {
INIT_SOCKETS_FOR_WINDOWS;
- mongo_replset_init( conn, set_name );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+ mongo_replica_set_init( conn, set_name );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT );
- res = mongo_replset_connect( conn );
+ res = mongo_replica_set_connect( conn );
- /* mongo_replset_connect should print a warning to stderr that it is deprecated */
+ /* mongo_replica_set_connect should print a warning to stderr that it is deprecated */
ASSERT( conn->write_concern == (void*)0 ); /* write_concern should be 0 for backwards compatibility */
@@ -52,11 +52,11 @@ int test_connect( const char *set_name ) {
INIT_SOCKETS_FOR_WINDOWS;
- mongo_replset_init( conn, set_name );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+ mongo_replica_set_init( conn, set_name );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT );
- res = mongo_replset_client( conn );
+ res = mongo_replica_set_client( conn );
if( res != MONGO_OK ) {
res = conn->err;
@@ -80,12 +80,12 @@ int test_reconnect( const char *set_name ) {
INIT_SOCKETS_FOR_WINDOWS;
- mongo_replset_init( conn, set_name );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replica_set_init( conn, set_name );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
- if( ( mongo_replset_client( conn ) != MONGO_OK ) ) {
+ if( ( mongo_replica_set_client( conn ) != MONGO_OK ) ) {
mongo_destroy( conn );
return MONGO_ERROR;
} else {
@@ -129,10 +129,10 @@ int test_insert_limits( const char *set_name ) {
if( mongo_get_server_version( version ) != -1 && version[0] <= '1' )
return 0;
- mongo_replset_init( conn, set_name );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
- mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
- res = mongo_replset_client( conn );
+ mongo_replica_set_init( conn, set_name );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replica_set_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+ res = mongo_replica_set_client( conn );
if( res != MONGO_OK ) {
res = conn->err;
View
185 test/replset_test.c
@@ -0,0 +1,185 @@
+/* test.c */
+
+#include "test.h"
+#include "mongo.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifndef SEED_START_PORT
+#define SEED_START_PORT 30000
+#endif
+
+#ifndef REPLICA_SET_NAME
+#define REPLICA_SET_NAME "replica-set-foo"
+#endif
+
+int test_connect_deprecated( const char *set_name ) {
+
+ mongo conn[1];
+ int res;
+
+ INIT_SOCKETS_FOR_WINDOWS;
+
+ mongo_replset_init( conn, set_name );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+
+ res = mongo_replset_connect( conn );
+
+ /* mongo_replset_connect should print a warning to stderr that it is deprecated */
+
+ ASSERT( conn->write_concern == (void*)0 ); /* write_concern should be 0 for backwards compatibility */
+
+ if( res != MONGO_OK ) {
+ res = conn->err;
+ return res;
+ }
+
+ ASSERT( conn->primary->port == SEED_START_PORT ||
+ conn->primary->port == SEED_START_PORT + 1 ||
+ conn->primary->port == SEED_START_PORT + 2 );
+
+ mongo_destroy( conn );
+ return res;
+}
+
+int test_connect( const char *set_name ) {
+
+ mongo conn[1];
+ int res;
+
+ INIT_SOCKETS_FOR_WINDOWS;
+
+ mongo_replset_init( conn, set_name );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+
+ res = mongo_replset_client( conn );
+
+ if( res != MONGO_OK ) {
+ res = conn->err;
+ return res;
+ }
+
+ ASSERT( conn->primary->port == SEED_START_PORT ||
+ conn->primary->port == SEED_START_PORT + 1 ||
+ conn->primary->port == SEED_START_PORT + 2 );
+
+ mongo_destroy( conn );
+ return res;
+}
+
+int test_reconnect( const char *set_name ) {
+
+ mongo conn[1];
+ int res = 0;
+ int e = 0;
+ bson b;
+
+ INIT_SOCKETS_FOR_WINDOWS;
+
+ mongo_replset_init( conn, set_name );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+
+
+ if( ( mongo_replset_client( conn ) != MONGO_OK ) ) {
+ mongo_destroy( conn );
+ return MONGO_ERROR;
+ } else {
+ fprintf( stderr, "Disconnect now:\n" );
+ sleep( 10 );
+ e = 1;
+ do {
+ res = mongo_find_one( conn, "foo.bar", bson_empty( &b ), bson_empty( &b ), NULL );
+ if( res == MONGO_ERROR && conn->err == MONGO_IO_ERROR ) {
+ sleep( 2 );
+ if( e++ < 30 ) {
+ fprintf( stderr, "Attempting reconnect %d.\n", e );
+ mongo_reconnect( conn );
+ } else {
+ fprintf( stderr, "Fail.\n" );
+ return -1;
+ }
+ }
+ } while( 1 );
+ }
+
+
+ return 0;
+}
+
+int test_insert_limits( const char *set_name ) {
+ char version[10];
+ mongo conn[1];
+ mongo_write_concern wc[1];
+ int i;
+ char key[10];
+ int res = 0;
+ bson b[1], b2[1];
+ bson *objs[2];
+
+ mongo_write_concern_init( wc );
+ wc->w = 1;
+ mongo_write_concern_finish( wc );
+
+ /* We'll perform the full test if we're running v2.0 or later. */
+ if( mongo_get_server_version( version ) != -1 && version[0] <= '1' )
+ return 0;
+
+ mongo_replset_init( conn, set_name );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT + 1 );
+ mongo_replset_add_seed( conn, TEST_SERVER, SEED_START_PORT );
+ res = mongo_replset_client( conn );
+
+ if( res != MONGO_OK ) {
+ res = conn->err;
+ return res;
+ }
+
+ ASSERT( conn->max_bson_size > MONGO_DEFAULT_MAX_BSON_SIZE );
+
+ bson_init( b );
+ for(i=0; i<1200000; i++) {
+ sprintf( key, "%d", i + 10000000 );
+ bson_append_int( b, key, i );
+ }
+ bson_finish( b );
+
+ ASSERT( bson_size( b ) > conn->max_bson_size );
+
+ ASSERT( mongo_insert( conn, "test.foo", b, wc ) == MONGO_ERROR );
+ ASSERT( conn->err == MONGO_BSON_TOO_LARGE );
+
+ mongo_clear_errors( conn );
+ ASSERT( conn->err == 0 );
+
+ bson_init( b2 );
+ bson_append_int( b2, "foo", 1 );
+ bson_finish( b2 );
+
+ objs[0] = b;
+ objs[1] = b2;
+
+ ASSERT( mongo_insert_batch( conn, "test.foo", (const bson**)objs, 2, wc, 0 ) == MONGO_ERROR );
+ ASSERT( conn->err == MONGO_BSON_TOO_LARGE );
+
+ mongo_write_concern_destroy( wc );
+
+ return 0;
+}
+
+int main() {
+ ASSERT( test_connect_deprecated( REPLICA_SET_NAME ) == MONGO_OK );
+ ASSERT( test_connect( REPLICA_SET_NAME ) == MONGO_OK );
+ ASSERT( test_connect( "test-foobar" ) == MONGO_CONN_BAD_SET_NAME );
+ ASSERT( test_insert_limits( REPLICA_SET_NAME ) == MONGO_OK );
+
+ /*
+ ASSERT( test_reconnect( "test-rs" ) == 0 );
+ */
+
+ return 0;
+}
View
4 test/simple_test.c
@@ -30,9 +30,9 @@ int main() {
* Advanced and replica set API
mongo conn[1];
- mongo_replset_init( conn, "foobar" );
+ mongo_replica_set_init( conn, "foobar" );
mongo_set_connect_timeout( conn, 1000 );
- mongo_replset_client( conn );
+ mongo_replica_set_client( conn );
mongo_destroy( conn );
* BSON API

0 comments on commit ebe1d59

Please sign in to comment.
Something went wrong with that request. Please try again.