/* Constructor for channel_data */ static void init_channel_elem(grpc_channel_element *elem, const grpc_channel_args *args, grpc_mdctx *mdctx, int is_first, int is_last) { size_t i; size_t gettable_capacity = 0; /* grab pointers to our data from the channel element */ channel_data *channeld = elem->channel_data; /* The first and the last filters tend to be implemented differently to handle the case that there's no 'next' filter to call on the up or down path */ GPR_ASSERT(!is_first); GPR_ASSERT(!is_last); /* initialize members */ channeld->te_trailers = grpc_mdelem_from_strings(mdctx, "te", "trailers"); channeld->status_ok = grpc_mdelem_from_strings(mdctx, ":status", "200"); channeld->status_not_found = grpc_mdelem_from_strings(mdctx, ":status", "404"); channeld->method_post = grpc_mdelem_from_strings(mdctx, ":method", "POST"); channeld->http_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "http"); channeld->https_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "https"); channeld->grpc_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc"); channeld->path_key = grpc_mdstr_from_string(mdctx, ":path"); channeld->authority_key = grpc_mdstr_from_string(mdctx, ":authority"); channeld->host_key = grpc_mdstr_from_string(mdctx, "host"); channeld->content_type = grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc"); channeld->mdctx = mdctx; /* initialize http download support */ channeld->gettable_count = 0; channeld->gettables = NULL; for (i = 0; i < args->num_args; i++) { if (0 == strcmp(args->args[i].key, GRPC_ARG_SERVE_OVER_HTTP)) { gettable *g; gpr_slice slice; grpc_http_server_page *p = args->args[i].value.pointer.p; if (channeld->gettable_count == gettable_capacity) { gettable_capacity = GPR_MAX(gettable_capacity * 3 / 2, gettable_capacity + 1); channeld->gettables = gpr_realloc(channeld->gettables, gettable_capacity * sizeof(gettable)); } g = &channeld->gettables[channeld->gettable_count++]; g->path = grpc_mdelem_from_strings(mdctx, ":path", p->path); g->content_type = grpc_mdelem_from_strings(mdctx, "content-type", p->content_type); slice = gpr_slice_from_copied_string(p->content); g->content = grpc_byte_buffer_create(&slice, 1); gpr_slice_unref(slice); } } }
static void finish_message(grpc_call *call) { /* TODO(ctiller): this could be a lot faster if coded directly */ grpc_byte_buffer *byte_buffer = grpc_byte_buffer_create( call->incoming_message.slices, call->incoming_message.count); gpr_slice_buffer_reset_and_unref(&call->incoming_message); grpc_bbq_push(&call->incoming_queue, byte_buffer); GPR_ASSERT(call->incoming_message.count == 0); call->reading_message = 0; }
static void test_invoke_large_request(grpc_end2end_test_config config) { grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL); gpr_slice request_payload_slice = large_slice(); gpr_slice response_payload_slice = large_slice(); grpc_call *c; grpc_call *s; grpc_byte_buffer *request_payload = grpc_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer *response_payload = grpc_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = n_seconds_time(30); cq_verifier *v_client = cq_verifier_create(f.client_cq); cq_verifier *v_server = cq_verifier_create(f.server_cq); grpc_op ops[6]; grpc_op *op; grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; grpc_call_details call_details; grpc_status_code status; char *details = NULL; size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "foo.test.google.fr", deadline); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); grpc_metadata_array_init(&request_metadata_recv); grpc_call_details_init(&call_details); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = request_payload; op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata = &initial_metadata_recv; op++; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &response_payload_recv; op++; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1))); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s, &call_details, &request_metadata_recv, f.server_cq, tag(101))); cq_expect_completion(v_server, tag(101), GRPC_OP_OK); cq_verify(v_server); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = response_payload; op++; op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; op->data.send_status_from_server.status_details = "xyz"; op++; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &request_payload_recv; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102))); cq_expect_completion(v_server, tag(102), GRPC_OP_OK); cq_verify(v_server); cq_expect_completion(v_client, tag(1), GRPC_OP_OK); cq_verify(v_client); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); GPR_ASSERT(0 == strcmp(details, "xyz")); GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 0); gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_call_destroy(c); grpc_call_destroy(s); cq_verifier_destroy(v_client); cq_verifier_destroy(v_server); grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); gpr_slice_unref(request_payload_slice); gpr_slice_unref(response_payload_slice); end_test(&f); config.tear_down_data(&f); }
grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) { gpr_slice slice = gpr_slice_from_copied_buffer(string, length); grpc_byte_buffer *buffer = grpc_byte_buffer_create(&slice, 1); gpr_slice_unref(slice); return buffer; }
static void request_response_with_payload_and_call_creds( const char *test_name, grpc_end2end_test_config config, override_mode mode) { grpc_call *c; grpc_call *s; gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you"); grpc_byte_buffer *request_payload = grpc_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer *response_payload = grpc_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); grpc_end2end_test_fixture f = begin_test(config, test_name, NULL, NULL); cq_verifier *v_client = cq_verifier_create(f.client_cq); cq_verifier *v_server = cq_verifier_create(f.server_cq); grpc_op ops[6]; grpc_op *op; grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; grpc_call_details call_details; grpc_status_code status; char *details = NULL; size_t details_capacity = 0; int was_cancelled = 2; grpc_credentials *creds = NULL; c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "foo.test.google.fr", deadline); GPR_ASSERT(c); creds = grpc_iam_credentials_create(iam_token, iam_selector); GPR_ASSERT(creds != NULL); GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK); switch (mode) { case NONE: break; case OVERRIDE: grpc_credentials_release(creds); creds = grpc_iam_credentials_create(overridden_iam_token, overridden_iam_selector); GPR_ASSERT(creds != NULL); GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK); break; case DESTROY: GPR_ASSERT(grpc_call_set_credentials(c, NULL) == GRPC_CALL_OK); break; } grpc_credentials_release(creds); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); grpc_metadata_array_init(&request_metadata_recv); grpc_call_details_init(&call_details); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = request_payload; op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata = &initial_metadata_recv; op++; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &response_payload_recv; op++; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1))); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s, &call_details, &request_metadata_recv, f.server_cq, f.server_cq, tag(101))); cq_expect_completion(v_server, tag(101), GRPC_OP_OK); cq_verify(v_server); /* Cannot set creds on the server call object. */ GPR_ASSERT(grpc_call_set_credentials(s, NULL) != GRPC_CALL_OK); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = response_payload; op++; op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; op->data.send_status_from_server.status_details = "xyz"; op++; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &request_payload_recv; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102))); cq_expect_completion(v_server, tag(102), GRPC_OP_OK); cq_verify(v_server); cq_expect_completion(v_client, tag(1), GRPC_OP_OK); cq_verify(v_client); GPR_ASSERT(status == GRPC_STATUS_OK); GPR_ASSERT(0 == strcmp(details, "xyz")); GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you")); switch (mode) { case NONE: GPR_ASSERT(contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, iam_token)); GPR_ASSERT(contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, iam_selector)); break; case OVERRIDE: GPR_ASSERT(contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, overridden_iam_token)); GPR_ASSERT(contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, overridden_iam_selector)); break; case DESTROY: GPR_ASSERT(!contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, iam_token)); GPR_ASSERT(!contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, iam_selector)); GPR_ASSERT(!contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, overridden_iam_token)); GPR_ASSERT(!contains_metadata(&request_metadata_recv, GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, overridden_iam_selector)); break; } gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_call_destroy(c); grpc_call_destroy(s); cq_verifier_destroy(v_client); cq_verifier_destroy(v_server); grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); end_test(&f); config.tear_down_data(&f); }
static void test_max_message_length(grpc_end2end_test_config config) { grpc_end2end_test_fixture f; grpc_arg server_arg; grpc_channel_args server_args; grpc_call *c; grpc_call *s; cq_verifier *v_client; cq_verifier *v_server; grpc_op ops[6]; grpc_op *op; gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); grpc_byte_buffer *request_payload = grpc_byte_buffer_create(&request_payload_slice, 1); grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; grpc_call_details call_details; grpc_status_code status; char *details = NULL; size_t details_capacity = 0; int was_cancelled = 2; server_arg.key = GRPC_ARG_MAX_MESSAGE_LENGTH; server_arg.type = GRPC_ARG_INTEGER; server_arg.value.integer = 5; server_args.num_args = 1; server_args.args = &server_arg; f = begin_test(config, __FUNCTION__, NULL, &server_args); v_client = cq_verifier_create(f.client_cq); v_server = cq_verifier_create(f.server_cq); c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "foo.test.google.fr:1234", gpr_inf_future); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); grpc_metadata_array_init(&request_metadata_recv); grpc_call_details_init(&call_details); op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = request_payload; op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata = &initial_metadata_recv; op++; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1))); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s, &call_details, &request_metadata_recv, f.server_cq, f.server_cq, tag(101))); cq_expect_completion(v_server, tag(101), 1); cq_verify(v_server); op = ops; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102))); cq_expect_completion(v_server, tag(102), 1); cq_verify(v_server); cq_expect_completion(v_client, tag(1), 1); cq_verify(v_client); GPR_ASSERT(status == GRPC_STATUS_CANCELLED); GPR_ASSERT(0 == strcmp(details, "Cancelled")); GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234")); GPR_ASSERT(was_cancelled == 1); gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_call_destroy(c); grpc_call_destroy(s); cq_verifier_destroy(v_client); cq_verifier_destroy(v_server); end_test(&f); config.tear_down_data(&f); }
/* Cancel after accept with a writes closed, no payload */ static void test_cancel_after_accept_and_writes_closed( grpc_end2end_test_config config, cancellation_mode mode) { grpc_op ops[6]; grpc_op *op; grpc_call *c; grpc_call *s; grpc_end2end_test_fixture f = begin_test(config, "test_cancel_after_accept_and_writes_closed", NULL, NULL); gpr_timespec deadline = five_seconds_time(); cq_verifier *v_client = cq_verifier_create(f.client_cq); cq_verifier *v_server = cq_verifier_create(f.server_cq); grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; grpc_call_details call_details; grpc_status_code status; char *details = NULL; size_t details_capacity = 0; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you"); grpc_byte_buffer *request_payload = grpc_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer *response_payload = grpc_byte_buffer_create(&response_payload_slice, 1); int was_cancelled = 2; c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "foo.test.google.fr", deadline); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); grpc_metadata_array_init(&request_metadata_recv); grpc_call_details_init(&call_details); op = ops; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = request_payload; op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata = &initial_metadata_recv; op++; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &response_payload_recv; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1))); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s, &call_details, &request_metadata_recv, f.server_cq, f.server_cq, tag(2))); cq_expect_completion(v_server, tag(2), 1); cq_verify(v_server); op = ops; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &request_payload_recv; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; op++; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = response_payload; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(3))); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c)); cq_expect_completion(v_server, tag(3), 1); cq_verify(v_server); cq_expect_completion(v_client, tag(1), 1); cq_verify(v_client); GPR_ASSERT(status == mode.expect_status); GPR_ASSERT(0 == strcmp(details, mode.expect_details)); GPR_ASSERT(was_cancelled == 1); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); gpr_free(details); grpc_call_destroy(c); grpc_call_destroy(s); cq_verifier_destroy(v_client); cq_verifier_destroy(v_server); end_test(&f); config.tear_down_data(&f); }
/* Request/response with metadata and payload.*/ static void test_request_response_with_metadata_and_payload( grpc_end2end_test_config config) { grpc_call *c; grpc_call *s; gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you"); grpc_byte_buffer *request_payload = grpc_byte_buffer_create(&request_payload_slice, 1); grpc_byte_buffer *response_payload = grpc_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); grpc_metadata meta1 = {"key1", "val1", 4}; grpc_metadata meta2 = {"key2", "val2", 4}; grpc_metadata meta3 = {"key3", "val3", 4}; grpc_metadata meta4 = {"key4", "val4", 4}; grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL); cq_verifier *v_client = cq_verifier_create(f.client_cq); cq_verifier *v_server = cq_verifier_create(f.server_cq); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100))); /* byte buffer holds the slice, we can unref it already */ gpr_slice_unref(request_payload_slice); gpr_slice_unref(response_payload_slice); c = grpc_channel_create_call_old(f.client, "/foo", "foo.test.google.fr", deadline); GPR_ASSERT(c); /* add multiple metadata */ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_old(c, request_payload, tag(4), 0)); /* destroy byte buffer early to ensure async code keeps track of its contents correctly */ grpc_byte_buffer_destroy(request_payload); cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK); cq_verify(v_client); cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "foo.test.google.fr", deadline, "key1", "val1", "key2", "val2", NULL); cq_verify(v_server); grpc_call_server_accept_old(s, f.server_cq, tag(102)); /* add multiple metadata */ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0)); grpc_call_server_end_initial_metadata_old(s, 0); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5))); cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world")); cq_verify(v_server); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_old(s, response_payload, tag(6), 0)); /* destroy byte buffer early to ensure async code keeps track of its contents correctly */ grpc_byte_buffer_destroy(response_payload); cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK); cq_verify(v_server); /* fetch metadata.. */ cq_expect_client_metadata_read(v_client, tag(2), "key3", "val3", "key4", "val4", NULL); cq_verify(v_client); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7))); cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you")); cq_verify(v_client); GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8))); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old( s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9))); cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK); cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL); cq_verify(v_client); cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK); cq_expect_finished(v_server, tag(102), NULL); cq_verify(v_server); grpc_call_destroy(c); grpc_call_destroy(s); end_test(&f); config.tear_down_data(&f); cq_verifier_destroy(v_client); cq_verifier_destroy(v_server); }
static void test_invoke_large_request(grpc_end2end_test_config config) { grpc_call *c; grpc_call *s; gpr_slice request_payload_slice = large_slice(); grpc_byte_buffer *request_payload = grpc_byte_buffer_create(&request_payload_slice, 1); gpr_timespec deadline = n_seconds_time(30); grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL); cq_verifier *v_client = cq_verifier_create(f.client_cq); cq_verifier *v_server = cq_verifier_create(f.server_cq); /* byte buffer holds the slice, we can unref it already */ gpr_slice_unref(request_payload_slice); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100))); c = grpc_channel_create_call_old(f.client, "/foo", "foo.test.google.fr", deadline); GPR_ASSERT(c); GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_old(c, request_payload, tag(4), 0)); /* destroy byte buffer early to ensure async code keeps track of its contents correctly */ grpc_byte_buffer_destroy(request_payload); /* write should not be accepted until the server is willing to read the request (as this request is very large) */ cq_verify_empty(v_client); cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "foo.test.google.fr", deadline, NULL); cq_verify(v_server); GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_accept_old(s, f.server_cq, tag(102))); GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0)); cq_expect_client_metadata_read(v_client, tag(2), NULL); cq_verify(v_client); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5))); /* now the write can be accepted */ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK); cq_verify(v_client); cq_expect_read(v_server, tag(5), large_slice()); cq_verify(v_server); GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8))); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old( s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9))); cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK); cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL); cq_verify(v_client); cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK); cq_expect_finished(v_server, tag(102), NULL); cq_verify(v_server); grpc_call_destroy(c); grpc_call_destroy(s); cq_verifier_destroy(v_client); cq_verifier_destroy(v_server); end_test(&f); config.tear_down_data(&f); }