mirror of
https://github.com/wassname/ray.git
synced 2026-08-08 11:25:28 +08:00
passing object info information with redis module (#138)
* adding object broadcast channel; published on each object table add * publishing data size to the bcast channel * bug fix: objectkey * update object tests to test for data size: C + py * remove debug * clang format * Minor changes. * Fix error. * merging with Robert's comments * clang format for the object table test upgrade
This commit is contained in:
committed by
Robert Nishihara
parent
269f37e26f
commit
cb3e6cde9e
@@ -219,6 +219,7 @@ TEST add_timeout_test(void) {
|
||||
int subscribe_failed = 0;
|
||||
|
||||
void subscribe_done_callback(object_id object_id,
|
||||
int64_t data_size,
|
||||
int manager_count,
|
||||
const char *manager_vector[],
|
||||
void *user_context) {
|
||||
@@ -243,8 +244,8 @@ TEST subscribe_timeout_test(void) {
|
||||
.timeout = 100,
|
||||
.fail_callback = subscribe_fail_callback,
|
||||
};
|
||||
object_table_subscribe_to_notifications(db, subscribe_done_callback, NULL,
|
||||
&retry, NULL, NULL);
|
||||
object_table_subscribe_to_notifications(db, false, subscribe_done_callback,
|
||||
NULL, &retry, NULL, NULL);
|
||||
/* Disconnect the database to see if the lookup times out. */
|
||||
close(db->sub_context->c.fd);
|
||||
event_loop_run(g_loop);
|
||||
@@ -472,7 +473,7 @@ TEST subscribe_retry_test(void) {
|
||||
.timeout = 100,
|
||||
.fail_callback = subscribe_retry_fail_callback,
|
||||
};
|
||||
object_table_subscribe_to_notifications(db, NULL, NULL, &retry,
|
||||
object_table_subscribe_to_notifications(db, false, NULL, NULL, &retry,
|
||||
subscribe_retry_done_callback,
|
||||
(void *) subscribe_retry_context);
|
||||
/* Disconnect the database to let the subscribe times out the first time. */
|
||||
@@ -612,7 +613,7 @@ TEST subscribe_late_test(void) {
|
||||
.timeout = 0,
|
||||
.fail_callback = subscribe_late_fail_callback,
|
||||
};
|
||||
object_table_subscribe_to_notifications(db, NULL, NULL, &retry,
|
||||
object_table_subscribe_to_notifications(db, false, NULL, NULL, &retry,
|
||||
subscribe_late_done_callback,
|
||||
(void *) subscribe_late_context);
|
||||
/* Install handler for terminating the event loop. */
|
||||
@@ -657,6 +658,7 @@ void subscribe_success_done_callback(object_id object_id,
|
||||
}
|
||||
|
||||
void subscribe_success_object_available_callback(object_id object_id,
|
||||
int64_t data_size,
|
||||
int manager_count,
|
||||
const char *manager_vector[],
|
||||
void *user_context) {
|
||||
@@ -679,7 +681,7 @@ TEST subscribe_success_test(void) {
|
||||
.fail_callback = subscribe_success_fail_callback,
|
||||
};
|
||||
object_table_subscribe_to_notifications(
|
||||
db, subscribe_success_object_available_callback,
|
||||
db, false, subscribe_success_object_available_callback,
|
||||
(void *) subscribe_success_context, &retry,
|
||||
subscribe_success_done_callback, (void *) db);
|
||||
|
||||
@@ -702,16 +704,24 @@ TEST subscribe_success_test(void) {
|
||||
}
|
||||
|
||||
/* Test if subscribe succeeds if the object is already present. */
|
||||
typedef struct {
|
||||
const char *teststr;
|
||||
int64_t data_size;
|
||||
} subscribe_object_present_context_t;
|
||||
|
||||
const char *subscribe_object_present_context = "subscribe_object_present";
|
||||
const char *subscribe_object_present_str = "subscribe_object_present";
|
||||
int subscribe_object_present_succeeded = 0;
|
||||
|
||||
void subscribe_object_present_object_available_callback(
|
||||
object_id object_id,
|
||||
int64_t data_size,
|
||||
int manager_count,
|
||||
const char *manager_vector[],
|
||||
void *user_context) {
|
||||
CHECK(user_context == (void *) subscribe_object_present_context);
|
||||
subscribe_object_present_context_t *ctx =
|
||||
(subscribe_object_present_context_t *) user_context;
|
||||
CHECK(ctx->data_size == data_size);
|
||||
CHECK(strcmp(subscribe_object_present_str, ctx->teststr) == 0);
|
||||
subscribe_object_present_succeeded = 1;
|
||||
CHECK(manager_count == 1);
|
||||
}
|
||||
@@ -722,6 +732,10 @@ void fatal_fail_callback(unique_id id, void *user_context, void *user_data) {
|
||||
}
|
||||
|
||||
TEST subscribe_object_present_test(void) {
|
||||
int64_t data_size = 0xF1F0;
|
||||
subscribe_object_present_context_t myctx = {subscribe_object_present_str,
|
||||
data_size};
|
||||
|
||||
g_loop = event_loop_create();
|
||||
db_handle *db =
|
||||
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 11236);
|
||||
@@ -730,10 +744,11 @@ TEST subscribe_object_present_test(void) {
|
||||
retry_info retry = {
|
||||
.num_retries = 0, .timeout = 100, .fail_callback = fatal_fail_callback,
|
||||
};
|
||||
object_table_add(db, id, 0, (unsigned char *) NIL_DIGEST, &retry, NULL, NULL);
|
||||
object_table_add(db, id, data_size, (unsigned char *) NIL_DIGEST, &retry,
|
||||
NULL, NULL);
|
||||
object_table_subscribe_to_notifications(
|
||||
db, subscribe_object_present_object_available_callback,
|
||||
(void *) subscribe_object_present_context, &retry, NULL, (void *) db);
|
||||
db, false, subscribe_object_present_object_available_callback,
|
||||
(void *) &myctx, &retry, NULL, (void *) db);
|
||||
/* Install handler for terminating the event loop. */
|
||||
event_loop_add_timer(g_loop, 750,
|
||||
(event_loop_timer_handler) terminate_event_loop_callback,
|
||||
@@ -764,6 +779,7 @@ const char *subscribe_object_not_present_context =
|
||||
|
||||
void subscribe_object_not_present_object_available_callback(
|
||||
object_id object_id,
|
||||
int64_t data_size,
|
||||
int manager_count,
|
||||
const char *manager_vector[],
|
||||
void *user_context) {
|
||||
@@ -781,7 +797,7 @@ TEST subscribe_object_not_present_test(void) {
|
||||
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
|
||||
};
|
||||
object_table_subscribe_to_notifications(
|
||||
db, subscribe_object_not_present_object_available_callback,
|
||||
db, false, subscribe_object_not_present_object_available_callback,
|
||||
(void *) subscribe_object_not_present_context, &retry, NULL, (void *) db);
|
||||
/* Install handler for terminating the event loop. */
|
||||
event_loop_add_timer(g_loop, 750,
|
||||
@@ -813,16 +829,26 @@ int subscribe_object_available_later_succeeded = 0;
|
||||
|
||||
void subscribe_object_available_later_object_available_callback(
|
||||
object_id object_id,
|
||||
int64_t data_size,
|
||||
int manager_count,
|
||||
const char *manager_vector[],
|
||||
void *user_context) {
|
||||
CHECK(user_context == (void *) subscribe_object_available_later_context);
|
||||
subscribe_object_present_context_t *myctx =
|
||||
(subscribe_object_present_context_t *) user_context;
|
||||
CHECK(myctx->data_size == data_size);
|
||||
CHECK(strcmp(myctx->teststr, subscribe_object_available_later_context) == 0);
|
||||
/* Make sure the callback is only called once. */
|
||||
subscribe_object_available_later_succeeded += 1;
|
||||
CHECK(manager_count == 1);
|
||||
}
|
||||
|
||||
TEST subscribe_object_available_later_test(void) {
|
||||
int64_t data_size = 0xF1F0;
|
||||
subscribe_object_present_context_t *myctx =
|
||||
malloc(sizeof(subscribe_object_present_context_t));
|
||||
myctx->teststr = subscribe_object_available_later_context;
|
||||
myctx->data_size = data_size;
|
||||
|
||||
g_loop = event_loop_create();
|
||||
db_handle *db =
|
||||
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 11236);
|
||||
@@ -832,9 +858,8 @@ TEST subscribe_object_available_later_test(void) {
|
||||
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
|
||||
};
|
||||
object_table_subscribe_to_notifications(
|
||||
db, subscribe_object_available_later_object_available_callback,
|
||||
(void *) subscribe_object_available_later_context, &retry, NULL,
|
||||
(void *) db);
|
||||
db, false, subscribe_object_available_later_object_available_callback,
|
||||
(void *) myctx, &retry, NULL, (void *) db);
|
||||
/* Install handler for terminating the event loop. */
|
||||
event_loop_add_timer(g_loop, 750,
|
||||
(event_loop_timer_handler) terminate_event_loop_callback,
|
||||
@@ -852,7 +877,8 @@ TEST subscribe_object_available_later_test(void) {
|
||||
event_loop_run(g_loop);
|
||||
|
||||
ASSERT_EQ(subscribe_object_available_later_succeeded, 0);
|
||||
object_table_add(db, id, 0, (unsigned char *) NIL_DIGEST, &retry, NULL, NULL);
|
||||
object_table_add(db, id, data_size, (unsigned char *) NIL_DIGEST, &retry,
|
||||
NULL, NULL);
|
||||
/* Install handler for terminating the event loop. */
|
||||
event_loop_add_timer(g_loop, 750,
|
||||
(event_loop_timer_handler) terminate_event_loop_callback,
|
||||
@@ -864,6 +890,57 @@ TEST subscribe_object_available_later_test(void) {
|
||||
destroy_outstanding_callbacks(g_loop);
|
||||
event_loop_destroy(g_loop);
|
||||
ASSERT_EQ(subscribe_object_available_later_succeeded, 1);
|
||||
/* Reset the global variable before exiting this unit test. */
|
||||
subscribe_object_available_later_succeeded = 0;
|
||||
free(myctx);
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST subscribe_object_available_subscribe_all(void) {
|
||||
int64_t data_size = 0xF1F0;
|
||||
subscribe_object_present_context_t myctx = {
|
||||
subscribe_object_available_later_context, data_size};
|
||||
g_loop = event_loop_create();
|
||||
db_handle *db =
|
||||
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 11236);
|
||||
db_attach(db, g_loop, false);
|
||||
unique_id id = globally_unique_id();
|
||||
retry_info retry = {
|
||||
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
|
||||
};
|
||||
object_table_subscribe_to_notifications(
|
||||
db, true, subscribe_object_available_later_object_available_callback,
|
||||
(void *) &myctx, &retry, NULL, (void *) db);
|
||||
/* Install handler for terminating the event loop. */
|
||||
event_loop_add_timer(g_loop, 750,
|
||||
(event_loop_timer_handler) terminate_event_loop_callback,
|
||||
NULL);
|
||||
/* Run the event loop to do the subscribe. */
|
||||
event_loop_run(g_loop);
|
||||
|
||||
/* At this point we don't expect any object notifications received. */
|
||||
ASSERT_EQ(subscribe_object_available_later_succeeded, 0);
|
||||
object_table_add(db, id, data_size, (unsigned char *) NIL_DIGEST, &retry,
|
||||
NULL, NULL);
|
||||
/* Install handler to terminate event loop after 750ms. */
|
||||
event_loop_add_timer(g_loop, 750,
|
||||
(event_loop_timer_handler) terminate_event_loop_callback,
|
||||
NULL);
|
||||
/* Run the event loop to do the object table add. */
|
||||
event_loop_run(g_loop);
|
||||
/* At this point we assume that object table add completed. */
|
||||
|
||||
db_disconnect(db);
|
||||
destroy_outstanding_callbacks(g_loop);
|
||||
event_loop_destroy(g_loop);
|
||||
/* Assert that the object table add completed and notification callback fired.
|
||||
*/
|
||||
printf("subscribe_all object info test: callback fired: %d times\n",
|
||||
subscribe_object_available_later_succeeded);
|
||||
fflush(stdout);
|
||||
ASSERT_EQ(subscribe_object_available_later_succeeded, 1);
|
||||
/* Reset the global variable before exiting this unit test. */
|
||||
subscribe_object_available_later_succeeded = 0;
|
||||
PASS();
|
||||
}
|
||||
|
||||
@@ -954,6 +1031,7 @@ SUITE(object_table_tests) {
|
||||
RUN_REDIS_TEST(subscribe_object_present_test);
|
||||
RUN_REDIS_TEST(subscribe_object_not_present_test);
|
||||
RUN_REDIS_TEST(subscribe_object_available_later_test);
|
||||
RUN_REDIS_TEST(subscribe_object_available_subscribe_all);
|
||||
// RUN_REDIS_TEST(subscribe_object_info_success_test);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user