1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18
19 #include <grpc/status.h>
20
21 #include <memory>
22
23 #include "gtest/gtest.h"
24 #include "src/core/util/time.h"
25 #include "test/core/end2end/end2end_tests.h"
26
27 namespace grpc_core {
28 namespace {
29
CORE_END2END_TEST(CoreEnd2endTest,TrailingMetadata)30 CORE_END2END_TEST(CoreEnd2endTest, TrailingMetadata) {
31 auto c = NewClientCall("/foo").Timeout(Duration::Minutes(1)).Create();
32 IncomingStatusOnClient server_status;
33 IncomingMetadata server_initial_metadata;
34 IncomingMessage server_message;
35 c.NewBatch(1)
36 .SendInitialMetadata({{"key1", "val1"}, {"key2", "val2"}})
37 .SendMessage("hello world")
38 .SendCloseFromClient()
39 .RecvInitialMetadata(server_initial_metadata)
40 .RecvMessage(server_message)
41 .RecvStatusOnClient(server_status);
42 auto s = RequestCall(101);
43 Expect(101, true);
44 Step();
45 IncomingMessage client_message;
46 s.NewBatch(102)
47 .SendInitialMetadata({{"key3", "val3"}, {"key4", "val4"}})
48 .RecvMessage(client_message);
49 Expect(102, true);
50 Step();
51 IncomingCloseOnServer client_close;
52 s.NewBatch(103)
53 .RecvCloseOnServer(client_close)
54 .SendMessage("hello you")
55 .SendStatusFromServer(GRPC_STATUS_OK, "xyz",
56 {{"key5", "val5"}, {"key6", "val6"}});
57 Expect(103, true);
58 Expect(1, true);
59 Step();
60 EXPECT_EQ(server_status.status(), GRPC_STATUS_OK);
61 EXPECT_EQ(server_status.message(), "xyz");
62 EXPECT_EQ(client_message.payload(), "hello world");
63 EXPECT_EQ(server_message.payload(), "hello you");
64 EXPECT_EQ(s.GetInitialMetadata("key1"), "val1");
65 EXPECT_EQ(s.GetInitialMetadata("key2"), "val2");
66 EXPECT_EQ(server_initial_metadata.Get("key3"), "val3");
67 EXPECT_EQ(server_initial_metadata.Get("key4"), "val4");
68 EXPECT_EQ(server_status.GetTrailingMetadata("key5"), "val5");
69 EXPECT_EQ(server_status.GetTrailingMetadata("key6"), "val6");
70 }
71
72 } // namespace
73 } // namespace grpc_core
74