public SaeaLayerCallback(ITransportLayerHandler handler, Socket listenSocket, Server server, int handlerId, ExecutionContextFlow contextFlow) { _handler = handler; _listenSocket = listenSocket; _server = server; _handlerId = handlerId; _contextSuppresser = ExecutionContextFlowSuppresser.CreateContextSuppresser(contextFlow); RecreateSaeas(); handler.Callback = this; }
public static Func<IDisposable> CreateContextSuppresser(ExecutionContextFlow contextFlow) { switch (contextFlow) { case ExecutionContextFlow.SuppressAlways: return _suppressAlways; case ExecutionContextFlow.SuppressOnAsync: return _suppressOnAsync; case ExecutionContextFlow.Flow: return _flow; default: throw new ArgumentOutOfRangeException(nameof(contextFlow)); } }
public void ExecutionContextOnSetupThread(ExecutionContextFlow flow) { ResetExecutionContextFlowForTestThread(); CallContext.LogicalSetData("test.data", "test.value"); var server = new ServerBuilder() .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082)) .SetExecutionContextFlow(flow) .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4)) .Build(); server.Start(); server.Dispose(); Assert.Equal( "test.value", CallContext.LogicalGetData("test.data") as string); }
public static Func <IDisposable> CreateContextSuppresser(ExecutionContextFlow contextFlow) { switch (contextFlow) { case ExecutionContextFlow.SuppressAlways: return(_suppressAlways); case ExecutionContextFlow.SuppressOnAsync: return(_suppressOnAsync); case ExecutionContextFlow.Flow: return(_flow); default: throw new ArgumentOutOfRangeException("contextFlow"); } }
public void ExecutionContextFlowFromSetupThread(ExecutionContextFlow flow, string expectedLogicalContextValue) { ResetExecutionContextFlowForTestThread(); CallContext.LogicalSetData("test.data", "test.value"); var server = new ServerBuilder() .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082)) .SetExecutionContextFlow(flow) .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4)) .Build(); server.Start(); server.Dispose(); var separateThreadValue = Task.Factory.StartNew(() => CallContext.LogicalGetData("test.data") as string); //Assert.True(ExecutionContext.IsFlowSuppressed()); Assert.Equal(expectedLogicalContextValue, separateThreadValue.Result); }
public void ExecutionContextFlowToOwinApp(ExecutionContextFlow flow, string expectedValue) { ResetExecutionContextFlowForTestThread(); string applicationValue = null; CallContext.LogicalSetData("test.data", "test.value"); var server = new ServerBuilder() .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082)) .SetExecutionContextFlow(flow) .SetOwinApp(env=> AppReadingLogicalCallContext(out applicationValue)) .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4)) .Build(); server.Start(); using (var httpClient = new HttpClient()) { var response = httpClient.GetAsync("http://localhost:8082").Result; } server.Dispose(); Assert.Equal(expectedValue, applicationValue); }
public void ExecutionContextFlowToOwinApp(ExecutionContextFlow flow, string expectedValue) { ResetExecutionContextFlowForTestThread(); string applicationValue = null; CallContext.LogicalSetData("test.data", "test.value"); var server = new ServerBuilder() .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082)) .SetExecutionContextFlow(flow) .SetOwinApp(env => AppReadingLogicalCallContext(out applicationValue)) .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4)) .Build(); server.Start(); using (var httpClient = new HttpClient()) { var response = httpClient.GetAsync("http://localhost:8082").Result; } server.Dispose(); Assert.Equal(expectedValue, applicationValue); }
public ServerBuilder SetExecutionContextFlow(ExecutionContextFlow flow) { _contextFlow = flow; return this; }
public ServerBuilder SetExecutionContextFlow(ExecutionContextFlow flow) { _contextFlow = flow; return(this); }