private static LoadReportingGrpc.LoadReportingGrpcClient GetClient() { var client = new LoadReportingGrpc.LoadReportingGrpcClient( new Channel(Host, Port, ChannelCredentials.Insecure)); return(client); }
private async Task <int?> GetOngoingRequestCountAsync([NotNull] Channel channel, [NotNull] string serviceName) { try { _logger.LogDebug("Getting load report from {serviceName} at {channel}...", serviceName, channel); var loadRequest = new LoadReportRequest { ServiceName = serviceName }; LoadReportingGrpc.LoadReportingGrpcClient loadClient = new LoadReportingGrpc.LoadReportingGrpcClient(channel); LoadReportResponse loadReportResponse = await loadClient.ReportLoadAsync(loadRequest); return(loadReportResponse.ServerStats.CurrentRequests); } catch (Exception e) { _logger.LogDebug(e, "Error getting load report from {serviceName}: {errorMessage}", serviceName, e.Message); return(null); } }
public void CanGetExceptionForNonExistingService() { _actualLoad.ServerUtilization = _actualLoad.GetCpuUsage(); LoadReportingGrpc.LoadReportingGrpcClient client = GetClient(); Assert.Throws <RpcException>( () => client.ReportLoad(new LoadReportRequest { ServiceName = "Does not exist" })); }
public void CanReportKnownLoadRate() { LoadReportingGrpc.LoadReportingGrpcClient client = GetClient(); AssertCorrectReport(client, _actualLoad); _actualLoad.KnownLoadRate = 0.987654; var expectedLoad = _actualLoad.Clone(); AssertCorrectReport(client, expectedLoad); }
public void CanReportBasicLoad() { LoadReportingGrpc.LoadReportingGrpcClient client = GetClient(); AssertCorrectReport(client, _actualLoad); _actualLoad.ProcessCapacity = 5; _actualLoad.CurrentProcessCount = 3; _actualLoad.ServerUtilization = 12.345; // Note: The actualLoad's start time is reset on report (same instance in unit test!) var expectedLoad = _actualLoad.Clone(); AssertCorrectReport(client, expectedLoad); }
private static void AssertCorrectReport(LoadReportingGrpc.LoadReportingGrpcClient client, ServiceLoad actualLoad) { var loadResponse = client.ReportLoad(new LoadReportRequest { ServiceName = ServiceName }); Assert.NotNull(loadResponse.ServerStats); ServerStats serverStats = loadResponse.ServerStats; Assert.AreEqual(actualLoad.ProcessCapacity, serverStats.RequestCapacity); Assert.AreEqual(actualLoad.CurrentProcessCount, serverStats.CurrentRequests); Assert.AreEqual(actualLoad.ServerUtilization, serverStats.ServerUtilization); }
private static async Task <LoadReportResponse> GetLoadReport( [NotNull] ServiceLocation serviceLocation, Channel channel, TimeSpan timeout) { var loadRequest = new LoadReportRequest { Scope = serviceLocation.Scope, ServiceName = serviceLocation.ServiceName }; LoadReportingGrpc.LoadReportingGrpcClient loadClient = new LoadReportingGrpc.LoadReportingGrpcClient(channel); LoadReportResponse loadReportResponse = await TaskUtils.TimeoutAfter( GetLoadReport(loadClient, loadRequest), timeout); return(loadReportResponse); }
public void CanReportCpuLoad() { _actualLoad.ServerUtilization = _actualLoad.GetCpuUsage(); LoadReportingGrpc.LoadReportingGrpcClient client = GetClient(); AssertCorrectReport(client, _actualLoad); // Mix between 8% and 0% -> ca. 5% for (long i = 0; i < 10000000000; i++) { double stress = (double)i / (i + 123456789); } Thread.Sleep(10000); _actualLoad.ServerUtilization = _actualLoad.GetCpuUsage(); Console.WriteLine("{0} CPU: {1:0.0}%", Process.GetCurrentProcess().ProcessName, _actualLoad.ServerUtilization * 100); AssertCorrectReport(client, _actualLoad); }
private static async Task <LoadReportResponse> GetLoadReport( [NotNull] LoadReportingGrpc.LoadReportingGrpcClient loadClient, [NotNull] LoadReportRequest loadRequest) { return(await loadClient.ReportLoadAsync(loadRequest)); }