|
|
|
@ -77,16 +77,20 @@ namespace testing { |
|
|
|
|
|
|
|
|
|
std::unique_ptr<Client> CreateClient(const ClientConfig& config) { |
|
|
|
|
switch (config.client_type()) { |
|
|
|
|
case ClientType::SYNCHRONOUS_CLIENT: return CreateSynchronousClient(config); |
|
|
|
|
case ClientType::ASYNC_CLIENT: abort(); //return CreateAsyncClient(config);
|
|
|
|
|
case ClientType::SYNCHRONOUS_CLIENT: |
|
|
|
|
return CreateSynchronousClient(config); |
|
|
|
|
case ClientType::ASYNC_CLIENT: |
|
|
|
|
abort(); // return CreateAsyncClient(config);
|
|
|
|
|
} |
|
|
|
|
abort(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::unique_ptr<Server> CreateServer(const ServerConfig& config) { |
|
|
|
|
switch (config.server_type()) { |
|
|
|
|
case ServerType::SYNCHRONOUS_SERVER: return CreateSynchronousServer(config, FLAGS_server_port); |
|
|
|
|
case ServerType::ASYNC_SERVER: abort(); //return CreateAsyncServer(config, FLAGS_server_port);
|
|
|
|
|
case ServerType::SYNCHRONOUS_SERVER: |
|
|
|
|
return CreateSynchronousServer(config, FLAGS_server_port); |
|
|
|
|
case ServerType::ASYNC_SERVER: |
|
|
|
|
abort(); // return CreateAsyncServer(config, FLAGS_server_port);
|
|
|
|
|
} |
|
|
|
|
abort(); |
|
|
|
|
} |
|
|
|
@ -95,7 +99,9 @@ class WorkerImpl final : public Worker::Service { |
|
|
|
|
public: |
|
|
|
|
WorkerImpl() : acquired_(false) {} |
|
|
|
|
|
|
|
|
|
Status RunTest(ServerContext* ctx, ServerReaderWriter<ClientStatus, ClientArgs>* stream) GRPC_OVERRIDE { |
|
|
|
|
Status RunTest(ServerContext* ctx, |
|
|
|
|
ServerReaderWriter<ClientStatus, ClientArgs>* stream) |
|
|
|
|
GRPC_OVERRIDE { |
|
|
|
|
InstanceGuard g(this); |
|
|
|
|
if (!g.Acquired()) { |
|
|
|
|
return Status(RESOURCE_EXHAUSTED); |
|
|
|
@ -127,7 +133,9 @@ class WorkerImpl final : public Worker::Service { |
|
|
|
|
return Status::OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status RunServer(ServerContext* ctx, ServerReaderWriter<ServerStatus, ServerArgs>* stream) GRPC_OVERRIDE { |
|
|
|
|
Status RunServer(ServerContext* ctx, |
|
|
|
|
ServerReaderWriter<ServerStatus, ServerArgs>* stream) |
|
|
|
|
GRPC_OVERRIDE { |
|
|
|
|
InstanceGuard g(this); |
|
|
|
|
if (!g.Acquired()) { |
|
|
|
|
return Status(RESOURCE_EXHAUSTED); |
|
|
|
@ -163,8 +171,13 @@ class WorkerImpl final : public Worker::Service { |
|
|
|
|
private: |
|
|
|
|
class InstanceGuard { |
|
|
|
|
public: |
|
|
|
|
InstanceGuard(WorkerImpl* impl) : impl_(impl), acquired_(impl->TryAcquireInstance()) {} |
|
|
|
|
~InstanceGuard() { if (acquired_) { impl_->ReleaseInstance(); } } |
|
|
|
|
InstanceGuard(WorkerImpl* impl) |
|
|
|
|
: impl_(impl), acquired_(impl->TryAcquireInstance()) {} |
|
|
|
|
~InstanceGuard() { |
|
|
|
|
if (acquired_) { |
|
|
|
|
impl_->ReleaseInstance(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Acquired() const { return acquired_; } |
|
|
|
|
|
|
|
|
|