本文整理汇总了C#中JobHost.StopAsync方法的典型用法代码示例。如果您正苦于以下问题:C# JobHost.StopAsync方法的具体用法?C# JobHost.StopAsync怎么用?C# JobHost.StopAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JobHost
的用法示例。
在下文中一共展示了JobHost.StopAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run(string connectionString)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CreateTestQueues(queueClient);
try
{
CloudQueue firstQueue = queueClient.GetQueueReference(_nameResolver.ResolveInString(FunctionChainingPerfTest.FirstQueueName));
firstQueue.AddMessage(new CloudQueueMessage("Test"));
_startBlock = MeasurementBlock.BeginNew(0, HostStartMetric);
JobHostConfiguration hostConfig = new JobHostConfiguration(connectionString);
hostConfig.NameResolver = _nameResolver;
hostConfig.TypeLocator = new FakeTypeLocator(typeof(FunctionChainingPerfTest));
JobHost host = new JobHost(hostConfig);
_tokenSource = new CancellationTokenSource();
Task stopTask = null;
_tokenSource.Token.Register(() => stopTask = host.StopAsync());
host.RunAndBlock();
stopTask.GetAwaiter().GetResult();
}
finally
{
DeleteTestQueues(queueClient);
}
}
示例2: Generate_EndToEnd
public async Task Generate_EndToEnd()
{
// construct our TimerTrigger attribute ([TimerTrigger("00:00:02", RunOnStartup = true)])
Collection<ParameterDescriptor> parameters = new Collection<ParameterDescriptor>();
ParameterDescriptor parameter = new ParameterDescriptor("timerInfo", typeof(TimerInfo));
ConstructorInfo ctorInfo = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
PropertyInfo runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
ctorInfo,
new object[] { "00:00:02" },
new PropertyInfo[] { runOnStartupProperty },
new object[] { true });
parameter.CustomAttributes.Add(attributeBuilder);
parameters.Add(parameter);
// create the FunctionDefinition
FunctionMetadata metadata = new FunctionMetadata();
TestInvoker invoker = new TestInvoker();
FunctionDescriptor function = new FunctionDescriptor("TimerFunction", invoker, metadata, parameters);
Collection<FunctionDescriptor> functions = new Collection<FunctionDescriptor>();
functions.Add(function);
// Get the Type Attributes (in this case, a TimeoutAttribute)
ScriptHostConfiguration scriptConfig = new ScriptHostConfiguration();
scriptConfig.FunctionTimeout = TimeSpan.FromMinutes(5);
Collection<CustomAttributeBuilder> typeAttributes = ScriptHost.CreateTypeAttributes(scriptConfig);
// generate the Type
Type functionType = FunctionGenerator.Generate("TestScriptHost", "TestFunctions", typeAttributes, functions);
// verify the generated function
MethodInfo method = functionType.GetMethod("TimerFunction");
TimeoutAttribute timeoutAttribute = (TimeoutAttribute)functionType.GetCustomAttributes().Single();
Assert.Equal(TimeSpan.FromMinutes(5), timeoutAttribute.Timeout);
Assert.True(timeoutAttribute.ThrowOnTimeout);
Assert.True(timeoutAttribute.TimeoutWhileDebugging);
ParameterInfo triggerParameter = method.GetParameters()[0];
TimerTriggerAttribute triggerAttribute = triggerParameter.GetCustomAttribute<TimerTriggerAttribute>();
Assert.NotNull(triggerAttribute);
// start the JobHost which will start running the timer function
JobHostConfiguration config = new JobHostConfiguration()
{
TypeLocator = new TypeLocator(functionType)
};
config.UseTimers();
JobHost host = new JobHost(config);
await host.StartAsync();
await Task.Delay(3000);
await host.StopAsync();
// verify our custom invoker was called
Assert.True(invoker.InvokeCount >= 2);
}
示例3: StopAsync_WhenAlreadyStopping_ReturnsSameTask
public void StopAsync_WhenAlreadyStopping_ReturnsSameTask()
{
// Arrange
using (JobHost host = new JobHost(CreateConfiguration()))
{
host.Start();
// Replace (and cleanup) the existing listener to hook StopAsync.
IListener oldRunner = host.Listener;
oldRunner.StopAsync(CancellationToken.None).GetAwaiter().GetResult();
TaskCompletionSource<object> stopTaskSource = new TaskCompletionSource<object>();
Mock<IListener> listenerMock = new Mock<IListener>(MockBehavior.Strict);
listenerMock.Setup(r => r.StopAsync(It.IsAny<CancellationToken>())).Returns(stopTaskSource.Task);
listenerMock.Setup(r => r.Dispose());
host.Listener = listenerMock.Object;
Task alreadyStopping = host.StopAsync();
// Act
Task stoppingAgain = host.StopAsync();
// Assert
Assert.Same(alreadyStopping, stoppingAgain);
// Cleanup
stopTaskSource.SetResult(null);
alreadyStopping.GetAwaiter().GetResult();
stoppingAgain.GetAwaiter().GetResult();
}
}
示例4: StopAsync_WhenStarting_Throws
public void StopAsync_WhenStarting_Throws()
{
// Arrange
TaskCompletionSource<IStorageAccount> getAccountTaskSource = new TaskCompletionSource<IStorageAccount>();
TestJobHostConfiguration configuration = CreateConfiguration(new LambdaStorageAccountProvider(
(i1, i2) => getAccountTaskSource.Task));
using (JobHost host = new JobHost(configuration))
{
Task starting = host.StartAsync();
Assert.False(starting.IsCompleted); // Guard
// Act & Assert
ExceptionAssert.ThrowsInvalidOperation(() => host.StopAsync(), "The host has not yet started.");
// Cleanup
getAccountTaskSource.SetResult(null);
starting.GetAwaiter().GetResult();
}
}
示例5: StopAsync_WhenNotStarted_Throws
public void StopAsync_WhenNotStarted_Throws()
{
// Arrange
using (JobHost host = new JobHost(CreateConfiguration()))
{
// Act & Assert
ExceptionAssert.ThrowsInvalidOperation(() => host.StopAsync(), "The host has not yet started.");
}
}
示例6: StopAsync_WhenStopped_DoesNotThrow
public void StopAsync_WhenStopped_DoesNotThrow()
{
// Arrange
using (JobHost host = new JobHost(CreateConfiguration()))
{
host.Start();
host.Stop();
// Act & Assert
host.StopAsync().GetAwaiter().GetResult();
}
}
示例7: StartAsync_WhenStopping_Throws
public void StartAsync_WhenStopping_Throws()
{
// Arrange
using (JobHost host = new JobHost(CreateConfiguration()))
{
host.Start();
// Replace (and cleanup) the exsiting runner to hook StopAsync.
IListener oldListener = host.Listener;
oldListener.StopAsync(CancellationToken.None).GetAwaiter().GetResult();
TaskCompletionSource<object> stopTaskSource = new TaskCompletionSource<object>();
Mock<IListener> listenerMock = new Mock<IListener>(MockBehavior.Strict);
listenerMock.Setup(r => r.StopAsync(It.IsAny<CancellationToken>())).Returns(stopTaskSource.Task);
listenerMock.Setup(r => r.Dispose());
host.Listener = listenerMock.Object;
Task stopping = host.StopAsync();
// Act & Assert
ExceptionAssert.ThrowsInvalidOperation(() => host.StartAsync(), "Start has already been called.");
// Cleanup
stopTaskSource.SetResult(null);
stopping.GetAwaiter().GetResult();
}
}
示例8: MultipleAccountTest
public async Task MultipleAccountTest()
{
try
{
TestTraceWriter trace = new TestTraceWriter(TraceLevel.Info);
_serviceBusConfig = new ServiceBusConfiguration();
_serviceBusConfig.MessagingProvider = new CustomMessagingProvider(_serviceBusConfig, trace);
JobHostConfiguration config = new JobHostConfiguration()
{
NameResolver = _nameResolver,
TypeLocator = new FakeTypeLocator(typeof(ServiceBusTestJobs))
};
config.Tracing.Tracers.Add(trace);
config.UseServiceBus(_serviceBusConfig);
JobHost host = new JobHost(config);
string queueName = ResolveName(StartQueueName);
string queuePrefix = queueName.Replace("-queue-start", "");
string firstTopicName = string.Format("{0}-topic/Subscriptions/{0}-queue-topic-1", queuePrefix);
WriteQueueMessage(_secondaryNamespaceManager, _secondaryConnectionString, queueName, "Test");
_topicSubscriptionCalled1 = new ManualResetEvent(initialState: false);
await host.StartAsync();
_topicSubscriptionCalled1.WaitOne(SBTimeout);
// ensure all logs have had a chance to flush
await Task.Delay(3000);
// Wait for the host to terminate
await host.StopAsync();
host.Dispose();
Assert.Equal("Test-topic-1", _resultMessage1);
}
finally
{
Cleanup();
}
}