Пример #1
0
static void
server_changed (const mongoc_apm_server_changed_t *event)
{
   context_t *ctx;
   bson_oid_t topology_id;
   const char *host_and_port;
   bson_t prev_sd;
   bson_t new_sd;

   ctx = (context_t *) mongoc_apm_server_changed_get_context (event);

   /* check topology id is consistent */
   mongoc_apm_server_changed_get_topology_id (event, &topology_id);
   ASSERT (bson_oid_equal (&topology_id, &ctx->topology_id));

   host_and_port = mongoc_apm_server_changed_get_host (event)->host_and_port;
   sd_to_bson (mongoc_apm_server_changed_get_previous_description (event),
               &prev_sd);
   sd_to_bson (mongoc_apm_server_changed_get_new_description (event),
               &new_sd);

   context_append (ctx,
                   BCON_NEW ("server_description_changed_event", "{",
                             "topologyId", BCON_UTF8 ("42"),
                             "address", BCON_UTF8 (host_and_port),
                             "previousDescription", BCON_DOCUMENT (&prev_sd),
                             "newDescription", BCON_DOCUMENT (&new_sd),
                             "}"));

   bson_destroy (&prev_sd);
   bson_destroy (&new_sd);
}
Пример #2
0
static void
topology_changed (const mongoc_apm_topology_changed_t *event)
{
   context_t *ctx;
   bson_oid_t topology_id;
   bson_t prev_td;
   bson_t new_td;

   ctx = (context_t *) mongoc_apm_topology_changed_get_context (event);

   mongoc_apm_topology_changed_get_topology_id (event, &topology_id);
   ASSERT (bson_oid_equal (&topology_id, &ctx->topology_id));

   td_to_bson (mongoc_apm_topology_changed_get_previous_description (event),
               &prev_td);
   td_to_bson (mongoc_apm_topology_changed_get_new_description (event),
               &new_td);

   context_append (ctx,
                   BCON_NEW ("topology_description_changed_event", "{",
                             "newDescription", BCON_DOCUMENT (&new_td),
                             "previousDescription", BCON_DOCUMENT (&prev_td),
                             "topologyId", BCON_UTF8 ("42"),
                             "}"));

   bson_destroy (&prev_td);
   bson_destroy (&new_td);
}
Пример #3
0
static void
test_bson_oid_compare (void)
{
   bson_oid_t oid;
   bson_oid_t oid2;

   bson_oid_init_from_string(&oid,  "000000000000000000001234");
   bson_oid_init_from_string(&oid2, "000000000000000000001234");
   assert(0 == bson_oid_compare(&oid, &oid2));
   assert(TRUE == bson_oid_equal(&oid, &oid2));

   bson_oid_init_from_string(&oid, "000000000000000000001234");
   bson_oid_init_from_string(&oid2, "000000000000000000004321");
   assert(bson_oid_compare(&oid, &oid2) < 0);
   assert(bson_oid_compare(&oid2, &oid) > 0);
   assert(FALSE == bson_oid_equal(&oid, &oid2));
}
Пример #4
0
static void
test_bson_oid_compare (void)
{
   bson_oid_t oid;
   bson_oid_t oid2;

   bson_oid_init_from_string (&oid, "000000000000000000001234");
   bson_oid_init_from_string (&oid2, "000000000000000000001234");
   BSON_ASSERT (0 == bson_oid_compare (&oid, &oid2));
   BSON_ASSERT (true == bson_oid_equal (&oid, &oid2));

   bson_oid_init_from_string (&oid, "000000000000000000001234");
   bson_oid_init_from_string (&oid2, "000000000000000000004321");
   BSON_ASSERT (bson_oid_compare (&oid, &oid2) < 0);
   BSON_ASSERT (bson_oid_compare (&oid2, &oid) > 0);
   BSON_ASSERT (false == bson_oid_equal (&oid, &oid2));
}
Пример #5
0
static void
test_bson_oid_copy (void)
{
   bson_oid_t oid;
   bson_oid_t oid2;

   bson_oid_init_from_string(&oid, "000000000000000000001234");
   bson_oid_init_from_string(&oid2, "000000000000000000004321");
   bson_oid_copy(&oid, &oid2);
   assert(TRUE == bson_oid_equal(&oid, &oid2));
}
Пример #6
0
static void
test_bson_oid_copy (void)
{
   bson_oid_t oid;
   bson_oid_t oid2;

   bson_oid_init_from_string (&oid, "000000000000000000001234");
   bson_oid_init_from_string (&oid2, "000000000000000000004321");
   bson_oid_copy (&oid, &oid2);
   BSON_ASSERT (true == bson_oid_equal (&oid, &oid2));
}
Пример #7
0
static void
topology_closed (const mongoc_apm_topology_closed_t *event)
{
   context_t *ctx;
   bson_oid_t topology_id;

   ctx = (context_t *) mongoc_apm_topology_closed_get_context (event);
   mongoc_apm_topology_closed_get_topology_id (event, &topology_id);
   ASSERT (bson_oid_equal (&topology_id, &ctx->topology_id));
   context_append (ctx, BCON_NEW ("topology_closed_event", "{",
                                  "topologyId", BCON_UTF8 ("42"),
                                  "}"));
}
Пример #8
0
static void
topology_opening (const mongoc_apm_topology_opening_t *event)
{
   context_t *ctx;
   bson_oid_t zeroes;

   /* new event's topology id is NOT all zeroes */
   bson_oid_init_from_string (&zeroes, "000000000000000000000000");
   ASSERT (!bson_oid_equal (&event->topology_id, &zeroes));

   ctx = (context_t *) mongoc_apm_topology_opening_get_context (event);
   mongoc_apm_topology_opening_get_topology_id (event, &ctx->topology_id);
   context_append (ctx, BCON_NEW ("topology_opening_event", "{",
                                  "topologyId", BCON_UTF8 ("42"),
                                  "}"));
}
Пример #9
0
static void
test_oid (void)
{
   bson_oid_t oid;
   const bson_oid_t *ooid;

   bson_oid_init (&oid, NULL);

   bson_t *bcon = BCON_NEW ("foo", BCON_OID (&oid));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_OID (ooid)));

   assert (bson_oid_equal (&oid, ooid));

   bson_destroy (bcon);
}
Пример #10
0
static void
test_bson_oid_init (void)
{
   bson_context_t context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   bson_context_init(&context, BSON_CONTEXT_NONE);
   bson_oid_init(&oid, &context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init(&oid2, &context);
      assert(FALSE == bson_oid_equal(&oid, &oid2));
      assert(0 > bson_oid_compare(&oid, &oid2));
      bson_oid_copy(&oid2, &oid);
   }
}
Пример #11
0
static void
test_bson_oid_init_sequence_with_tid (void)
{
   bson_context_t context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   bson_context_init(&context, BSON_CONTEXT_USE_TASK_ID);
   bson_oid_init_sequence(&oid, &context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init_sequence(&oid2, &context);
      assert(FALSE == bson_oid_equal(&oid, &oid2));
      assert(0 > bson_oid_compare(&oid, &oid2));
      bson_oid_copy(&oid2, &oid);
   }
}
Пример #12
0
static void
test_bson_oid_init_sequence_thread_safe (void)
{
   bson_context_t context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   bson_context_init(&context, BSON_CONTEXT_THREAD_SAFE);
   bson_oid_init_sequence(&oid, &context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init_sequence(&oid2, &context);
      assert(FALSE == bson_oid_equal(&oid, &oid2));
      assert(0 > bson_oid_compare(&oid, &oid2));
      bson_oid_copy(&oid2, &oid);
   }
}
Пример #13
0
static void
test_bson_oid_init_sequence (void)
{
   bson_context_t *context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   context = bson_context_new(BSON_CONTEXT_NONE);
   bson_oid_init_sequence(&oid, context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init_sequence(&oid2, context);
      assert(FALSE == bson_oid_equal(&oid, &oid2));
      assert(0 > bson_oid_compare(&oid, &oid2));
      bson_oid_copy(&oid2, &oid);
   }
   bson_context_destroy(context);
}
Пример #14
0
static void
test_bson_oid_init_sequence_with_tid (void)
{
   bson_context_t *context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   context = bson_context_new (BSON_CONTEXT_USE_TASK_ID);
   bson_oid_init_sequence (&oid, context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init_sequence (&oid2, context);
      BSON_ASSERT (false == bson_oid_equal (&oid, &oid2));
      BSON_ASSERT (0 > bson_oid_compare (&oid, &oid2));
      bson_oid_copy (&oid2, &oid);
   }
   bson_context_destroy (context);
}
Пример #15
0
static void
test_bson_oid_init_sequence_thread_safe (void)
{
   bson_context_t *context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   context = bson_context_new (BSON_CONTEXT_THREAD_SAFE);
   bson_oid_init_sequence (&oid, context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init_sequence (&oid2, context);
      BSON_ASSERT (false == bson_oid_equal (&oid, &oid2));
      BSON_ASSERT (0 > bson_oid_compare (&oid, &oid2));
      bson_oid_copy (&oid2, &oid);
   }
   bson_context_destroy (context);
}
Пример #16
0
static void *
oid_worker (void *data)
{
   bson_context_t *context = data;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   bson_oid_init(&oid2, context);
   for (i = 0; i < 500000; i++) {
      bson_oid_init(&oid, context);
      assert(FALSE == bson_oid_equal(&oid, &oid2));
      assert(0 < bson_oid_compare(&oid, &oid2));
      bson_oid_copy(&oid, &oid2);
   }

   return NULL;
}
Пример #17
0
static void
test_dbpointer (void)
{
   const char *collection;
   bson_oid_t oid;
   const bson_oid_t *ooid;

   bson_oid_init (&oid, NULL);

   bson_t *bcon = BCON_NEW ("foo", BCON_DBPOINTER ("collection", &oid));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_DBPOINTER (collection, ooid)));

   assert (strcmp (collection, "collection") == 0);
   assert (bson_oid_equal (ooid, &oid));

   bson_destroy (bcon);
}
Пример #18
0
static void
server_closed (const mongoc_apm_server_closed_t *event)
{
   context_t *ctx;
   bson_oid_t topology_id;
   const char *host_and_port;

   ctx = (context_t *) mongoc_apm_server_closed_get_context (event);

   mongoc_apm_server_closed_get_topology_id (event, &topology_id);
   ASSERT (bson_oid_equal (&topology_id, &ctx->topology_id));

   host_and_port = mongoc_apm_server_closed_get_host (event)->host_and_port;
   context_append (ctx,
                   BCON_NEW ("server_closed_event", "{",
                             "address", BCON_UTF8 (host_and_port),
                             "topologyId", BCON_UTF8 ("42"),
                             "}"));
}
Пример #19
0
static void
test_bson_oid_init (void)
{
   bson_context_t *context;
   bson_oid_t oid;
   bson_oid_t oid2;
   int i;

   context = bson_context_new(BSON_CONTEXT_NONE);
   bson_oid_init(&oid, context);
   for (i = 0; i < 10000; i++) {
      bson_oid_init(&oid2, context);
      assert(FALSE == bson_oid_equal(&oid, &oid2));
      assert(0 > bson_oid_compare(&oid, &oid2));
      bson_oid_copy(&oid2, &oid);
   }
   bson_context_destroy(context);

   /*
    * Test that the shared context works.
    */
   bson_oid_init(&oid, NULL);
   BSON_ASSERT(bson_context_get_default());
}