示例#1
0
        public void Initialize_InitializesHandlerRunner()
        {
            // arrange

            // act
            _bootstrap.Initialize();

            // assert
            A.CallTo(() => _runner.Initialize()).MustHaveHappened();
        }
示例#2
0
        private static void Run(IHandlerRunner runner)
        {
            ILambdaRuntime   runtime   = new LambdaRuntime(new SystemEnvironment(), new SystemDateTime(), new HttpClient());
            ILambdaBootstrap bootstrap = new LambdaBootstrap(runtime, runner);

            bootstrap.Initialize();
            bootstrap.Run();
        }
示例#3
0
        private static void Run(IHandlerRunner runner)
        {
            // The Lambda container freezes the process at a point where an HTTP request is in progress.
            // We need to make sure we don't timeout waiting for the next invocation.
            // Reference 12 Hours from AWS Custom Runtime Support
            HttpClient httpClient = new HttpClient();

            httpClient.Timeout = TimeSpan.FromHours(12);

            ILambdaRuntime   runtime   = new LambdaRuntime(new SystemEnvironment(), new SystemDateTime(), httpClient);
            ILambdaBootstrap bootstrap = new LambdaBootstrap(runtime, runner);

            bootstrap.Initialize();
            bootstrap.Run();
        }
示例#4
0
        /// Program entry point
        static void Main(string[] args)
        {
            // Add all /var/lang/bin/shared/*/* directories to the search path
            foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2)))
            {
                assemblyDirs.Add(di.FullName);
            }
            AssemblyLoadContext.Default.Resolving += OnAssemblyResolving;

            try
            {
                var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs);

                var handler = GetFunctionHandler(positionalArgs);
                var body    = GetEventBody(positionalArgs);

                if (shouldWaitForDebugger)
                {
                    Console.Error.WriteLine("Waiting for the debugger to attach...");

                    if (!DebuggerExtensions.TryWaitForAttaching(
                            _debuggerStatusQueryInterval,
                            _debuggerStatusQueryTimeout))
                    {
                        Console.Error.WriteLine("Timeout. Proceeding without debugger.");
                    }
                }

                var             lambdaRuntime   = new MockRuntime(handler, body);
                LambdaBootstrap lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER);
                UnhandledExceptionLogger.Register();
                lambdaBootstrap.Initialize();
                lambdaBootstrap.Invoke();
            }

            // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging
            catch (Exception ex)
            {
                Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}");
            }
        }
示例#5
0
        /// Program entry point
        static void Main(string[] args)
        {
            // Add all /var/lang/bin/shared/*/* directories to the search path
            foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2)))
            {
                assemblyDirs.Add(di.FullName);
            }
            AssemblyLoadContext.Default.Resolving += OnAssemblyResolving;

            //Console.CancelKeyPress += delegate {
            //    // call methods to clean up
            //};

            Process mockServer = null;

            try
            {
                var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs);

                var handler = GetFunctionHandler(positionalArgs);
                var body    = GetEventBody(positionalArgs);

                var lambdaRuntime = new MockRuntime(handler, body);

                mockServer = new Process();
                mockServer.StartInfo.FileName              = "/var/runtime/mockserver";
                mockServer.StartInfo.CreateNoWindow        = true;
                mockServer.StartInfo.RedirectStandardInput = true;
                mockServer.StartInfo.Environment["DOCKER_LAMBDA_NO_BOOTSTRAP"] = "1";
                mockServer.StartInfo.Environment["DOCKER_LAMBDA_USE_STDIN"]    = "1";
                mockServer.Start();
                mockServer.StandardInput.Write(body);
                mockServer.StandardInput.Close();

                if (shouldWaitForDebugger)
                {
                    Console.Error.WriteLine("Waiting for the debugger to attach...");

                    if (!DebuggerExtensions.TryWaitForAttaching(
                            _debuggerStatusQueryInterval,
                            _debuggerStatusQueryTimeout))
                    {
                        Console.Error.WriteLine("Timeout. Proceeding without debugger.");
                    }
                }

                var lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER);
                UnhandledExceptionLogger.Register();
                lambdaBootstrap.Initialize();
                lambdaBootstrap.Invoke();
            }

            // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging
            catch (Exception ex)
            {
                Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}");
            }
            finally
            {
                if (mockServer != null)
                {
                    mockServer.Dispose();
                }
            }
        }