public async Task RawMessageAvailable() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); BrokeredMessage pre = null; BrokeredMessage post = null; pipeline.Add(async(ctx, next, cancel) => { pre = ctx.Message; await next(); post = ctx.Message; }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsTrue(result); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); Assert.AreSame(message, pre); Assert.AreSame(message, post); }
public async Task ResultAvailableAfterTrigger() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var pre = false; var post = false; pipeline.Add(async(ctx, next, cancel) => { pre = ctx.Result == null; await next(); post = ctx.Result != null; }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsTrue(result); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); Assert.IsTrue(pre); Assert.IsTrue(post); }
public async Task ContextPassesToDifferentStagesReverse() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var key = "xxx"; var actual = "zzz"; var expected = actual + actual; pipeline.Add(async(ctx, next, cancel) => { await next(); if (ctx.Enviorment.ContainsKey(key)) { actual = ctx.Enviorment[key] as string; } }); pipeline.Add(async(ctx, next, cancel) => { await next(); ctx.Enviorment[key] = expected; }); var result = await pipeline.BeginProcessingMessageAsync(message, token.Token); Assert.IsTrue(result); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); Assert.AreEqual(expected, actual); }
public async Task ExceptionInPipePostTrigger() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); var funcresult = new FunctionResult(true); var pre = false; var result = false; pipeline.Add(async(ctx, next, cancel) => { pre = true; await next(); throw new DivideByZeroException(); }); try { result = await pipeline.BeginProcessingMessageAsync(message, token.Token); await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token); } catch { Assert.IsTrue(pre); Assert.IsTrue(result); throw; } }
public async Task CompleteProcessingMessageAsyncNullResult() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var message = new BrokeredMessage(); var token = new CancellationTokenSource(); await pipeline.CompleteProcessingMessageAsync(message, null, token.Token); }
public async Task CompleteProcessingMessageAsyncNullMessage() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var funcresult = new FunctionResult(true); var token = new CancellationTokenSource(); await pipeline.CompleteProcessingMessageAsync(null, funcresult, token.Token); }
public async Task ContextsDontMixMessages2() { var pipeline = new PipelineProcessor(new OnMessageOptions()); var id1 = Guid.NewGuid().ToString(); var id2 = Guid.NewGuid().ToString(); var message1 = new BrokeredMessage() { MessageId = id1 }; var message2 = new BrokeredMessage() { MessageId = id2 }; var token1 = new CancellationTokenSource(); var token2 = new CancellationTokenSource(); var funcresult = new FunctionResult(true); pipeline.Add(async(ctx, next, cancel) => { ctx.Enviorment["id"] = ctx.Message.MessageId; await next(); ctx.Message.MessageId = ctx.Enviorment["id"] as string; }); var result1 = await pipeline.BeginProcessingMessageAsync(message1, token1.Token); var result2 = await pipeline.BeginProcessingMessageAsync(message2, token1.Token); await pipeline.CompleteProcessingMessageAsync(message2, funcresult, token2.Token); await pipeline.CompleteProcessingMessageAsync(message1, funcresult, token1.Token); Assert.IsTrue(result1); Assert.IsTrue(result2); Assert.AreEqual(id1, message1.MessageId); Assert.AreEqual(id2, message2.MessageId); }
public override Task CompleteProcessingMessageAsync(BrokeredMessage message, FunctionResult result, CancellationToken cancellationToken) { return(_processor.CompleteProcessingMessageAsync(message, result, cancellationToken)); }