aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/end2end
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-02-05 13:01:33 -0800
committerGravatar Craig Tiller <ctiller@google.com>2015-02-05 13:01:33 -0800
commitbea3840476fb3d3f23dee3f535dbc08334139825 (patch)
tree418e13798ae302cf8dcbd39f66d12d0843ad7007 /test/core/end2end
parent16c39671836b3825e032c93e0a7f0dab37f7e3ac (diff)
Convert request_response_with_binary_metadata_and_payload
Diffstat (limited to 'test/core/end2end')
-rw-r--r--test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c198
1 files changed, 114 insertions, 84 deletions
diff --git a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
index daadcf619b..ec66d781e9 100644
--- a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
+++ b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
@@ -114,107 +114,137 @@ static void test_request_response_with_metadata_and_payload(
grpc_byte_buffer *response_payload =
grpc_byte_buffer_create(&response_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
- /* staggered lengths to ensure we hit various branches in base64 encode/decode
- */
- grpc_metadata meta1 = {
- "key1-bin", "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13};
- grpc_metadata meta2 = {
- "key2-bin", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
- 14};
- grpc_metadata meta3 = {
- "key3-bin",
- "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15};
- grpc_metadata meta4 = {
- "key4-bin",
- "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 16};
+ grpc_metadata meta_c[2] = {
+ {"key1-bin", "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13},
+ {"key2-bin", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
+ 14}};
+ grpc_metadata meta_s[2] = {
+ {"key3-bin",
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15},
+ {"key4-bin",
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 16}};
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", "test.google.com",
- deadline);
+ 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", "test.google.com",
+ 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", "test.google.com", deadline, "key1-bin",
- "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", "key2-bin",
- "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", NULL);
+ 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 = 2;
+ op->data.send_initial_metadata.metadata = meta_c;
+ 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);
- 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"));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_s;
+ 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);
- 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-bin",
- "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee",
- "key4-bin",
- "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
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);
+ 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, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
+ GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
+ GPR_ASSERT(contains_metadata(
+ &request_metadata_recv, "key1-bin",
+ "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc"));
+ GPR_ASSERT(contains_metadata(
+ &request_metadata_recv, "key2-bin",
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d"));
+ GPR_ASSERT(contains_metadata(
+ &initial_metadata_recv, "key3-bin",
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee"));
+ GPR_ASSERT(contains_metadata(
+ &initial_metadata_recv, "key4-bin",
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"));
+
+ 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);
- end_test(&f);
- config.tear_down_data(&f);
-
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);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {