Browse Source

1. Add .bazelignore and add bazel in ci.yml;
2. Update helloworld.proto for trpc tutorial;
3. Replace ctx->successs() with ctx->get_status_code() in unittest;

holmes1412 9 months ago
parent
commit
e4aa0a3909

+ 2 - 0
.bazelignore

@@ -0,0 +1,2 @@
+./third_party/snappy/third_party/benchmark
+./third_party/snappy/third_party/googletest

+ 19 - 13
.github/workflows/ci.yml

@@ -1,39 +1,35 @@
-name: ci build                                                                  
+name: ci build
 
-on:                                                                             
+on:
   push:
     branches: [ master ]
   pull_request:
     branches: [ master ]
 
-jobs:                                                                           
-  build:
+jobs:
 
+  ubuntu-cmake:
+    name: ubuntu
     runs-on: ubuntu-latest
 
     steps:
-    - uses: actions/checkout@v2
-
+    - uses: actions/checkout@master
     - name: install deps
       run: |
         sudo apt-get update
         sudo apt-get install -y libprotobuf-dev protobuf-compiler libgtest-dev valgrind
-
     - name: update submodules
       run: git submodule update --init --recursive
-
     - name: make
       run: make -j4
-
     - name: make tutorial
       run: make tutorial -j4
-
     - name: make check
       run: make check -j4
-
     - name: make install
       run: sudo make install
-  test:
+
+  fedora-cmake:
     name: fedora
     runs-on: ubuntu-latest
     
@@ -44,7 +40,7 @@ jobs:
           sudo apt-get -y install podman
           podman pull fedora:rawhide
       - name: Get source
-        uses: actions/checkout@v3
+        uses: actions/checkout@master
         with:
           path: 'workflow'
       - name: Create container and run tests
@@ -65,3 +61,13 @@ jobs:
               echo 'RUN make tutorial'
           } > podmanfile
           podman build --tag fedorarawhide -f ./podmanfile
+
+  ubuntu-bazel:
+    name: bazel
+    runs-on: ubuntu-latest
+
+    steps:
+    - uses: actions/checkout@master
+    - name: bazel build
+      run: bazel build ...
+

+ 1 - 0
WORKSPACE

@@ -32,3 +32,4 @@ new_git_repository(
     build_file = "@//third_party:snappy.BUILD",
     tag = "1.1.9",
     remote = "https://github.com/google/snappy.git")
+

+ 4 - 8
test/unittest.cc

