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.ClearStatus(null, ""));
            Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus("", null));
        }
示例#2
0
        public void NullsRejected()
        {
            var impl = new HealthServiceImpl();
            Assert.Throws(typeof(NullReferenceException), () => impl.SetStatus(null, "", HealthCheckResponse.Types.ServingStatus.SERVING));
            Assert.Throws(typeof(NullReferenceException), () => impl.SetStatus("", null, HealthCheckResponse.Types.ServingStatus.SERVING));

            Assert.Throws(typeof(NullReferenceException), () => impl.ClearStatus(null, ""));
            Assert.Throws(typeof(NullReferenceException), () => impl.ClearStatus("", null));
        }
示例#3
0
        public void ClearStatus()
        {
            var impl = new HealthServiceImpl();
            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
            impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN);

            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, "grpc.test.TestService"));
        }
        public void ClearStatus()
        {
            var impl = new HealthServiceImpl();

            impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
            impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);

            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", ""));
        }
        public void ClearStatus()
        {
            var impl = new HealthServiceImpl();
            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.Serving);
            impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.Unknown);

            impl.ClearStatus("");

            var ex = Assert.Throws<RpcException>(() => GetStatusHelper(impl, ""));
            Assert.AreEqual(StatusCode.NotFound, ex.Status.StatusCode);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Unknown, GetStatusHelper(impl, "grpc.test.TestService"));
        }
        public void ClearStatus()
        {
            var impl = new HealthServiceImpl();

            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.Serving);
            impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.Unknown);

            impl.ClearStatus("");

            var ex = Assert.Throws <RpcException>(() => GetStatusHelper(impl, ""));

            Assert.AreEqual(StatusCode.NotFound, ex.Status.StatusCode);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Unknown, GetStatusHelper(impl, "grpc.test.TestService"));
        }
        public async Task Watch()
        {
            var cts     = new CancellationTokenSource();
            var context = new TestServerCallContext(cts.Token);
            var writer  = new TestResponseStreamWriter();

            var impl     = new HealthServiceImpl();
            var callTask = impl.Watch(new HealthCheckRequest {
                Service = ""
            }, writer, context);

            // Calling Watch on a service that doesn't have a value set will initially return ServiceUnknown
            var nextWriteTask = writer.WrittenMessagesReader.ReadAsync();

            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.ServiceUnknown, (await nextWriteTask).Status);

            nextWriteTask = writer.WrittenMessagesReader.ReadAsync();
            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.Serving);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Serving, (await nextWriteTask).Status);

            nextWriteTask = writer.WrittenMessagesReader.ReadAsync();
            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.NotServing);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NotServing, (await nextWriteTask).Status);

            nextWriteTask = writer.WrittenMessagesReader.ReadAsync();
            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.Unknown);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Unknown, (await nextWriteTask).Status);

            // Setting status for a different service name will not update Watch results
            nextWriteTask = writer.WrittenMessagesReader.ReadAsync();
            impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.Serving);
            Assert.IsFalse(nextWriteTask.IsCompleted);

            impl.ClearStatus("");
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.ServiceUnknown, (await nextWriteTask).Status);

            Assert.IsFalse(callTask.IsCompleted);
            cts.Cancel();
            await callTask;
        }
        public async Task Watch_MultipleWatchesForSameService()
        {
            var cts     = new CancellationTokenSource();
            var context = new TestServerCallContext(cts.Token);
            var writer1 = new TestResponseStreamWriter();
            var writer2 = new TestResponseStreamWriter();

            var impl      = new HealthServiceImpl();
            var callTask1 = impl.Watch(new HealthCheckRequest {
                Service = ""
            }, writer1, context);
            var callTask2 = impl.Watch(new HealthCheckRequest {
                Service = ""
            }, writer2, context);

            // Calling Watch on a service that doesn't have a value set will initially return ServiceUnknown
            var nextWriteTask1 = writer1.WrittenMessagesReader.ReadAsync();
            var nextWriteTask2 = writer2.WrittenMessagesReader.ReadAsync();

            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.ServiceUnknown, (await nextWriteTask1).Status);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.ServiceUnknown, (await nextWriteTask2).Status);

            nextWriteTask1 = writer1.WrittenMessagesReader.ReadAsync();
            nextWriteTask2 = writer2.WrittenMessagesReader.ReadAsync();
            impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.Serving);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Serving, (await nextWriteTask1).Status);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.Serving, (await nextWriteTask2).Status);

            nextWriteTask1 = writer1.WrittenMessagesReader.ReadAsync();
            nextWriteTask2 = writer2.WrittenMessagesReader.ReadAsync();
            impl.ClearStatus("");
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.ServiceUnknown, (await nextWriteTask1).Status);
            Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.ServiceUnknown, (await nextWriteTask2).Status);

            cts.Cancel();
            await callTask1;
            await callTask2;
        }
        public void NullsRejected()
        {
            var impl = new HealthServiceImpl();
            Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, HealthCheckResponse.Types.ServingStatus.Serving));

            Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null));
        }