aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2016-02-19 13:30:23 -0800
committerGravatar yang-g <yangg@google.com>2016-02-19 13:30:23 -0800
commita4598b4c47694b67cad94ccdb9385ec20940cf4c (patch)
tree2a866abb8e1fec390bd02f309667d238ff6f7585
parente1711624e1ce76545af09947c89ffd761a413051 (diff)
fix impl and test about host
-rw-r--r--src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs6
-rw-r--r--src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs44
-rw-r--r--src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs40
3 files changed, 34 insertions, 56 deletions
diff --git a/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs b/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
index 7956f33524..c3fac05324 100644
--- a/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
+++ b/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
@@ -79,16 +79,16 @@ namespace Grpc.HealthCheck.Tests
[Test]
public void ServiceIsRunning()
{
- serviceImpl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
+ serviceImpl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
- var response = client.Check(new HealthCheckRequest { Host = "", Service = "" });
+ var response = client.Check(new HealthCheckRequest { Service = "" });
Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, response.Status);
}
[Test]
public void ServiceDoesntExist()
{
- Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => client.Check(new HealthCheckRequest { Host = "", Service = "nonexistent.service" }));
+ Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => client.Check(new HealthCheckRequest { Service = "nonexistent.service" }));
}
// TODO(jtattermusch): add test with timeout once timeouts are supported
diff --git a/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs b/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs
index b86d511b16..47e4b7c2a7 100644
--- a/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs
+++ b/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs
@@ -50,58 +50,56 @@ namespace Grpc.HealthCheck.Tests
public void SetStatus()
{
var impl = new HealthServiceImpl();
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "", ""));
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, ""));
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.NOT_SERVING);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NOT_SERVING, GetStatusHelper(impl, "", ""));
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.NOT_SERVING);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NOT_SERVING, GetStatusHelper(impl, ""));
- impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "virtual-host", ""));
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, ""));
- impl.SetStatus("virtual-host", "grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.SERVING);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "virtual-host", "grpc.test.TestService"));
+ impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.SERVING);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "grpc.test.TestService"));
}
[Test]
public void ClearStatus()
{
var impl = new HealthServiceImpl();
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
- impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
+ impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
- impl.ClearStatus("", "");
+ impl.ClearStatus("");
- Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => GetStatusHelper(impl, "", ""));
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "virtual-host", ""));
+ Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => GetStatusHelper(impl, ""));
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "grpc.test.TestService"));
}
[Test]
public void ClearAll()
{
var impl = new HealthServiceImpl();
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
- impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
+ impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
impl.ClearAll();
- Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "", ""));
- Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "virtual-host", ""));
+ Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, ""));
+ Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "grpc.test.TestService"));
}
[Test]
public void NullsRejected()
{
var impl = new HealthServiceImpl();
- Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, "", HealthCheckResponse.Types.ServingStatus.SERVING));
- Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus("", null, HealthCheckResponse.Types.ServingStatus.SERVING));
+ Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, HealthCheckResponse.Types.ServingStatus.SERVING));
- Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null, ""));
- Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus("", null));
+ Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null));
}
- private static HealthCheckResponse.Types.ServingStatus GetStatusHelper(HealthServiceImpl impl, string host, string service)
+ private static HealthCheckResponse.Types.ServingStatus GetStatusHelper(HealthServiceImpl impl, string service)
{
- return impl.Check(new HealthCheckRequest { Host = host, Service = service }, null).Result.Status;
+ return impl.Check(new HealthCheckRequest { Service = service }, null).Result.Status;
}
}
}
diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
index e93b9b96dc..21482b302b 100644
--- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
+++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
@@ -54,38 +54,36 @@ namespace Grpc.HealthCheck
public class HealthServiceImpl : Grpc.Health.V1.Health.IHealth
{
private readonly object myLock = new object();
- private readonly Dictionary<Key, HealthCheckResponse.Types.ServingStatus> statusMap =
- new Dictionary<Key, HealthCheckResponse.Types.ServingStatus>();
+ private readonly Dictionary<string, HealthCheckResponse.Types.ServingStatus> statusMap =
+ new Dictionary<string, HealthCheckResponse.Types.ServingStatus>();
/// <summary>
- /// Sets the health status for given host and service.
+ /// Sets the health status for given service.
/// </summary>
- /// <param name="host">The host. Cannot be null.</param>
/// <param name="service">The service. Cannot be null.</param>
/// <param name="status">the health status</param>
- public void SetStatus(string host, string service, HealthCheckResponse.Types.ServingStatus status)
+ public void SetStatus(string service, HealthCheckResponse.Types.ServingStatus status)
{
lock (myLock)
{
- statusMap[CreateKey(host, service)] = status;
+ statusMap[service] = status;
}
}
/// <summary>
- /// Clears health status for given host and service.
+ /// Clears health status for given service.
/// </summary>
- /// <param name="host">The host. Cannot be null.</param>
/// <param name="service">The service. Cannot be null.</param>
- public void ClearStatus(string host, string service)
+ public void ClearStatus(string service)
{
lock (myLock)
{
- statusMap.Remove(CreateKey(host, service));
+ statusMap.Remove(service);
}
}
/// <summary>
- /// Clears statuses for all hosts and services.
+ /// Clears statuses for all services.
/// </summary>
public void ClearAll()
{
@@ -105,11 +103,10 @@ namespace Grpc.HealthCheck
{
lock (myLock)
{
- var host = request.Host;
var service = request.Service;
HealthCheckResponse.Types.ServingStatus status;
- if (!statusMap.TryGetValue(CreateKey(host, service), out status))
+ if (!statusMap.TryGetValue(service, out status))
{
// TODO(jtattermusch): returning specific status from server handler is not supported yet.
throw new RpcException(new Status(StatusCode.NotFound, ""));
@@ -117,22 +114,5 @@ namespace Grpc.HealthCheck
return Task.FromResult(new HealthCheckResponse { Status = status });
}
}
-
- private static Key CreateKey(string host, string service)
- {
- return new Key(host, service);
- }
-
- private struct Key
- {
- public Key(string host, string service)
- {
- this.Host = GrpcPreconditions.CheckNotNull(host);
- this.Service = GrpcPreconditions.CheckNotNull(service);
- }
-
- readonly string Host;
- readonly string Service;
- }
}
}