mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 06:38:14 +08:00
Feature/downstream aggregation (#248)
* started messing around with this on the train last night * mega hacking away to change middleware into Ocelot iddleware * scoped data repo back in * broken commit getting tests working * another broken commit farting around with tests * all unit tests passing again * mw pipeline for ocelot...still loads of hacks but getting there now to get acceptance tests working, then fix config so you can have aggregate and then imlement multiplexer, then mapping to response...loads to do * all tests passing before aggregation feature implemented * removed all the request middleware stuff we dont need it * updated how errors work...tho i think there could be edge case here when aggregating because one downstream could error and this would effect another * removed multiplexer so you dont have to send route down, this isnt very thread safe...sigh * hacking around getting the config for aggregates in, this might change * refactored builder and unit tests passing now * Updated a bunch of ports for tests * plugged in code to create reroutes that are aggregates * made multiplexer a class * hacked test to death * simple aggregator done, initial validation done * removed request id from context, it is still specific for http request * now aggregates to json always * docs for aggregate reroutes * Updated docs
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@ -336,7 +338,7 @@ namespace Ocelot.AcceptanceTests
|
||||
/// <summary>
|
||||
/// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
|
||||
/// </summary>
|
||||
public void GivenOcelotIsRunning(OcelotMiddlewareConfiguration ocelotMiddlewareConfig)
|
||||
public void GivenOcelotIsRunning(OcelotPipelineConfiguration ocelotPipelineConfig)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
@ -373,7 +375,7 @@ namespace Ocelot.AcceptanceTests
|
||||
})
|
||||
.Configure(a =>
|
||||
{
|
||||
a.UseOcelot(ocelotMiddlewareConfig).Wait();
|
||||
a.UseOcelot(ocelotPipelineConfig).Wait();
|
||||
}));
|
||||
|
||||
_ocelotClient = _ocelotServer.CreateClient();
|
||||
@ -552,7 +554,6 @@ namespace Ocelot.AcceptanceTests
|
||||
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
|
||||
}
|
||||
|
||||
|
||||
public void ThenTheStatusCodeShouldBe(int expectedHttpStatusCode)
|
||||
{
|
||||
var responseStatusCode = (int)_response.StatusCode;
|
||||
@ -579,5 +580,51 @@ namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
_response.Content.Headers.ContentLength.ShouldBe(expected);
|
||||
}
|
||||
|
||||
public void WhenIMakeLotsOfDifferentRequestsToTheApiGateway()
|
||||
{
|
||||
int numberOfRequests = 100;
|
||||
var aggregateUrl = "/";
|
||||
var aggregateExpected = "{\"Laura\":{Hello from Laura},\"Tom\":{Hello from Tom}}";
|
||||
var tomUrl = "/tom";
|
||||
var tomExpected = "{Hello from Tom}";
|
||||
var lauraUrl = "/laura";
|
||||
var lauraExpected = "{Hello from Laura}";
|
||||
var random = new Random();
|
||||
|
||||
var aggregateTasks = new Task[numberOfRequests];
|
||||
|
||||
for (int i = 0; i < numberOfRequests; i++)
|
||||
{
|
||||
aggregateTasks[i] = Fire(aggregateUrl, aggregateExpected, random);
|
||||
}
|
||||
|
||||
var tomTasks = new Task[numberOfRequests];
|
||||
|
||||
for (int i = 0; i < numberOfRequests; i++)
|
||||
{
|
||||
tomTasks[i] = Fire(tomUrl, tomExpected, random);
|
||||
}
|
||||
|
||||
var lauraTasks = new Task[numberOfRequests];
|
||||
|
||||
for (int i = 0; i < numberOfRequests; i++)
|
||||
{
|
||||
lauraTasks[i] = Fire(lauraUrl, lauraExpected, random);
|
||||
}
|
||||
|
||||
Task.WaitAll(lauraTasks);
|
||||
Task.WaitAll(tomTasks);
|
||||
Task.WaitAll(aggregateTasks);
|
||||
}
|
||||
|
||||
private async Task Fire(string url, string expectedBody, Random random)
|
||||
{
|
||||
var request = new HttpRequestMessage(new HttpMethod("GET"), url);
|
||||
await Task.Delay(random.Next(0, 2));
|
||||
var response = await _ocelotClient.SendAsync(request);
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
content.ShouldBe(expectedBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user