-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ServerSide PErformance (#7807)
- Loading branch information
1 parent
0489973
commit caa77fb
Showing
11 changed files
with
287 additions
and
33 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...otnet/APIView/APIViewIntegrationTests/RepositoryTests/CosmosPullRequestRepositoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using APIViewWeb; | ||
using Microsoft.Azure.Cosmos; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
using APIViewWeb.LeanModels; | ||
using APIViewWeb.Models; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
|
||
namespace APIViewIntegrationTests.RepositoryTests | ||
{ | ||
public class CosmosPullRequestRepositoryTestsBaseFixture : IDisposable | ||
{ | ||
private IConfigurationRoot _config; | ||
private readonly CosmosClient _cosmosClient; | ||
private readonly string _cosmosDBname; | ||
public CosmosPullRequestsRepository PullRequestRepositopry { get; private set; } | ||
public CosmosReviewRepository ReviewRepository { get; private set; } | ||
|
||
public CosmosPullRequestRepositoryTestsBaseFixture() | ||
{ | ||
var _config = new ConfigurationBuilder() | ||
.AddEnvironmentVariables(prefix: "APIVIEW_") | ||
.AddUserSecrets(typeof(TestsBaseFixture).Assembly) | ||
.Build(); | ||
|
||
_cosmosDBname = "CosmosPullRequestRepositoryTestsDB"; | ||
_config["CosmosDBName"] = _cosmosDBname; | ||
|
||
_cosmosClient = new CosmosClient(_config["Cosmos:ConnectionString"]); | ||
var dataBaseResponse = _cosmosClient.CreateDatabaseIfNotExistsAsync(_config["CosmosDBName"]).Result; | ||
dataBaseResponse.Database.CreateContainerIfNotExistsAsync("Reviews", "/id").Wait(); | ||
dataBaseResponse.Database.CreateContainerIfNotExistsAsync("PullRequests", "/ReviewId").Wait(); | ||
|
||
ReviewRepository = new CosmosReviewRepository(_config, _cosmosClient); | ||
PullRequestRepositopry = new CosmosPullRequestsRepository(_config, ReviewRepository, _cosmosClient); | ||
PopulateDBWithDummyPullRequestData().Wait(); | ||
PopulateDBWithDummyReviewData().Wait(); | ||
} | ||
|
||
private async Task PopulateDBWithDummyPullRequestData() | ||
{ | ||
List<PullRequestModel> testPullRequests = new List<PullRequestModel> | ||
{ | ||
new PullRequestModel { Id = "1", ReviewId = "1", IsDeleted = false}, | ||
new PullRequestModel { Id = "2", ReviewId = "1", IsDeleted = false}, | ||
new PullRequestModel { Id = "3", ReviewId = "2", IsDeleted = false}, | ||
new PullRequestModel { Id = "4", ReviewId = "3", IsDeleted = true}, | ||
}; | ||
foreach (var pr in testPullRequests) | ||
{ | ||
await PullRequestRepositopry.UpsertPullRequestAsync(pr); | ||
} | ||
} | ||
|
||
private async Task PopulateDBWithDummyReviewData() | ||
{ | ||
List<ReviewListItemModel> testReviews = new List<ReviewListItemModel> | ||
{ | ||
new ReviewListItemModel { Id = "1", IsClosed = false}, | ||
new ReviewListItemModel { Id = "2", IsClosed = true}, | ||
new ReviewListItemModel { Id = "3", IsClosed = false} | ||
}; | ||
foreach (var review in testReviews) | ||
{ | ||
await ReviewRepository.UpsertReviewAsync(review); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_cosmosClient.GetDatabase(_cosmosDBname).DeleteAsync().Wait(); | ||
_cosmosClient.Dispose(); | ||
} | ||
} | ||
|
||
[CollectionDefinition("CosmosPullRequestRepositoryTestsCollection")] | ||
public class CosmosPullRequestRepositoryTestsCollection : ICollectionFixture<CosmosPullRequestRepositoryTestsBaseFixture> | ||
{ | ||
// This class has no code, and is never created. Its purpose is simply | ||
// to be the place to apply [CollectionDefinition] and all the | ||
// ICollectionFixture<> interfaces. | ||
} | ||
|
||
[Collection("CosmosPullRequestRepositoryTestsCollection")] | ||
public class CosmosPullRequestRepositoryTests | ||
{ | ||
private readonly CosmosPullRequestRepositoryTestsBaseFixture _fixture; | ||
|
||
public CosmosPullRequestRepositoryTests(CosmosPullRequestRepositoryTestsBaseFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task GetPullRequestAsync_By_ReviewId_ReturnsCorrectNumberOfPullRequests() | ||
{ | ||
var pullRequests = await _fixture.PullRequestRepositopry.GetPullRequestsAsync(reviewId: "1"); | ||
Assert.Equal(2, pullRequests.Count()); | ||
|
||
pullRequests = await _fixture.PullRequestRepositopry.GetPullRequestsAsync(reviewId: "2"); | ||
Assert.False(pullRequests.Any()); | ||
|
||
pullRequests = await _fixture.PullRequestRepositopry.GetPullRequestsAsync(reviewId: "3"); | ||
Assert.False(pullRequests.Any()); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/dotnet/APIView/APIViewIntegrationTests/RepositoryTests/CosmosReviewRepositoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using APIViewWeb; | ||
using Microsoft.Azure.Cosmos; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
using APIViewWeb.LeanModels; | ||
using APIViewWeb.Models; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
|
||
namespace APIViewIntegrationTests.RepositoryTests | ||
{ | ||
public class CosmosReviewRepositoryTestsBaseFixture : IDisposable | ||
{ | ||
private IConfigurationRoot _config; | ||
private readonly CosmosClient _cosmosClient; | ||
private readonly string _cosmosDBname; | ||
public CosmosReviewRepository ReviewRepository { get; private set; } | ||
|
||
public CosmosReviewRepositoryTestsBaseFixture() | ||
{ | ||
var _config = new ConfigurationBuilder() | ||
.AddEnvironmentVariables(prefix: "APIVIEW_") | ||
.AddUserSecrets(typeof(TestsBaseFixture).Assembly) | ||
.Build(); | ||
|
||
_cosmosDBname = "CosmosReviewRepositoryTestsDB"; | ||
_config["CosmosDBName"] = _cosmosDBname; | ||
|
||
_cosmosClient = new CosmosClient(_config["Cosmos:ConnectionString"]); | ||
var dataBaseResponse = _cosmosClient.CreateDatabaseIfNotExistsAsync(_config["CosmosDBName"]).Result; | ||
dataBaseResponse.Database.CreateContainerIfNotExistsAsync("Reviews", "/id").Wait(); | ||
|
||
ReviewRepository = new CosmosReviewRepository(_config, _cosmosClient); | ||
PopulateDBWithDummyReviewData().Wait(); | ||
} | ||
|
||
private async Task PopulateDBWithDummyReviewData() | ||
{ | ||
List<ReviewListItemModel> testReviews = new List<ReviewListItemModel> | ||
{ | ||
new ReviewListItemModel { Id = "1", IsClosed = false}, | ||
new ReviewListItemModel { Id = "2", IsClosed = true}, | ||
new ReviewListItemModel { Id = "3", IsClosed = false}, | ||
new ReviewListItemModel { Id = "4", IsClosed = false}, | ||
new ReviewListItemModel { Id = "5", IsClosed = false}, | ||
}; | ||
foreach (var review in testReviews) | ||
{ | ||
await ReviewRepository.UpsertReviewAsync(review); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_cosmosClient.GetDatabase(_cosmosDBname).DeleteAsync().Wait(); | ||
_cosmosClient.Dispose(); | ||
} | ||
} | ||
|
||
[CollectionDefinition("CosmosReviewRepositoryTestsCollection")] | ||
public class CosmosReviewRepositoryTestsCollection : ICollectionFixture<CosmosReviewRepositoryTestsBaseFixture> | ||
{ | ||
// This class has no code, and is never created. Its purpose is simply | ||
// to be the place to apply [CollectionDefinition] and all the | ||
// ICollectionFixture<> interfaces. | ||
} | ||
|
||
[Collection("CosmosReviewRepositoryTestsCollection")] | ||
public class CosmosReviewRepositoryTests | ||
{ | ||
private readonly CosmosReviewRepositoryTestsBaseFixture _fixture; | ||
|
||
public CosmosReviewRepositoryTests(CosmosReviewRepositoryTestsBaseFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task GetPullRequestAsync_By_ReviewId_ReturnsCorrectNumberOfPullRequests() | ||
{ | ||
var reviews = await _fixture.ReviewRepository.GetReviewsAsync(reviewIds: new List<string> { "1", "2", "3", "4" }); | ||
Assert.Equal(4, reviews.Count()); | ||
|
||
reviews = await _fixture.ReviewRepository.GetReviewsAsync(reviewIds: new List<string> { "1", "2", "3", "4", "5" }, isClosed: true); | ||
Assert.Single(reviews); | ||
|
||
reviews = await _fixture.ReviewRepository.GetReviewsAsync(reviewIds: new List<string> { "1", "2", "3", "4", "5" }, isClosed: false); | ||
Assert.Equal(4, reviews.Count()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.