Removed unnecessary comments. Added connection counter to test.

pull/6915/head
Mark D. Roth 9 years ago
parent f5bbff9c8e
commit 9fe5ef5f9d
  1. 2
      include/grpc++/channel_filter.h
  2. 20
      src/cpp/common/channel_filter.cc
  3. 54
      test/cpp/end2end/filter_end2end_test.cc

@ -54,7 +54,6 @@
namespace grpc {
// Represents channel data.
// Note: Must be copyable.
class ChannelData {
public:
virtual ~ChannelData() {}
@ -68,7 +67,6 @@ class ChannelData {
};
// Represents call data.
// Note: Must be copyable.
class CallData {
public:
virtual ~CallData() {}

@ -37,6 +37,16 @@
namespace grpc {
//
// ChannelData
//
void ChannelData::StartTransportOp(grpc_exec_ctx *exec_ctx,
grpc_channel_element *elem,
grpc_transport_op *op) {
grpc_channel_next_op(exec_ctx, elem, op);
}
//
// CallData
//
@ -57,16 +67,6 @@ char *CallData::GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
return grpc_call_next_get_peer(exec_ctx, elem);
}
//
// ChannelData
//
void ChannelData::StartTransportOp(grpc_exec_ctx *exec_ctx,
grpc_channel_element *elem,
grpc_transport_op *op) {
grpc_channel_next_op(exec_ctx, elem, op);
}
//
// RegisterChannelFilter()
//

@ -75,20 +75,36 @@ void verify_ok(CompletionQueue* cq, int i, bool expect_ok) {
namespace {
int global_num_connections = 0;
int global_num_calls = 0;
mutex global_mu;
void IncrementCounter() {
void IncrementConnectionCounter() {
unique_lock<mutex> lock(global_mu);
++global_num_connections;
}
void ResetConnectionCounter() {
unique_lock<mutex> lock(global_mu);
global_num_connections = 0;
}
int GetConnectionCounterValue() {
unique_lock<mutex> lock(global_mu);
return global_num_connections;
}
void IncrementCallCounter() {
unique_lock<mutex> lock(global_mu);
++global_num_calls;
}
void ResetCounter() {
void ResetCallCounter() {
unique_lock<mutex> lock(global_mu);
global_num_calls = 0;
}
int GetCounterValue() {
int GetCallCounterValue() {
unique_lock<mutex> lock(global_mu);
return global_num_calls;
}
@ -97,19 +113,22 @@ int GetCounterValue() {
class ChannelDataImpl : public ChannelData {
public:
explicit ChannelDataImpl(const grpc_channel_args& args) : ChannelData(args) {}
virtual ~ChannelDataImpl() {}
ChannelDataImpl(const grpc_channel_args& args, const char* peer)
: ChannelData(args, peer) {
IncrementConnectionCounter();
}
};
class CallDataImpl : public CallData {
public:
explicit CallDataImpl(const ChannelDataImpl& channel_data)
: CallData(channel_data) {}
virtual ~CallDataImpl() {}
void StartTransportStreamOp(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
grpc_transport_stream_op* op) GRPC_OVERRIDE {
if (op->recv_initial_metadata != nullptr) IncrementCounter();
// Incrementing the counter could be done from the ctor, but we want
// to test that the individual methods are actually called correctly.
if (op->recv_initial_metadata != nullptr) IncrementCallCounter();
grpc_call_next_op(exec_ctx, elem, op);
}
};
@ -146,7 +165,8 @@ class FilterEnd2endTest : public ::testing::Test {
std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), InsecureChannelCredentials());
generic_stub_.reset(new GenericStub(channel));
ResetCounter();
ResetConnectionCounter();
ResetCallCounter();
}
void server_ok(int i) { verify_ok(srv_cq_.get(), i, true); }
@ -227,22 +247,27 @@ class FilterEnd2endTest : public ::testing::Test {
TEST_F(FilterEnd2endTest, SimpleRpc) {
ResetStub();
EXPECT_EQ(0, GetCounterValue());
EXPECT_EQ(0, GetConnectionCounterValue());
EXPECT_EQ(0, GetCallCounterValue());
SendRpc(1);
EXPECT_EQ(1, GetCounterValue());
EXPECT_EQ(1, GetConnectionCounterValue());
EXPECT_EQ(1, GetCallCounterValue());
}
TEST_F(FilterEnd2endTest, SequentialRpcs) {
ResetStub();
EXPECT_EQ(0, GetCounterValue());
EXPECT_EQ(0, GetConnectionCounterValue());
EXPECT_EQ(0, GetCallCounterValue());
SendRpc(10);
EXPECT_EQ(10, GetCounterValue());
EXPECT_EQ(1, GetConnectionCounterValue());
EXPECT_EQ(10, GetCallCounterValue());
}
// One ping, one pong.
TEST_F(FilterEnd2endTest, SimpleBidiStreaming) {
ResetStub();
EXPECT_EQ(0, GetCounterValue());
EXPECT_EQ(0, GetConnectionCounterValue());
EXPECT_EQ(0, GetCallCounterValue());
const grpc::string kMethodName(
"/grpc.cpp.test.util.EchoTestService/BidiStream");
@ -306,7 +331,8 @@ TEST_F(FilterEnd2endTest, SimpleBidiStreaming) {
EXPECT_EQ(send_response.message(), recv_response.message());
EXPECT_TRUE(recv_status.ok());
EXPECT_EQ(1, GetCounterValue());
EXPECT_EQ(1, GetCallCounterValue());
EXPECT_EQ(1, GetConnectionCounterValue());
}
} // namespace

Loading…
Cancel
Save