Example #1
0
 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));
     }
 }
Example #3
0
        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);
        }
Example #4
0
        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");
            }
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
 public ServerBuilder SetExecutionContextFlow(ExecutionContextFlow flow)
 {
     _contextFlow = flow;
     return this;
 }
Example #11
0
 public ServerBuilder SetExecutionContextFlow(ExecutionContextFlow flow)
 {
     _contextFlow = flow;
     return(this);
 }
Example #12
0
 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;
 }