public void TestThatMultipleResponsesParse(int responses) { var parser = ResponseParser.ParserFor(ToStream(MultipleResponseBuilder(responses)).ToArray()); Assert.True(parser.HasCompleted); Assert.True(parser.HasFullResponse()); Assert.False(parser.IsMissingContent); Assert.False(parser.HasMissingContentTimeExpired((long)DateExtensions.GetCurrentMillis() + 100)); var count = 0; var bodyIterator = _uniqueBodies.GetEnumerator(); while (parser.HasFullResponse()) { ++count; var response = parser.FullResponse(); Assert.NotNull(response); Assert.True(response.Version.IsHttp1_1()); Assert.True(bodyIterator.MoveNext()); var body = bodyIterator.Current; Assert.Equal(body, response.Entity.Content); } Assert.Equal(responses, count); bodyIterator.Dispose(); }
public void TestThatServerDispatchesManyRequests() { var startTime = DateExtensions.GetCurrentMillis(); var consumeCalls = _progress.ExpectConsumeTimes(TotalRequestsResponses); var totalPairs = TotalRequestsResponses / 2; var currentConsumeCount = 0; for (var idx = 0; idx < totalPairs; ++idx) { _client.RequestWith(ToStream(PostRequestCloseFollowing(UniqueJohnDoe())).ToArray()); _client.RequestWith(ToStream(PostRequestCloseFollowing(UniqueJaneDoe())).ToArray()); var expected = currentConsumeCount + 2; while (consumeCalls.TotalWrites < expected) { _client.ProbeChannel(); } currentConsumeCount = expected; } while (consumeCalls.TotalWrites < TotalRequestsResponses) { _client.ProbeChannel(); } consumeCalls.ReadFrom <int>("completed"); _output.WriteLine("TOTAL REQUESTS-RESPONSES: {0} TIME: {1} ms", TotalRequestsResponses, DateExtensions.GetCurrentMillis() - startTime); Assert.Equal(TotalRequestsResponses, _progress.ConsumeCount.Get()); _progress.Responses.TryPeek(out var createdResponse); Assert.NotNull(createdResponse.Headers.HeaderOf(ResponseHeader.Location)); }
public ServerActor( Resources resources, Filters filters, int port, int dispatcherPoolSize) { var start = DateExtensions.GetCurrentMillis(); _filters = filters; _world = Stage.World; _requestsMissingContent = new Dictionary <string, RequestResponseHttpContext>(); _maxMessageSize = 0; try { _dispatcherPool = new AgentDispatcherPool(Stage, resources, dispatcherPoolSize); var end = DateExtensions.GetCurrentMillis(); Logger.Info($"Server {ServerName} is listening on port: {port} started in {end - start} ms"); LogResourceMappings(resources); } catch (Exception e) { var message = $"Failed to start server because: {e.Message}"; Logger.Error(message, e); throw new InvalidOperationException(message); } }
public void TestThatMultipleResponsesParse(int requests) { var parser = RequestParser.ParserFor(ToByteBuffer(MultipleRequestBuilder(requests))); Assert.True(parser.HasCompleted); Assert.True(parser.HasFullRequest()); Assert.False(parser.IsMissingContent); Assert.False(parser.HasMissingContentTimeExpired((long)DateExtensions.GetCurrentMillis() + 100)); var count = 0; var bodyIterator = _uniqueBodies.GetEnumerator(); while (parser.HasFullRequest()) { ++count; var request = parser.FullRequest(); Assert.NotNull(request); Assert.True(request.Method.IsPost()); Assert.Equal("/users", request.Uri.PathAndQuery); Assert.True(request.Version.IsHttp1_1()); Assert.True(bodyIterator.MoveNext()); var body = bodyIterator.Current; Assert.Equal(body, request.Body.Content); } Assert.Equal(requests, count); bodyIterator.Dispose(); }
public ServerActor( Resources resources, Filters filters, int port, Configuration.SizingConf sizing, Configuration.TimingConf timing, string channelMailboxTypeName) { var start = DateExtensions.GetCurrentMillis(); _filters = filters; _dispatcherPoolIndex = 0; _world = Stage.World; _requestsMissingContent = new Dictionary <string, RequestResponseHttpContext>(); _maxMessageSize = sizing.MaxMessageSize; try { _responseBufferPool = new ConsumerByteBufferPool( ElasticResourcePool <IConsumerByteBuffer, Nothing> .Config.Of(sizing.MaxBufferPoolSize), sizing.MaxMessageSize); _dispatcherPool = new IDispatcher[sizing.DispatcherPoolSize]; for (int idx = 0; idx < sizing.DispatcherPoolSize; ++idx) { _dispatcherPool[idx] = Dispatcher.StartWith(Stage, resources); } _channel = ServerRequestResponseChannelFactory.Start( Stage, Stage.World.AddressFactory.WithHighId(ChannelName), channelMailboxTypeName, this, port, ChannelName, sizing.ProcessorPoolSize, sizing.MaxBufferPoolSize, sizing.MaxMessageSize, timing.ProbeInterval, timing.ProbeTimeout); var end = DateExtensions.GetCurrentMillis(); Logger.Info($"Server {ServerName} is listening on port: {port} started in {end - start} ms"); _requestMissingContentTimeout = timing.RequestMissingContentTimeout; LogResourceMappings(resources); } catch (Exception e) { var message = $"Failed to start server because: {e.Message}"; Logger.Error(message, e); throw new InvalidOperationException(message); } }
public void TestThatTwoHundredResponsesParseNextSucceeds() { var manyRequests = MultipleRequestBuilder(200); var totalLength = manyRequests.Length; var random = new Random(); var alteringEndIndex = 1024; var parser = RequestParser.ParserFor(ToStream(manyRequests.Substring(0, alteringEndIndex)).ToArray()); var startingIndex = alteringEndIndex; while (startingIndex < totalLength) { var randomLength = random.Next(512) + 1; alteringEndIndex = startingIndex + randomLength + (int)(DateExtensions.GetCurrentMillis() % startingIndex); if (alteringEndIndex > totalLength) { alteringEndIndex = totalLength; } parser.ParseNext(ToStream(manyRequests.Substring(startingIndex, alteringEndIndex - startingIndex)).ToArray()); startingIndex = alteringEndIndex; } Assert.True(parser.HasCompleted); Assert.True(parser.HasFullRequest()); Assert.False(parser.IsMissingContent); Assert.False(parser.HasMissingContentTimeExpired((long)DateExtensions.GetCurrentMillis() + 100)); var count = 0; var bodyIterator = _uniqueBodies.GetEnumerator(); while (parser.HasFullRequest()) { ++count; var request = parser.FullRequest(); Assert.NotNull(request); Assert.True(request.Method.IsPost()); Assert.Equal("/users", request.Uri.PathAndQuery); Assert.True(request.Version.IsHttp1_1()); Assert.True(bodyIterator.MoveNext()); var body = bodyIterator.Current; Assert.Equal(body, request.Body.Content); } Assert.Equal(200, count); bodyIterator.Dispose(); }
public void TestThatSingleResponseParses() { var parser = ResponseParser.ParserFor(ToStream(JohnDoeCreated()).ToArray()); Assert.True(parser.HasCompleted); Assert.True(parser.HasFullResponse()); Assert.False(parser.IsMissingContent); Assert.False(parser.HasMissingContentTimeExpired((long)DateExtensions.GetCurrentMillis() + 100)); var response = parser.FullResponse(); Assert.NotNull(response); Assert.True(response.Version.IsHttp1_1()); Assert.Equal(JohnDoeUserSerialized, response.Entity.Content); }
public void TestThatSingleResponseParses() { var parser = RequestParser.ParserFor(ToStream(PostJohnDoeUserMessage).ToArray()); Assert.True(parser.HasCompleted); Assert.True(parser.HasFullRequest()); Assert.False(parser.IsMissingContent); Assert.False(parser.HasMissingContentTimeExpired((long)DateExtensions.GetCurrentMillis() + 100)); var request = parser.FullRequest(); Assert.NotNull(request); Assert.True(request.Method.IsPost()); Assert.Equal("/users", request.Uri.PathAndQuery); Assert.True(request.Version.IsHttp1_1()); Assert.Equal(JohnDoeUserSerialized, request.Body.Content); }
public void TestThatTwoHundredResponsesParseParseNextSucceeds() { var manyResponses = MultipleResponseBuilder(200); var totalLength = manyResponses.Length; var alteringEndIndex = 1024; var parser = ResponseParser.ParserFor(ToByteBuffer(manyResponses.Substring(0, alteringEndIndex))); var startingIndex = alteringEndIndex; while (startingIndex < totalLength) { alteringEndIndex = startingIndex + 1024 + (int)(DateExtensions.GetCurrentMillis() % startingIndex); if (alteringEndIndex > totalLength) { alteringEndIndex = totalLength; } parser.ParseNext(ToByteBuffer(manyResponses.Substring(startingIndex, alteringEndIndex - startingIndex))); startingIndex = alteringEndIndex; } Assert.True(parser.HasCompleted); Assert.True(parser.HasFullResponse()); Assert.False(parser.IsMissingContent); Assert.False(parser.HasMissingContentTimeExpired((long)DateExtensions.GetCurrentMillis() + 100)); var count = 0; var bodyIterator = _uniqueBodies.GetEnumerator(); while (parser.HasFullResponse()) { ++count; var response = parser.FullResponse(); Assert.NotNull(response); Assert.True(response.Version.IsHttp1_1()); Assert.True(bodyIterator.MoveNext()); var body = bodyIterator.Current; Assert.Equal(body, response.Entity.Content); } Assert.Equal(200, count); bodyIterator.Dispose(); }
internal VirtualStateParser Parse() { var isOutOfContent = false; while (!HasCompleted) { if (IsNotStarted) { isOutOfContent = NextStep(); } else if (IsStatusLineStep) { isOutOfContent = ParseStatusLine(); } else if (IsHeadersStep) { isOutOfContent = ParseHeaders(); } else if (IsBodyStep) { isOutOfContent = ParseBody(); } else if (IsCompletedStep) { _continuation = false; isOutOfContent = NewResponse(); } if (isOutOfContent) { _continuation = true; _outOfContentTime = (long)DateExtensions.GetCurrentMillis(); return(this); } } PrepareForStream(); return(this); }
internal bool HasMissingContentTimeExpired(long timeLimit) => _outOfContentTime + timeLimit < DateExtensions.GetCurrentMillis();