public void ShouldCancelRequest() { // given // when var task = ZeebeClient .NewResolveIncidentCommand(1201321) .Send(new CancellationTokenSource(TimeSpan.Zero).Token); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode); }
public void ShouldTimeoutRequest() { // given // when var task = ZeebeClient .NewResolveIncidentCommand(1201321) .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldSendRequestReceiveResponseAsExpected() { // given var expectedRequest = new ActivateJobsRequest { Timeout = 123_000L, MaxJobsToActivate = 3, Type = "foo", Worker = "jobWorker", RequestTimeout = 5_000L }; TestService.AddRequestHandler(typeof(ActivateJobsRequest), request => CreateExpectedResponse()); // when var signal = new EventWaitHandle(false, EventResetMode.AutoReset); var receivedJobs = new List <IJob>(); using (var jobWorker = ZeebeClient.NewWorker() .JobType("foo") .Handler((jobClient, job) => { receivedJobs.Add(job); if (receivedJobs.Count == 3) { signal.Set(); } }) .MaxJobsActive(3) .Name("jobWorker") .Timeout(TimeSpan.FromSeconds(123L)) .PollInterval(TimeSpan.FromMilliseconds(100)) .PollingTimeout(TimeSpan.FromSeconds(5L)) .Open()) { Assert.True(jobWorker.IsOpen()); signal.WaitOne(); } // then var actualRequest = TestService.Requests[0]; Assert.AreEqual(expectedRequest, actualRequest); Assert.AreEqual(receivedJobs.Count, 3); AssertJob(receivedJobs[0], 1); AssertJob(receivedJobs[1], 2); AssertJob(receivedJobs[2], 3); }
public void ShouldTimeoutRequest() { // given const string variables = "{\"foo\":23}"; const int jobKey = 255; // when var task = ZeebeClient.NewCompleteJobCommand(jobKey).Variables(variables).Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldFailWithZeroThreadCount() { // expected var aggregateException = Assert.Throws <ArgumentOutOfRangeException>( () => { ZeebeClient.NewWorker() .JobType("foo") .Handler((jobClient, job) => { }) .HandlerThreads(0); }); StringAssert.Contains("Expected an handler thread count larger then zero, but got 0.", aggregateException.Message); }
public void ShouldUseAutoCompleteWithWorker() { // given var expectedRequest = new ActivateJobsRequest { Timeout = 5_000L, MaxJobsToActivate = 3, Type = "foo", Worker = "jobWorker", RequestTimeout = 5_000L }; TestService.AddRequestHandler( typeof(ActivateJobsRequest), request => CreateExpectedResponse()); // when using (var jobWorker = ZeebeClient.NewWorker() .JobType("foo") .Handler((jobClient, job) => { Logger.Info("Handler has seen job '{0}'", job); }) .AutoCompletion() .MaxJobsActive(3) .Name("jobWorker") .Timeout(TimeSpan.FromMilliseconds(5_000L)) .PollInterval(TimeSpan.FromSeconds(5)) .PollingTimeout(TimeSpan.FromMilliseconds(5_000L)) .Open()) { Assert.True(jobWorker.IsOpen()); while (TestService.Requests[typeof(CompleteJobRequest)].Count < 3) { } } // then var actualRequest = TestService.Requests[typeof(ActivateJobsRequest)][0]; Assert.AreEqual(expectedRequest, actualRequest); var completeJobRequests = TestService.Requests[typeof(CompleteJobRequest)].OfType <CompleteJobRequest>().Select(j => j.JobKey).ToList(); Assert.AreEqual(3, completeJobRequests.Count); Assert.Contains(1, completeJobRequests); Assert.Contains(2, completeJobRequests); Assert.Contains(3, completeJobRequests); }
/// <summary> /// Adds the Zeebe builders to the IServiceCollection /// </summary> /// <param name="services">the collection where the zeebe services are appended</param> /// <returns>the service collection</returns> public static IServiceCollection AddZeebeBuilders(this IServiceCollection services) { services.AddTransient(serviceProvider => { var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); return(ZeebeClient.Builder().UseLoggerFactory(loggerFactory)); }); services.AddTransient(serviceProvider => { var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); return(CamundaCloudTokenProvider.Builder().UseLoggerFactory(loggerFactory)); }); return(services); }
public void ShouldNotThrowExceptionWhenDisposingMultipleTimes() { // given var zeebeClient = ZeebeClient.Builder() .UseGatewayAddress("localhost:26500") .UsePlainText() .Build(); // when zeebeClient.Dispose(); // then Assert.DoesNotThrow(() => zeebeClient.Dispose()); }
public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected() { // given var expectedResponse = new DeployWorkflowResponse { Key = 1 }; expectedResponse.Workflows.Add(new WorkflowMetadata { BpmnProcessId = "process", ResourceName = _demoProcessPath, Version = 1, WorkflowKey = 2 }); expectedResponse.Workflows.Add(new WorkflowMetadata { BpmnProcessId = "process2", ResourceName = _demoProcessPath, Version = 1, WorkflowKey = 3 }); TestService.AddRequestHandler(typeof(DeployWorkflowRequest), request => expectedResponse); // when var fileContent = File.ReadAllText(_demoProcessPath); var deployWorkflowResponse = await ZeebeClient.NewDeployCommand() .AddResourceFile(_demoProcessPath) .AddResourceString(fileContent, Encoding.UTF8, _demoProcessPath) .Send(); // then Assert.AreEqual(1, deployWorkflowResponse.Key); Assert.AreEqual(2, deployWorkflowResponse.Workflows.Count); var workflowMetadata = deployWorkflowResponse.Workflows[0]; Assert.AreEqual("process", workflowMetadata.BpmnProcessId); Assert.AreEqual(1, workflowMetadata.Version); Assert.AreEqual(_demoProcessPath, workflowMetadata.ResourceName); Assert.AreEqual(2, workflowMetadata.WorkflowKey); var workflowMetadata2 = deployWorkflowResponse.Workflows[1]; Assert.AreEqual("process2", workflowMetadata2.BpmnProcessId); Assert.AreEqual(1, workflowMetadata2.Version); Assert.AreEqual(_demoProcessPath, workflowMetadata2.ResourceName); Assert.AreEqual(3, workflowMetadata2.WorkflowKey); }
public void ShouldTimeoutRequest() { // given // when var task = ZeebeClient .NewUpdateRetriesCommand(1024) .Retries(223) .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldCancelRequest() { // given // when var task = ZeebeClient.NewCreateProcessInstanceCommand() .BpmnProcessId("process") .LatestVersion() .Send(new CancellationTokenSource(TimeSpan.Zero).Token); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.Cancelled, rpcException.Status.StatusCode); }
public void ShouldTimeoutRequest() { // given // when var task = ZeebeClient.NewCreateWorkflowInstanceCommand() .BpmnProcessId("process") .LatestVersion() .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldTimeoutRequest() { // given // when var task = ZeebeClient .NewSetVariablesCommand(2123) .Variables("{\"foo\":\"bar\"}") .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldTimeoutRequest() { // given // when var task = ZeebeClient .NewDeployCommand() .AddResourceFile(_demoProcessPath) .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldCancelRequest() { // given // when var task = ZeebeClient .NewDeployCommand() .AddResourceFile(_demoProcessPath) .Send(new CancellationTokenSource(TimeSpan.Zero).Token); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode); }
public void ShouldCancelRequest() { // given // when var task = ZeebeClient .NewSetVariablesCommand(2123) .Variables("{\"foo\":\"bar\"}") .Send(new CancellationTokenSource(TimeSpan.Zero).Token); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode); }
public void ShouldCancelRequest() { // given // when var task = ZeebeClient .NewPublishMessageCommand() .MessageName("messageName") .CorrelationKey("p-1") .Send(new CancellationTokenSource(TimeSpan.Zero).Token); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode); }
public async Task ShouldSendRequestAsExpected() { // given var expected = new ResolveIncidentRequest { IncidentKey = 1201321 }; // when await ZeebeClient.NewResolveIncidentCommand(1201321).Send(); // then var request = TestService.Requests[typeof(ResolveIncidentRequest)][0]; Assert.AreEqual(expected, request); }
public void ShouldTimeoutRequest() { // given // when var task = ZeebeClient .NewPublishMessageCommand() .MessageName("messageName") .CorrelationKey("p-1") .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public void ShouldCancelRequest() { // given const int jobKey = 255; // when var task = ZeebeClient.NewThrowErrorCommand(jobKey) .ErrorCode("code 13") .ErrorMessage("This is a business error!") .Send(new CancellationTokenSource(TimeSpan.Zero).Token); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode); }
public async Task shouldSendRequestWithFilterAsExpected() { // given var expected = new ListWorkflowsRequest { BpmnProcessId = "process" }; // when await ZeebeClient.NewListWorkflowRequest().BpmnProcessId("process").Send(); // then var request = TestService.Requests[0]; Assert.AreEqual(expected, request); }
public async Task ShouldReceiveResponseAsExpected() { // given var expectedResponse = new SetVariablesResponse { Key = 12 }; TestService.AddRequestHandler(typeof(SetVariablesRequest), request => expectedResponse); // when var response = await ZeebeClient.NewSetVariablesCommand(2123).Variables("{\"foo\":\"bar\"}").Local().Send(); // then Assert.AreEqual(12, response.Key); }
public void ShouldTimeoutRequest() { // given const int JobKey = 255; // when var task = ZeebeClient.NewThrowErrorCommand(JobKey) .ErrorCode("code 13") .ErrorMessage("This is a business error!") .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public async Task ShouldSendRequestAsExpected() { // given var expected = new CancelWorkflowInstanceRequest { WorkflowInstanceKey = 12113 }; // when await ZeebeClient.NewCancelInstanceCommand(12113).Send(); // then var request = TestService.Requests[typeof(CancelWorkflowInstanceRequest)][0]; Assert.AreEqual(expected, request); }
public void ShouldTimeoutRequest() { // given const int jobKey = 255; // when var task = ZeebeClient .NewFailCommand(jobKey) .Retries(2) .ErrorMessage("This job failed!") .Send(TimeSpan.Zero); var aggregateException = Assert.Throws <AggregateException>(() => task.Wait()); var rpcException = (RpcException)aggregateException.InnerExceptions[0]; // then Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); }
public async Task ShouldSendRequestAsExpected() { // given var expectedRequest = new SetVariablesRequest { ElementInstanceKey = 2123, Variables = "{\"foo\":\"bar\"}" }; // when await ZeebeClient.NewSetVariablesCommand(2123).Variables("{\"foo\":\"bar\"}").Send(); // then var request = TestService.Requests[typeof(SetVariablesRequest)][0]; Assert.AreEqual(expectedRequest, request); }
public async Task shouldSendRequestAsExpected() { // given var expectedRequest = new UpdateWorkflowInstancePayloadRequest { ElementInstanceKey = 2123, Payload = "{\"foo\":\"bar\"}" }; // when await ZeebeClient.NewUpdatePayloadCommand(2123).Payload("{\"foo\":\"bar\"}").Send(); // then var request = TestService.Requests[0]; Assert.AreEqual(expectedRequest, request); }
public async Task ShouldFailOnWrongCert() { // given GrpcEnvironment.SetLogger(new ConsoleLogger()); var keyCertificatePairs = new List <KeyCertificatePair>(); var serverCert = File.ReadAllText(ServerCertPath); keyCertificatePairs.Add(new KeyCertificatePair(serverCert, File.ReadAllText(ServerKeyPath))); var channelCredentials = new SslServerCredentials(keyCertificatePairs); var server = new Server(); server.Ports.Add(new ServerPort("0.0.0.0", 26505, channelCredentials)); var testService = new GatewayTestService(); var serviceDefinition = Gateway.BindService(testService); server.Services.Add(serviceDefinition); server.Start(); // client var zeebeClient = ZeebeClient.Builder() .UseGatewayAddress("0.0.0.0:26505") .UseTransportEncryption(WrongCertPath) .Build(); // when try { await zeebeClient .NewPublishMessageCommand() .MessageName("messageName") .CorrelationKey("p-1") .Send(); Assert.Fail(); } catch (RpcException rpcException) { // expected Assert.AreEqual(rpcException.Status.StatusCode, StatusCode.Unavailable); } }
public async Task ShouldSendRequestWithWorkflowKeyAsExpected() { // given var expectedRequest = new CreateWorkflowInstanceRequest { WorkflowKey = 1 }; // when await ZeebeClient.NewCreateWorkflowInstanceCommand() .WorkflowKey(1) .Send(); // then var request = TestService.Requests[typeof(CreateWorkflowInstanceRequest)][0]; Assert.AreEqual(expectedRequest, request); }
public async Task ShouldUseUserAgentHeader() { // given Metadata sendMetadata = null; TestService.ConsumeRequestHeaders(metadata => { sendMetadata = metadata; }); // when await ZeebeClient.TopologyRequest().Send(); // then Assert.NotNull(sendMetadata); var entry = sendMetadata[0]; Assert.AreEqual("user-agent", entry.Key); Assert.IsTrue(entry.Value.StartsWith("zeebe-client-csharp/" + typeof(ZeebeClient).Assembly.GetName().Version)); }