private static IFunctionDispatcher GetTestFunctionDispatcherWithMockLanguageWorkerChannelManager(string maxProcessCountValue = null, bool addWebhostChannel = false) { var eventManager = new ScriptEventManager(); var scriptJobHostEnvironment = new Mock <IScriptJobHostEnvironment>(); var metricsLogger = new Mock <IMetricsLogger>(); var testEnv = new TestEnvironment(); if (!string.IsNullOrEmpty(maxProcessCountValue)) { testEnv.SetEnvironmentVariable(LanguageWorkerConstants.FunctionsWorkerProcessCountSettingName, maxProcessCountValue); } var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); var testLogger = new TestLogger("FunctionDispatcherTests"); var options = new ScriptJobHostOptions { RootLogPath = Path.GetTempPath() }; IOptions <ScriptJobHostOptions> scriptOptions = new OptionsManager <ScriptJobHostOptions>(new TestOptionsFactory <ScriptJobHostOptions>(options)); var workerConfigOptions = new LanguageWorkerOptions { WorkerConfigs = TestHelpers.GetTestWorkerConfigs() }; var languageWorkerChannelManager = new Mock <ILanguageWorkerChannelManager>(); var mockFunctionDispatcherLoadBalancer = new Mock <IFunctionDispatcherLoadBalancer>(); return(new FunctionDispatcher(scriptOptions, metricsLogger.Object, testEnv, scriptJobHostEnvironment.Object, eventManager, loggerFactory, new OptionsWrapper <LanguageWorkerOptions>(workerConfigOptions), languageWorkerChannelManager.Object, null, mockFunctionDispatcherLoadBalancer.Object)); }
public WebFunctionsManagerTests() { _testRootScriptPath = Path.GetTempPath(); _testHostConfigFilePath = Path.Combine(_testRootScriptPath, ScriptConstants.HostMetadataFileName); FileUtility.DeleteFileSafe(_testHostConfigFilePath); _hostOptions = new ScriptApplicationHostOptions { ScriptPath = @"x:\root", IsSelfHost = false, LogPath = @"x:\tmp\log", SecretsPath = @"x:\secrets", TestDataPath = @"x:\test" }; string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample"); var fileSystem = CreateFileSystem(_hostOptions); var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var factory = new TestOptionsFactory <ScriptApplicationHostOptions>(_hostOptions); var tokenSource = new TestChangeTokenSource <ScriptApplicationHostOptions>(); var changeTokens = new[] { tokenSource }; var optionsMonitor = new OptionsMonitor <ScriptApplicationHostOptions>(factory, changeTokens, factory); var secretManagerProviderMock = new Mock <ISecretManagerProvider>(MockBehavior.Strict); var secretManagerMock = new Mock <ISecretManager>(MockBehavior.Strict); secretManagerProviderMock.SetupGet(p => p.Current).Returns(secretManagerMock.Object); var hostSecretsInfo = new HostSecretsInfo(); secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo); Dictionary <string, string> functionSecrets = new Dictionary <string, string>(); secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("httptrigger", false)).ReturnsAsync(functionSecrets); var configurationMock = new Mock <IConfiguration>(MockBehavior.Strict); var hostIdProviderMock = new Mock <IHostIdProvider>(MockBehavior.Strict); var mockWebHostEnvironment = new Mock <IScriptWebHostEnvironment>(MockBehavior.Strict); mockWebHostEnvironment.SetupGet(p => p.InStandbyMode).Returns(false); _mockEnvironment = new Mock <IEnvironment>(MockBehavior.Strict); _mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady)).Returns("1"); _mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.CoreToolsEnvironment)).Returns((string)null); _mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteHostName)).Returns(TestHostName); var hostNameProvider = new HostNameProvider(_mockEnvironment.Object, loggerFactory.CreateLogger <HostNameProvider>()); var workerOptions = new LanguageWorkerOptions(); FileUtility.Instance = fileSystem; _fileSystem = fileSystem; var languageWorkerOptions = new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()); var metadataProvider = new FunctionMetadataProvider(optionsMonitor, languageWorkerOptions, NullLogger <FunctionMetadataProvider> .Instance, new TestMetricsLogger()); var functionsSyncManager = new FunctionsSyncManager(configurationMock.Object, hostIdProviderMock.Object, optionsMonitor, loggerFactory.CreateLogger <FunctionsSyncManager>(), httpClient, secretManagerProviderMock.Object, mockWebHostEnvironment.Object, _mockEnvironment.Object, hostNameProvider, metadataProvider); _webFunctionsManager = new WebFunctionsManager(optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, functionsSyncManager, hostNameProvider, metadataProvider); }
private static RpcFunctionInvocationDispatcher GetTestFunctionDispatcher(string maxProcessCountValue = null, bool addWebhostChannel = false, Mock <IWebHostRpcWorkerChannelManager> mockwebHostLanguageWorkerChannelManager = null, bool throwOnProcessStartUp = false) { var eventManager = new ScriptEventManager(); var metricsLogger = new Mock <IMetricsLogger>(); var mockApplicationLifetime = new Mock <IApplicationLifetime>(); var testEnv = new TestEnvironment(); if (!string.IsNullOrEmpty(maxProcessCountValue)) { testEnv.SetEnvironmentVariable(RpcWorkerConstants.FunctionsWorkerProcessCountSettingName, maxProcessCountValue); } var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); var options = new ScriptJobHostOptions { RootLogPath = Path.GetTempPath() }; IOptions <ScriptJobHostOptions> scriptOptions = new OptionsManager <ScriptJobHostOptions>(new TestOptionsFactory <ScriptJobHostOptions>(options)); var workerConfigOptions = new LanguageWorkerOptions { WorkerConfigs = TestHelpers.GetTestWorkerConfigs() }; IRpcWorkerChannelFactory testLanguageWorkerChannelFactory = new TestRpcWorkerChannelFactory(eventManager, _testLogger, scriptOptions.Value.RootScriptPath, throwOnProcessStartUp); IWebHostRpcWorkerChannelManager testWebHostLanguageWorkerChannelManager = new TestRpcWorkerChannelManager(eventManager, _testLogger, scriptOptions.Value.RootScriptPath, testLanguageWorkerChannelFactory); IJobHostRpcWorkerChannelManager jobHostLanguageWorkerChannelManager = new JobHostRpcWorkerChannelManager(loggerFactory); if (addWebhostChannel) { testWebHostLanguageWorkerChannelManager.InitializeChannelAsync("java"); } if (mockwebHostLanguageWorkerChannelManager != null) { testWebHostLanguageWorkerChannelManager = mockwebHostLanguageWorkerChannelManager.Object; } var mockFunctionDispatcherLoadBalancer = new Mock <IRpcFunctionInvocationDispatcherLoadBalancer>(); _javaTestChannel = new TestRpcWorkerChannel(Guid.NewGuid().ToString(), "java", eventManager, _testLogger, false); var optionsMonitor = TestHelpers.CreateOptionsMonitor(workerConfigOptions); return(new RpcFunctionInvocationDispatcher(scriptOptions, metricsLogger.Object, testEnv, mockApplicationLifetime.Object, eventManager, loggerFactory, testLanguageWorkerChannelFactory, optionsMonitor, testWebHostLanguageWorkerChannelManager, jobHostLanguageWorkerChannelManager, new OptionsWrapper <ManagedDependencyOptions>(new ManagedDependencyOptions()), mockFunctionDispatcherLoadBalancer.Object)); }
public SharedMemoryManagerTests() { _loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); ILogger <MemoryMappedFileAccessor> logger = NullLogger <MemoryMappedFileAccessor> .Instance; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _mapAccessor = new MemoryMappedFileAccessorWindows(logger); } else { _mapAccessor = new MemoryMappedFileAccessorUnix(logger); } }
public void ReadFunctionsMetadataSucceeds() { string functionsPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\sample"); // Setup var fileSystem = CreateFileSystem(_hostOptions.ScriptPath); var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); var contentBuilder = new StringBuilder(); var httpClient = CreateHttpClient(contentBuilder); var factory = new TestOptionsFactory <ScriptApplicationHostOptions>(_hostOptions); var tokenSource = new TestChangeTokenSource(); var changeTokens = new[] { tokenSource }; var optionsMonitor = new OptionsMonitor <ScriptApplicationHostOptions>(factory, changeTokens, factory); var secretManagerProviderMock = new Mock <ISecretManagerProvider>(MockBehavior.Strict); var secretManagerMock = new Mock <ISecretManager>(MockBehavior.Strict); secretManagerProviderMock.SetupGet(p => p.Current).Returns(secretManagerMock.Object); var hostSecretsInfo = new HostSecretsInfo(); secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo); Dictionary <string, string> functionSecrets = new Dictionary <string, string>(); secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("httptrigger", false)).ReturnsAsync(functionSecrets); var configurationMock = new Mock <IConfiguration>(MockBehavior.Strict); var hostIdProviderMock = new Mock <IHostIdProvider>(MockBehavior.Strict); var mockWebHostEnvironment = new Mock <IScriptWebHostEnvironment>(MockBehavior.Strict); mockWebHostEnvironment.SetupGet(p => p.InStandbyMode).Returns(false); var mockEnvironment = new Mock <IEnvironment>(MockBehavior.Strict); mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteContainerReady)).Returns("1"); mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.CoreToolsEnvironment)).Returns((string)null); var functionsSyncManager = new FunctionsSyncManager(configurationMock.Object, hostIdProviderMock.Object, optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, mockWebHostEnvironment.Object, mockEnvironment.Object); var webManager = new WebFunctionsManager(optionsMonitor, new OptionsWrapper <LanguageWorkerOptions>(CreateLanguageWorkerConfigSettings()), loggerFactory, httpClient, secretManagerProviderMock.Object, functionsSyncManager); FileUtility.Instance = fileSystem; IEnumerable <FunctionMetadata> metadata = webManager.GetFunctionsMetadata(); var jsFunctions = metadata.Where(funcMetadata => funcMetadata.Language == LanguageWorkerConstants.NodeLanguageWorkerName).ToList(); var unknownFunctions = metadata.Where(funcMetadata => string.IsNullOrEmpty(funcMetadata.Language)).ToList(); Assert.Equal(2, jsFunctions.Count()); Assert.Equal(1, unknownFunctions.Count()); }
public FunctionDataCacheTests() { _loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); ILogger <MemoryMappedFileAccessor> logger = NullLogger <MemoryMappedFileAccessor> .Instance; _testEnvironment = new TestEnvironment(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _mapAccessor = new MemoryMappedFileAccessorWindows(logger); } else { _mapAccessor = new MemoryMappedFileAccessorUnix(logger, _testEnvironment); } _testEnvironment.SetEnvironmentVariable(FunctionDataCacheConstants.FunctionDataCacheEnabledSettingName, "1"); }
private static IFunctionDispatcher GetTestFunctionDispatcher() { var eventManager = new Mock <IScriptEventManager>(); var metricsLogger = new Mock <IMetricsLogger>(); var languageWorkerChannelManager = new Mock <ILanguageWorkerChannelManager>(); var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory(); var options = new ScriptJobHostOptions { RootLogPath = Path.GetTempPath() }; IOptions <ScriptJobHostOptions> scriptOptions = new OptionsManager <ScriptJobHostOptions>(new TestOptionsFactory <ScriptJobHostOptions>(options)); var workerConfigOptions = new LanguageWorkerOptions { WorkerConfigs = TestHelpers.GetTestWorkerConfigs() }; return(new FunctionDispatcher(scriptOptions, metricsLogger.Object, eventManager.Object, loggerFactory, new OptionsWrapper <LanguageWorkerOptions>(workerConfigOptions), languageWorkerChannelManager.Object)); }
private ExtensionBundleManager GetExtensionBundleManager(ExtensionBundleOptions bundleOptions, TestEnvironment environment = null) { environment = environment ?? new TestEnvironment(); return(new ExtensionBundleManager(bundleOptions, environment, MockNullLoggerFactory.CreateLoggerFactory())); }