@@ -89,9 +89,7 @@ void test_pb(SERVER& server)
 	req1.set_a(123);
 	req1.set_b(456);
 	client.Add(&req1, [&client, &wg](AddResponse *response, RPCContext *ctx) {
-		fprintf(stderr, "success : %d status : %d error : %d\n",
-				ctx->success(), ctx->get_status_code(), ctx->get_error());
-		EXPECT_EQ(ctx->success(), true);
+		EXPECT_EQ(ctx->get_status_code(), RPCStatusOK);
 		if (ctx->success())
 		{
 			EXPECT_EQ(response->c(), 123 + 456);
@@ -101,7 +99,7 @@ void test_pb(SERVER& server)
 			req2.set_str("hello world!");
 			req2.set_idx(6);
 			client.Substr(&req2, [&wg](SubstrResponse *response, RPCContext *ctx) {
-				EXPECT_EQ(ctx->success(), true);
+				EXPECT_EQ(ctx->get_status_code(), RPCStatusOK);
 				EXPECT_TRUE(response->str() == "world!");
 				wg.done();
 			});
@@ -148,9 +146,7 @@ void test_thrift(SERVER& server)
 	req1.a = 123;
 	req1.b = 456;
 	client.add(&req1, [&client, &wg](TestThrift::addResponse *response, RPCContext *ctx) {
-		fprintf(stderr, "success : %d status : %d error : %d\n",
-				ctx->success(), ctx->get_status_code(), ctx->get_error());
-		EXPECT_EQ(ctx->success(), true);
+		EXPECT_EQ(ctx->get_status_code(), RPCStatusOK);
 		if (ctx->success())
 		{
 			EXPECT_EQ(response->result, 123 + 456);
@@ -161,7 +157,7 @@ void test_thrift(SERVER& server)
 			req2.idx = 6;
 			req2.length = -1;
 			client.substr(&req2, [&wg](TestThrift::substrResponse *response, RPCContext *ctx) {
-				EXPECT_EQ(ctx->success(), true);
+				EXPECT_EQ(ctx->get_status_code(), RPCStatusOK);
 				EXPECT_TRUE(response->result == "world!");
 				wg.done();
 			});

+ 1 - 1
tutorial/helloworld.proto

@@ -4,7 +4,7 @@ package trpc.test.helloworld;
 
 service Greeter {
   rpc SayHello (HelloRequest) returns (HelloReply) {}
-//  rpc Route (HelloRequest) returns (HelloReply) {}
+  rpc SayHi (HelloRequest) returns (HelloReply) {}
 }
 
 message HelloRequest {

+ 10 - 1
tutorial/tutorial-11-trpc_pb_server.cc

@@ -30,11 +30,19 @@ public:
 	void SayHello(HelloRequest *req, HelloReply *resp, RPCContext *ctx) override
 	{
 		ctx->set_compress_type(RPCCompressGzip);
-		resp->set_msg("This is SRPC framework TRPC protocol. Hi back.");
+		resp->set_msg("This is SRPC framework TRPC protocol. Hello back.");
 
 		printf("Server SayHello()\nget_req:\n%s\nset_resp:\n%s\n",
 		req->DebugString().c_str(), resp->DebugString().c_str());
 	}
+
+	void SayHi(HelloRequest *req, HelloReply *resp, RPCContext *ctx) override
+	{
+		resp->set_msg("This is SRPC framework TRPC protocol. Hi back.");
+
+		printf("Server SayHi()\nget_req:\n%s\nset_resp:\n%s\n",
+		req->DebugString().c_str(), resp->DebugString().c_str());
+	}
 };
 
 static void sig_handler(int signo)
@@ -55,6 +63,7 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("SRPC framework TRPC server running on 1412...\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 2
tutorial/tutorial-12-trpc_pb_client.cc

@@ -45,8 +45,8 @@ int main()
 	HelloReply sync_resp;
 	RPCSyncContext sync_ctx;
 
-	sync_req.set_msg("Hello, trpc server. This is srpc framework trpc client!");
-	client.SayHello(&sync_req, &sync_resp, &sync_ctx);
+	sync_req.set_msg("Hi, trpc server. This is srpc framework trpc client!");
+	client.SayHi(&sync_req, &sync_resp, &sync_ctx);
 
 	if (sync_ctx.success)
 		printf("%s\n", sync_resp.DebugString().c_str());

+ 12 - 2
tutorial/tutorial-13-trpc_http_server.cc

@@ -29,10 +29,19 @@ class GreeterServiceImpl : public Greeter::Service
 public:
 	void SayHello(HelloRequest *req, HelloReply *resp, RPCContext *ctx) override
 	{
-		resp->set_msg("This is SRPC framework TRPCHttp protocol. Hi back.");
+		ctx->set_compress_type(RPCCompressGzip);
+		resp->set_msg("This is SRPC framework TRPC protocol. Hello back.");
 
 		printf("Server SayHello()\nget_req:\n%s\nset_resp:\n%s\n",
-				req->DebugString().c_str(), resp->DebugString().c_str());
+		req->DebugString().c_str(), resp->DebugString().c_str());
+	}
+
+	void SayHi(HelloRequest *req, HelloReply *resp, RPCContext *ctx) override
+	{
+		resp->set_msg("This is SRPC framework TRPC protocol. Hi back.");
+
+		printf("Server SayHi()\nget_req:\n%s\nset_resp:\n%s\n",
+		req->DebugString().c_str(), resp->DebugString().c_str());
 	}
 };
 
@@ -54,6 +63,7 @@ int main()
 
 	if (server.start(1412) == 0)
 	{
+		printf("SRPC framework TRPCHttp server running on 1412...\n");
 		wait_group.wait();
 		server.stop();
 	}

+ 2 - 2
tutorial/tutorial-14-trpc_http_client.cc

@@ -45,8 +45,8 @@ int main()
 	HelloReply sync_resp;
 	RPCSyncContext sync_ctx;
 
-	sync_req.set_msg("Hello, trpc-http server. This is srpc framework trpc-http client!");
-	client.SayHello(&sync_req, &sync_resp, &sync_ctx);
+	sync_req.set_msg("Hi, trpc-http server. This is srpc framework trpc-http client!");
+	client.SayHi(&sync_req, &sync_resp, &sync_ctx);
 	if (sync_ctx.success)
 		printf("%s\n", sync_resp.DebugString().c_str());
 	else