コード例 #1
0
        public void ShutdownStandyChannels_WorkerRuntime_Node_Set()
        {
            _testEnvironment = new TestEnvironment();
            _testEnvironment.SetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeSettingName, LanguageWorkerConstants.NodeLanguageWorkerName);

            _languageWorkerChannelManager = new LanguageWorkerChannelManager(_eventManager, _testEnvironment, _rpcServer, _loggerFactory, new OptionsWrapper <LanguageWorkerOptions>(_languageWorkerOptions), _optionsMonitor);
            string javaWorkerId = Guid.NewGuid().ToString();
            ILanguageWorkerChannel javaWorkerChannel = CreateTestChannel(javaWorkerId, LanguageWorkerConstants.JavaLanguageWorkerName);

            FunctionMetadata funcJs1 = new FunctionMetadata()
            {
                Name     = "funcJs1",
                Language = "node"
            };
            FunctionMetadata funcCS1 = new FunctionMetadata()
            {
                Name     = "funcCS1",
                Language = "csharp"
            };
            IEnumerable <FunctionMetadata> functionsList = new Collection <FunctionMetadata>()
            {
                funcJs1, funcCS1
            };

            _languageWorkerChannelManager.ShutdownStandbyChannels(functionsList);

            var initializedChannel = _languageWorkerChannelManager.GetChannel(LanguageWorkerConstants.JavaLanguageWorkerName);

            Assert.Null(initializedChannel);
        }
コード例 #2
0
        public void ShutdownStandbyChannels_OnlyProxies()
        {
            _testEnvironment = new TestEnvironment();
            _languageWorkerChannelManager = new LanguageWorkerChannelManager(_eventManager, _testEnvironment, _rpcServer, _loggerFactory, new OptionsWrapper <LanguageWorkerOptions>(_languageWorkerOptions), _optionsMonitor);
            string javaWorkerId = Guid.NewGuid().ToString();
            ILanguageWorkerChannel javaWorkerChannel = CreateTestChannel(javaWorkerId, LanguageWorkerConstants.JavaLanguageWorkerName);

            FunctionMetadata proxy1 = new FunctionMetadata()
            {
                Name    = "funcproxy1",
                IsProxy = true
            };
            FunctionMetadata proxy2 = new FunctionMetadata()
            {
                Name    = "funcproxy2",
                IsProxy = true
            };
            IEnumerable <FunctionMetadata> functionsList = new Collection <FunctionMetadata>()
            {
                proxy2, proxy1
            };

            _languageWorkerChannelManager.ShutdownStandbyChannels(functionsList);

            var initializedChannel = _languageWorkerChannelManager.GetChannel(LanguageWorkerConstants.JavaLanguageWorkerName);

            Assert.Null(initializedChannel);
        }
コード例 #3
0
        public async void FunctionDispatcherState_Default_DotNetFunctions()
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "dotnet"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);

            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);

            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
        }
コード例 #4
0
        public void IsSupported_Returns_False(string language, string funcMetadataLanguage)
        {
            IFunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();
            FunctionMetadata    func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = funcMetadataLanguage
            };

            Assert.False(functionDispatcher.IsSupported(func1, language));
        }
コード例 #5
0
        public static void IsSupported_Returns_False(string language, string funcMetadataLanguage)
        {
            var workerConfigs      = TestHelpers.GetTestWorkerConfigs();
            var eventManager       = new Mock <IScriptEventManager>();
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = funcMetadataLanguage
            };
            FunctionDispatcher functionDispatcher = new FunctionDispatcher(eventManager.Object, new TestRpcServer(), null, workerConfigs, language);

            Assert.False(functionDispatcher.IsSupported(func1));
        }
コード例 #6
0
        public async void FunctionDispatcherState_Transitions_From_Starting_To_Initialized()
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();
            FunctionMetadata   func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "node"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            await functionDispatcher.InitializeAsync(functions);

            Assert.True(functionDispatcher.State == FunctionDispatcherState.Initializing || functionDispatcher.State == FunctionDispatcherState.Initialized);
            await WaitForFunctionDispactherStateInitialized(functionDispatcher);
        }
コード例 #7
0
        public async Task FunctionDispatcherState_Transitions_From_Starting_To_Initialized()
        {
            RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher();
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "node"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionInvocationDispatcherState.Initializing, functionDispatcher.State);
            await WaitForFunctionDispactherStateInitialized(functionDispatcher);

            Assert.Equal(FunctionInvocationDispatcherState.Initialized, functionDispatcher.State);
        }
コード例 #8
0
        public async void ShutdownChannels_DotNetFunctions()
        {
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "dotnet"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            var mockLanguageWorkerChannelManager  = new Mock <IWebHostLanguageWorkerChannelManager>();
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockLanguageWorkerChannelManager);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
            await functionDispatcher.InitializeAsync(functions);

            // Wait longer than debouce action.
            await Task.Delay(6000);

            mockLanguageWorkerChannelManager.Verify(m => m.ShutdownChannels(), Times.Once);
        }
コード例 #9
0
        public async Task FunctionDispatcherState_Transitions_From_Default_To_Initialized_To_Disposing()
        {
            RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher();

            Assert.Equal(FunctionInvocationDispatcherState.Default, functionDispatcher.State);
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "node"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionInvocationDispatcherState.Initializing, functionDispatcher.State);
            await WaitForFunctionDispactherStateInitialized(functionDispatcher);

            Assert.Equal(FunctionInvocationDispatcherState.Initialized, functionDispatcher.State);
            functionDispatcher.Dispose();
            Assert.True(functionDispatcher == null || functionDispatcher.State == FunctionInvocationDispatcherState.Disposing || functionDispatcher.State == FunctionInvocationDispatcherState.Disposed);
        }