Skip to content

Commit

Permalink
moved some things out of shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ligtenberg committed Feb 7, 2024
1 parent a4845e5 commit b9b2520
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/API/CloudRepublic.BenchMark.API.V2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
.ConfigureRefresh(refreshOptions =>
{
refreshOptions.Register("BenchMarkTests:Sentinel", refreshAll: true)
.SetCacheExpiration(TimeSpan.FromSeconds(30));
.SetCacheExpiration(TimeSpan.FromSeconds(200));
});
});
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CloudRepublic.BenchMark.Application.Models;

namespace CloudRepublic.BenchMark.Orchestrator.V2.Interfaces;

public interface IBenchMarkService
{
/// <summary>
/// Starts the client and makes the Request
/// </summary>
/// <param name="clientName"></param>
/// <returns></returns>
Task<BenchMarkResponse> RunBenchMarkAsync(BenchMarkType benchMarkType, int CallPositionNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Diagnostics;
using CloudRepublic.BenchMark.Application.Models;
using CloudRepublic.BenchMark.Orchestrator.V2.Interfaces;

namespace CloudRepublic.BenchMark.Orchestrator.V2.Services;

public class BenchMarkService : IBenchMarkService
{
private readonly IHttpClientFactory _httpClientFactory;

public BenchMarkService(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public async Task<BenchMarkResponse> RunBenchMarkAsync(BenchMarkType benchMarkType, int CallPositionNumber)
{
var client = _httpClientFactory.CreateClient("benchmarkTester");
try
{
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, benchMarkType.TestEndpoint);

requestMessage.Headers.Add(benchMarkType.AuthenticationHeaderName, benchMarkType.AuthenticationHeaderValue);

var stopWatch = Stopwatch.StartNew();
var response = await client.SendAsync(requestMessage);
var result = stopWatch.ElapsedMilliseconds;

return new BenchMarkResponse(response.IsSuccessStatusCode, (int)response.StatusCode, result, await response.Content.ReadAsStringAsync(), CallPositionNumber);
}
catch (Exception)
{
return new BenchMarkResponse(false, 0, 0, null, CallPositionNumber);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace CloudRepublic.BenchMark.Application;

public static class IServiceCollectionExtensions
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddBenchMarkData(this IServiceCollection services, string sectionKey, TokenCredential tokenCredential)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
Expand All @@ -11,15 +10,8 @@

namespace CloudRepublic.BenchMark.Data;

public class BenchMarkResultRepository : IBenchMarkResultRepository
public class BenchMarkResultRepository(TableClient tableClient) : IBenchMarkResultRepository
{
private readonly TableClient _tableClient;

public BenchMarkResultRepository(TableClient tableClient)
{
_tableClient = tableClient;
}

public async Task AddBenchMarkResultAsync(BenchMarkResult benchMarkResult)
{
var entity = new BenchMarkResultEntity
Expand All @@ -29,13 +21,13 @@ public async Task AddBenchMarkResultAsync(BenchMarkResult benchMarkResult)
RecordJson = JsonSerializer.Serialize(benchMarkResult, BenchMarkResultSerializer.Default.BenchMarkResult)
};

await _tableClient.AddEntityAsync(entity);
await tableClient.AddEntityAsync(entity);
}

public async Task<IEnumerable<BenchMarkResult>> GetBenchMarkResultsAsync(CloudProvider provider, HostEnvironment environment, Runtime runtime, Language language, string sku, int year, int month, int day)
{
var partitionKey = BuildPartitionKey(provider, environment, runtime, language, sku, year, month, day);
var results = _tableClient.QueryAsync<BenchMarkResultEntity>((x) => x.PartitionKey == partitionKey);
var results = tableClient.QueryAsync<BenchMarkResultEntity>((x) => x.PartitionKey == partitionKey);

if (results is null)
{
Expand Down

0 comments on commit b9b2520

Please sign in to comment.