Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, Google Inc.
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions are
8 : * met:
9 : *
10 : * * Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * * Redistributions in binary form must reproduce the above
13 : * copyright notice, this list of conditions and the following disclaimer
14 : * in the documentation and/or other materials provided with the
15 : * distribution.
16 : * * Neither the name of Google Inc. nor the names of its
17 : * contributors may be used to endorse or promote products derived from
18 : * this software without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 : *
32 : */
33 :
34 : #ifndef TEST_QPS_SERVER_H
35 : #define TEST_QPS_SERVER_H
36 :
37 : #include "test/cpp/qps/timer.h"
38 : #include "test/cpp/qps/qpstest.grpc.pb.h"
39 :
40 : namespace grpc {
41 : namespace testing {
42 :
43 : class Server {
44 : public:
45 6 : Server() : timer_(new Timer) {}
46 6 : virtual ~Server() {}
47 :
48 12 : ServerStats Mark() {
49 12 : std::unique_ptr<Timer> timer(new Timer);
50 12 : timer.swap(timer_);
51 :
52 12 : auto timer_result = timer->Mark();
53 :
54 12 : ServerStats stats;
55 12 : stats.set_time_elapsed(timer_result.wall);
56 12 : stats.set_time_system(timer_result.system);
57 12 : stats.set_time_user(timer_result.user);
58 12 : return stats;
59 : }
60 :
61 1277846 : static bool SetPayload(PayloadType type, int size, Payload* payload) {
62 1277846 : PayloadType response_type = type;
63 : // TODO(yangg): Support UNCOMPRESSABLE payload.
64 1277846 : if (type != PayloadType::COMPRESSABLE) {
65 0 : return false;
66 : }
67 1277846 : payload->set_type(response_type);
68 1277775 : std::unique_ptr<char[]> body(new char[size]());
69 1277906 : payload->set_body(body.get(), size);
70 1278080 : return true;
71 : }
72 :
73 : private:
74 : std::unique_ptr<Timer> timer_;
75 : };
76 :
77 : std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config,
78 : int port);
79 : std::unique_ptr<Server> CreateAsyncServer(const ServerConfig& config, int port);
80 :
81 : } // namespace testing
82 : } // namespace grpc
83 :
84 : #endif
|