static void
test_replica_set_ssl_client(void)
{
   mongoc_collection_t *collection;
   mongoc_client_t *client;
   ha_replica_set_t *replica_set;
   bson_error_t error;
   int r;
   bson_t b;

   mongoc_ssl_opt_t sopt = { 0 };

   sopt.pem_file = gTestPEMFileLocalhost;
   sopt.ca_file = gTestCAFile;

   replica_set = ha_replica_set_new("repltest1");
   ha_replica_set_ssl(replica_set, &sopt);
   ha_replica_set_add_replica(replica_set, "replica1");
   ha_replica_set_add_replica(replica_set, "replica2");
   ha_replica_set_add_replica(replica_set, "replica3");

   ha_replica_set_start(replica_set);
   ha_replica_set_wait_for_healthy(replica_set);


   client = ha_replica_set_create_client(replica_set);
   assert(client);

   collection = mongoc_client_get_collection(client, "test", "test");
   assert(collection);

   bson_init(&b);
   bson_append_utf8(&b, "hello", -1, "world", -1);

   r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE, &b, NULL, &error);
   assert(r);

   mongoc_collection_destroy(collection);
   mongoc_client_destroy(client);
   bson_destroy(&b);

   ha_replica_set_shutdown(replica_set);
   ha_replica_set_destroy(replica_set);
}
Beispiel #2
0
int
main (int   argc,   /* IN */
      char *argv[]) /* IN */
{
   mongoc_init();

   replica_set = ha_replica_set_new("repltest1");
   r1 = ha_replica_set_add_replica(replica_set, "replica1");
   r2 = ha_replica_set_add_replica(replica_set, "replica2");
   r3 = ha_replica_set_add_replica(replica_set, "replica3");
   a1 = ha_replica_set_add_arbiter(replica_set, "arbiter1");

   ha_replica_set_start(replica_set);

   ha_replica_set_wait_for_healthy(replica_set);
   use_pool = false;
   run_test("/ReplicaSet/single/lose_node_during_cursor", test1);

   ha_replica_set_wait_for_healthy(replica_set);
   use_pool = true;
   run_test("/ReplicaSet/pool/lose_node_during_cursor", test1);

   ha_replica_set_wait_for_healthy(replica_set);
   use_pool = false;
   run_test("/ReplicaSet/single/cursor_with_2_of_3_replicas_down", test2);

   ha_replica_set_wait_for_healthy(replica_set);
   use_pool = true;
   run_test("/ReplicaSet/pool/cursor_with_2_of_3_replicas_down", test2);

   ha_replica_set_wait_for_healthy(replica_set);

   ha_replica_set_shutdown(replica_set);
   ha_replica_set_destroy(replica_set);

   mongoc_cleanup();

   return 0;
}
Beispiel #3
0
void
ha_sharded_cluster_start (ha_sharded_cluster_t *cluster)
{
   bson_string_t *configopt;
   struct stat st;
   ha_node_t *iter;
   char *cmd;
   int i;

   bson_return_if_fail(cluster);

   if (!stat(cluster->name, &st)) {
      if (S_ISDIR(st.st_mode)) {
         /* Ayyyeeeeeee */
         cmd = bson_strdup_printf("rm -rf \"%s\"", cluster->name);
         fprintf(stderr, "%s\n", cmd);
         system(cmd);
         bson_free(cmd);
      }
   }

   if (!!mkdir(cluster->name, 0750)) {
      fprintf(stderr, "Failed to create directory \"%s\"\n",
              cluster->name);
      abort();
   }

   for (i = 0; i < 12; i++) {
      if (cluster->replicas[i]) {
         ha_replica_set_start(cluster->replicas[i]);
      }
   }

   configopt = bson_string_new (NULL);

   for (iter = cluster->configs; iter; iter = iter->next) {
      ha_node_setup(iter);
      ha_node_restart(iter);
      bson_string_append_printf (configopt, "127.0.0.1:%hu%s",
                                 iter->port,
                                 iter->next ? "," : "");
   }

   sleep (5);

   for (iter = cluster->routers; iter; iter = iter->next) {
      bson_free (iter->configopt);
      iter->configopt = bson_strdup (configopt->str);
      ha_node_setup (iter);
      ha_node_restart (iter);
   }

   ha_sharded_cluster_wait_for_healthy (cluster);

   for (i = 0; i < 12; i++) {
      if (cluster->replicas[i]) {
         ha_config_add_shard (cluster->routers, cluster->replicas[i]);
      }
   }

   bson_string_free (configopt, TRUE);
}