Skip to content

Commit

Permalink
Accessing via default url
Browse files Browse the repository at this point in the history
  • Loading branch information
wxf committed Sep 1, 2020
1 parent d50f3fa commit 4eea737
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/brpc_server_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,16 @@ TEST_F(ServerTest, restful_mapping) {
" /v1/*/* => Echo"));
ASSERT_EQ(0u, server9.service_count());

// default url access
brpc::Server server10;
ASSERT_EQ(0, server10.AddService(
&service_v1,
brpc::SERVER_DOESNT_OWN_SERVICE,
"/v1/echo => Echo",
true));
ASSERT_EQ(1u, server10.service_count());
ASSERT_FALSE(server10._global_restful_map);

// Access services
ASSERT_EQ(0, server1.Start(port, NULL));
brpc::Channel http_channel;
Expand Down Expand Up @@ -867,6 +877,31 @@ TEST_F(ServerTest, restful_mapping) {
server1.Stop(0);
server1.Join();

ASSERT_EQ(0, server10.Start(port, NULL));

// access v1.Echo via /v1/echo.
cntl.Reset();
cntl.http_request().uri() = "/v1/echo";
cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
cntl.request_attachment().append("{\"message\":\"foo\"}");
http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
ASSERT_EQ(12, service_v1.ncalled.load());
ASSERT_EQ("{\"message\":\"foo_v1\"}", cntl.response_attachment());

// access v1.Echo via default url
cntl.Reset();
cntl.http_request().uri() = "/EchoService/Echo";
cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
cntl.request_attachment().append("{\"message\":\"foo\"}");
http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
ASSERT_EQ(13, service_v1.ncalled.load());
ASSERT_EQ("{\"message\":\"foo_v1\"}", cntl.response_attachment());

server10.Stop(0);
server10.Join();

// Removing the service should update _global_restful_map.
ASSERT_EQ(0, server1.RemoveService(&service_v1));
ASSERT_EQ(0u, server1.service_count());
Expand Down

0 comments on commit 4eea737

Please sign in to comment.