public void JobHost_UsesSas_FromEnvVar() { var fakeSasUri = "https://contoso.blob.core.windows.net/myContainer?signature=foo"; using (EnvVarHolder.Set("AzureWebJobs:InternalSasBlobContainer", fakeSasUri)) { var hostBuilder = new HostBuilder() .ConfigureDefaultTestHost(b => { b.AddAzureStorage() .AddAzureStorageCoreServices(); }) .ConfigureAppConfiguration(c => { c.AddEnvironmentVariables(); }); IHost host = hostBuilder.Build(); var config = host.Services.GetService <DistributedLockManagerContainerProvider>(); var container = config.InternalContainer; Assert.NotNull(container); Assert.Equal(container.Name, "myContainer"); // specified in sas. } }
public void JobHost_NoStorage_Succeeds() { using (EnvVarHolder.Set("AzureWebJobsStorage", null)) using (EnvVarHolder.Set("AzureWebJobsDashboard", null)) { JobHostConfiguration config = new JobHostConfiguration() { TypeLocator = new FakeTypeLocator(typeof(BasicTest)) }; Assert.Null(config.InternalStorageConfiguration); // Explicitly disalbe storage. config.HostId = Guid.NewGuid().ToString("n"); config.DashboardConnectionString = null; config.StorageConnectionString = null; var randomValue = Guid.NewGuid().ToString(); StringBuilder sbLoggingCallbacks = new StringBuilder(); var fastLogger = new FastLogger(); config.AddService <IAsyncCollector <FunctionInstanceLogEntry> >(fastLogger); JobHost host = new JobHost(config); // Manually invoked. var method = typeof(BasicTest).GetMethod("Method", BindingFlags.Public | BindingFlags.Static); host.Call(method, new { value = randomValue }); Assert.True(BasicTest.Called); Assert.Equal(2, fastLogger.List.Count); // We should be batching, so flush not called yet. host.Start(); // required to call stop() host.Stop(); // will ensure flush is called. // Verify fast logs Assert.Equal(3, fastLogger.List.Count); var startMsg = fastLogger.List[0]; Assert.Equal("BasicTest.Method", startMsg.FunctionName); Assert.Equal(null, startMsg.EndTime); Assert.NotNull(startMsg.StartTime); var endMsg = fastLogger.List[1]; Assert.Equal(startMsg.FunctionName, endMsg.FunctionName); Assert.Equal(startMsg.StartTime, endMsg.StartTime); Assert.Equal(startMsg.FunctionInstanceId, endMsg.FunctionInstanceId); Assert.NotNull(endMsg.EndTime); // signal completed Assert.True(endMsg.StartTime <= endMsg.EndTime); Assert.Null(endMsg.ErrorDetails); Assert.Null(endMsg.ParentId); Assert.Equal(2, endMsg.Arguments.Count); Assert.True(endMsg.Arguments.ContainsKey("log")); Assert.Equal(randomValue, endMsg.Arguments["value"]); Assert.Equal("val=" + randomValue, endMsg.LogOutput.Trim()); Assert.Same(FastLogger.FlushEntry, fastLogger.List[2]); } }
public async Task JobHost_NoStorage_Succeeds() { var fastLogger = new FastLogger(); using (EnvVarHolder.Set("AzureWebJobsStorage", null)) using (EnvVarHolder.Set("AzureWebJobsDashboard", null)) { IHost host = new HostBuilder() .ConfigureWebJobs(b => { b.AddTableLogging(fastLogger); }) .ConfigureTypeLocator(typeof(BasicTest)) .Build(); var randomValue = Guid.NewGuid().ToString(); StringBuilder sbLoggingCallbacks = new StringBuilder(); // Manually invoked. var method = typeof(BasicTest).GetMethod("Method", BindingFlags.Public | BindingFlags.Static); var lockManager = host.Services.GetRequiredService <IDistributedLockManager>(); Assert.IsType <InMemoryDistributedLockManager>(lockManager); await host.GetJobHost().CallAsync(method, new { value = randomValue }); Assert.True(BasicTest.Called); Assert.Equal(2, fastLogger.List.Count); // We should be batching, so flush not called yet. host.Start(); // required to call stop() await host.StopAsync(); // will ensure flush is called. // Verify fast logs Assert.Equal(3, fastLogger.List.Count); var startMsg = fastLogger.List[0]; Assert.Equal("BasicTest.Method", startMsg.FunctionName); Assert.Equal(null, startMsg.EndTime); Assert.NotNull(startMsg.StartTime); var endMsg = fastLogger.List[1]; Assert.Equal(startMsg.FunctionName, endMsg.FunctionName); Assert.Equal(startMsg.StartTime, endMsg.StartTime); Assert.Equal(startMsg.FunctionInstanceId, endMsg.FunctionInstanceId); Assert.NotNull(endMsg.EndTime); // signal completed Assert.True(endMsg.StartTime <= endMsg.EndTime); Assert.Null(endMsg.ErrorDetails); Assert.Null(endMsg.ParentId); Assert.Equal(2, endMsg.Arguments.Count); Assert.True(endMsg.Arguments.ContainsKey("log")); Assert.Equal(randomValue, endMsg.Arguments["value"]); Assert.Equal("val=" + randomValue, endMsg.LogOutput.Trim()); Assert.Same(FastLogger.FlushEntry, fastLogger.List[2]); }// EnvVarHolder }
public void IsDevelopment_ReturnsCorrectValue(string settingValue, bool expected) { using (EnvVarHolder.Set(Constants.EnvironmentSettingName, settingValue)) { JobHostConfiguration config = new JobHostConfiguration(); Assert.Equal(config.IsDevelopment, expected); } }
public async Task Test() { var containerName = "test-internal1"; var acs = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); if (acs == null) { Assert.False(true, "Missing AzureWebJobsStorage setting"); } // Create a real Blob Container Sas URI var account1 = CloudStorageAccount.Parse(acs); var client = account1.CreateCloudBlobClient(); var container = client.GetContainerReference(containerName); await container.CreateIfNotExistsAsync(); // this will throw if acs is bad var now = DateTime.UtcNow; var sig = container.GetSharedAccessSignature(new SharedAccessBlobPolicy { Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List, SharedAccessStartTime = now.AddDays(-10), SharedAccessExpiryTime = now.AddDays(10) }); var fakeSasUri = container.Uri + sig; // Set env to the SAS container and clear out all other storage. using (EnvVarHolder.Set("AzureWebJobsInternalSasBlobContainer", fakeSasUri)) using (EnvVarHolder.Set("AzureWebJobsStorage", null)) using (EnvVarHolder.Set("AzureWebJobsDashboard", null)) { var prog = new BasicProg(); var activator = new FakeActivator(prog); JobHostConfiguration config = new JobHostConfiguration() { TypeLocator = new FakeTypeLocator(typeof(BasicProg)) }; Assert.NotNull(config.InternalStorageConfiguration); Assert.Equal(container.Name, config.InternalStorageConfiguration.InternalContainer.Name); config.JobActivator = activator; config.HostId = Guid.NewGuid().ToString("n"); config.DashboardConnectionString = null; config.StorageConnectionString = null; var host = new JobHost(config); await host.CallAsync("Foo"); Assert.Equal(1, prog._count); // Verify successfully called. } }
public void JobHost_UsesSas() { var fakeSasUri = "https://contoso.blob.core.windows.net/myContainer?signature=foo"; using (EnvVarHolder.Set("AzureWebJobsInternalSasBlobContainer", fakeSasUri)) { JobHostConfiguration config = new JobHostConfiguration(); Assert.NotNull(config.InternalStorageConfiguration); // Env var should cause this to get initialized var container = config.InternalStorageConfiguration.InternalContainer; Assert.NotNull(container); Assert.Equal(container.Name, "myContainer"); // specified in sas. } }
public void UseDevelopmentSettings_ConfiguresCorrectValues() { using (EnvVarHolder.Set(Constants.EnvironmentSettingName, "Development")) { JobHostConfiguration config = new JobHostConfiguration(); Assert.False(config.UsingDevelopmentSettings); if (config.IsDevelopment) { config.UseDevelopmentSettings(); } Assert.True(config.UsingDevelopmentSettings); Assert.Equal(TimeSpan.FromSeconds(2), config.Queues.MaxPollingInterval); Assert.Equal(TimeSpan.FromSeconds(15), config.Singleton.ListenerLockPeriod); } }