1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include "mongoc-tests.h"
#include <mongoc.h>
#include "ha-test.h"
static ha_sharded_cluster_t *cluster;
static ha_replica_set_t *repl_1;
static ha_replica_set_t *repl_2;
static ha_node_t *node_1_1;
static ha_node_t *node_1_2;
static ha_node_t *node_1_3;
static ha_node_t *node_2_1;
static ha_node_t *node_2_2;
static ha_node_t *node_2_3;
static void
test1 (void)
{
mongoc_collection_t *collection;
mongoc_client_t *client;
bson_error_t error = { 0 };
bool r;
bson_t q = BSON_INITIALIZER;
int i;
BSON_ASSERT (cluster);
bson_append_utf8 (&q, "hello", -1, "world", -1);
client = ha_sharded_cluster_get_client (cluster);
collection = mongoc_client_get_collection (client, "test", "test");
for (i = 0; i < 100; i++) {
r = mongoc_collection_insert (collection,
MONGOC_INSERT_NONE,
&q,
NULL,
&error);
BSON_ASSERT (r);
BSON_ASSERT (!error.domain);
BSON_ASSERT (!error.code);
}
mongoc_collection_destroy (collection);
mongoc_client_destroy (client);
bson_destroy (&q);
}
int
main (int argc,
char *argv[])
{
mongoc_init();
repl_1 = ha_replica_set_new("shardtest1");
node_1_1 = ha_replica_set_add_replica(repl_1, "shardtest1_1");
node_1_2 = ha_replica_set_add_replica(repl_1, "shardtest1_2");
node_1_3 = ha_replica_set_add_replica(repl_1, "shardtest1_3");
repl_2 = ha_replica_set_new("shardtest2");
node_2_1 = ha_replica_set_add_replica(repl_2, "shardtest2_1");
node_2_2 = ha_replica_set_add_replica(repl_2, "shardtest2_2");
node_2_3 = ha_replica_set_add_replica(repl_2, "shardtest2_3");
cluster = ha_sharded_cluster_new("cluster1");
ha_sharded_cluster_add_replica_set(cluster, repl_1);
ha_sharded_cluster_add_replica_set(cluster, repl_2);
ha_sharded_cluster_add_config(cluster, "config1");
ha_sharded_cluster_add_router(cluster, "router1");
ha_sharded_cluster_add_router(cluster, "router2");
ha_sharded_cluster_start(cluster);
ha_sharded_cluster_wait_for_healthy(cluster);
run_test("/ShardedCluster/basic", test1);
ha_sharded_cluster_shutdown(cluster);
mongoc_cleanup();
return 0;
}
|