protected internal virtual FetchAndLockResult tryFetchAndLock(FetchAndLockRequest request) { ProcessEngine processEngine = null; IdentityService identityService = null; FetchAndLockResult result = null; try { processEngine = getProcessEngine(request); identityService = processEngine.IdentityService; identityService.Authentication = request.Authentication; FetchExternalTasksExtendedDto fetchingDto = request.Dto; IList <LockedExternalTaskDto> lockedTasks = executeFetchAndLock(fetchingDto, processEngine); result = FetchAndLockResult.successful(lockedTasks); } catch (Exception e) { result = FetchAndLockResult.failed(e); } finally { if (identityService != null) { identityService.clearAuthentication(); } } return(result); }
protected internal virtual IList <LockedExternalTaskDto> executeFetchAndLock(FetchExternalTasksExtendedDto fetchingDto, ProcessEngine processEngine) { ExternalTaskQueryBuilder fetchBuilder = fetchingDto.buildQuery(processEngine); IList <LockedExternalTask> externalTasks = fetchBuilder.execute(); return(LockedExternalTaskDto.fromLockedExternalTasks(externalTasks)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldResponseImmediatelyDueToAvailableTasks() public virtual void shouldResponseImmediatelyDueToAvailableTasks() { when(fetchTopicBuilder.execute()).thenReturn(new List <LockedExternalTask>(Collections.singleton(lockedExternalTaskMock))); FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).then().expect().body("size()", @is(1)).statusCode(Status.OK.StatusCode).when().post(FETCH_EXTERNAL_TASK_URL); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowProcessEngineExceptionNotDuringTimeout() public virtual void shouldThrowProcessEngineExceptionNotDuringTimeout() { FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L); when(fetchTopicBuilder.execute()).thenThrow(new ProcessEngineException("anExceptionMessage")); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().body("type", equalTo(typeof(ProcessEngineException).Name)).body("message", equalTo("anExceptionMessage")).statusCode(Status.INTERNAL_SERVER_ERROR.StatusCode).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE); verify(fetchTopicBuilder, times(1)).execute(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFetchWithoutVariables() public virtual void shouldFetchWithoutVariables() { when(fetchTopicBuilder.execute()).thenReturn(new List <LockedExternalTask>(Collections.singleton(lockedExternalTaskMock))); FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).then().expect().statusCode(Status.OK.StatusCode).body("[0].id", equalTo(MockProvider.EXTERNAL_TASK_ID)).when().post(FETCH_EXTERNAL_TASK_URL); InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService); inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", false); inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L); inOrder.verify(fetchTopicBuilder).execute(); verifyNoMoreInteractions(fetchTopicBuilder, externalTaskService); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFetchAndLock() public virtual void shouldFetchAndLock() { when(fetchTopicBuilder.execute()).thenReturn(new List <LockedExternalTask>(Collections.singleton(lockedExternalTaskMock))); FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null, true, true, false); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().statusCode(Status.OK.StatusCode).body("[0].id", equalTo(MockProvider.EXTERNAL_TASK_ID)).body("[0].topicName", equalTo(MockProvider.EXTERNAL_TASK_TOPIC_NAME)).body("[0].workerId", equalTo(MockProvider.EXTERNAL_TASK_WORKER_ID)).body("[0].lockExpirationTime", equalTo(MockProvider.EXTERNAL_TASK_LOCK_EXPIRATION_TIME)).body("[0].processInstanceId", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("[0].executionId", equalTo(MockProvider.EXAMPLE_EXECUTION_ID)).body("[0].activityId", equalTo(MockProvider.EXAMPLE_ACTIVITY_ID)).body("[0].activityInstanceId", equalTo(MockProvider.EXAMPLE_ACTIVITY_INSTANCE_ID)).body("[0].processDefinitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("[0].processDefinitionKey", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)).body("[0].tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID)).body("[0].retries", equalTo(MockProvider.EXTERNAL_TASK_RETRIES)).body("[0].errorMessage", equalTo(MockProvider.EXTERNAL_TASK_ERROR_MESSAGE)).body("[0].errorMessage", equalTo(MockProvider.EXTERNAL_TASK_ERROR_MESSAGE)).body("[0].priority", equalTo(MockProvider.EXTERNAL_TASK_PRIORITY)).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME, notNullValue()).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_PRIMITIVE_VARIABLE_VALUE.Value)).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type", equalTo("String")).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE); InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService); inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", true); inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L); inOrder.verify(fetchTopicBuilder).variables(Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME)); inOrder.verify(fetchTopicBuilder).execute(); verifyNoMoreInteractions(fetchTopicBuilder, externalTaskService); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Ignore @Test public void shouldSetAuthenticationProperly() public virtual void shouldSetAuthenticationProperly() { when(identityServiceMock.CurrentAuthentication).thenReturn(new Authentication(MockProvider.EXAMPLE_USER_ID, groupIds, tenantIds)); FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE); ArgumentCaptor <Authentication> argumentCaptor = ArgumentCaptor.forClass(typeof(Authentication)); verify(identityServiceMock, atLeastOnce()).Authentication = argumentCaptor.capture(); assertThat(argumentCaptor.Value.UserId, @is(MockProvider.EXAMPLE_USER_ID)); assertThat(argumentCaptor.Value.GroupIds, @is(groupIds)); assertThat(argumentCaptor.Value.TenantIds, @is(tenantIds)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFetchWithCustomObjectDeserializationEnabled() public virtual void shouldFetchWithCustomObjectDeserializationEnabled() { when(fetchTopicBuilder.execute()).thenReturn(new List <LockedExternalTask>(Collections.singleton(lockedExternalTaskMock))); FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null, false, true, true); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().statusCode(Status.OK.StatusCode).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE); InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService); inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", false); inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L); inOrder.verify(fetchTopicBuilder).variables(Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME)); inOrder.verify(fetchTopicBuilder).enableCustomObjectDeserialization(); inOrder.verify(fetchTopicBuilder).execute(); verifyNoMoreInteractions(fetchTopicBuilder, externalTaskService); }
public virtual void addPendingRequest(FetchExternalTasksExtendedDto dto, AsyncResponse asyncResponse, ProcessEngine processEngine) { long?asyncResponseTimeout = dto.AsyncResponseTimeout; if (asyncResponseTimeout != null && asyncResponseTimeout.Value > MAX_REQUEST_TIMEOUT) { asyncResponse.resume(new InvalidRequestException(Status.BAD_REQUEST, "The asynchronous response timeout cannot be set to a value greater than " + MAX_REQUEST_TIMEOUT + " milliseconds")); return; } IdentityService identityService = processEngine.IdentityService; Authentication authentication = identityService.CurrentAuthentication; string processEngineName = processEngine.Name; FetchAndLockRequest incomingRequest = (new FetchAndLockRequest()).setProcessEngineName(processEngineName).setAsyncResponse(asyncResponse).setAuthentication(authentication).setDto(dto); LOG.log(Level.FINEST, "New request: {0}", incomingRequest); FetchAndLockResult result = tryFetchAndLock(incomingRequest); LOG.log(Level.FINEST, "Fetch and lock result: {0}", result); if (result.wasSuccessful()) { IList <LockedExternalTaskDto> lockedTasks = result.Tasks; if (lockedTasks.Count > 0 || dto.AsyncResponseTimeout == null) { // response immediately if tasks available asyncResponse.resume(lockedTasks); LOG.log(Level.FINEST, "Resuming request with {0}", lockedTasks); } else { addRequest(incomingRequest); LOG.log(Level.FINEST, "Deferred request"); } } else { Exception processEngineException = result.Throwable; asyncResponse.resume(processEngineException); LOG.log(Level.FINEST, "Resuming request with error {0}", processEngineException); } }
protected internal virtual FetchExternalTasksExtendedDto createDto(long?responseTimeout, string workerId) { FetchExternalTasksExtendedDto externalTask = new FetchExternalTasksExtendedDto(); FetchExternalTasksExtendedDto.FetchExternalTaskTopicDto topic = new FetchExternalTasksExtendedDto.FetchExternalTaskTopicDto(); topic.TopicName = "aTopicName"; topic.LockDuration = 12354L; externalTask.MaxTasks = 5; externalTask.WorkerId = workerId; externalTask.Topics = Collections.singletonList(topic); if (responseTimeout != null) { externalTask.AsyncResponseTimeout = responseTimeout; } return(externalTask); }
private FetchExternalTasksExtendedDto createDto(long?responseTimeout, bool usePriority, bool withVariables, bool withDeserialization) { FetchExternalTasksExtendedDto fetchExternalTasksDto = new FetchExternalTasksExtendedDto(); if (responseTimeout != null) { fetchExternalTasksDto.AsyncResponseTimeout = responseTimeout; } fetchExternalTasksDto.MaxTasks = 5; fetchExternalTasksDto.WorkerId = "aWorkerId"; fetchExternalTasksDto.UsePriority = usePriority; FetchExternalTasksExtendedDto.FetchExternalTaskTopicDto topicDto = new FetchExternalTasksExtendedDto.FetchExternalTaskTopicDto(); fetchExternalTasksDto.Topics = Collections.singletonList(topicDto); topicDto.TopicName = "aTopicName"; topicDto.LockDuration = 12354L; if (withVariables) { topicDto.Variables = Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME); } topicDto.DeserializeValues = withDeserialization; fetchExternalTasksDto.Topics = Collections.singletonList(topicDto); return(fetchExternalTasksDto); }
public virtual FetchAndLockRequest setDto(FetchExternalTasksExtendedDto dto) { this.dto = dto; return(this); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowInvalidRequestExceptionOnMaxTimeoutExceeded() public virtual void shouldThrowInvalidRequestExceptionOnMaxTimeoutExceeded() { FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(FetchAndLockHandlerImpl.MAX_REQUEST_TIMEOUT + 1); given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", containsString("The asynchronous response timeout cannot be set to a value greater than ")).statusCode(Status.BAD_REQUEST.StatusCode).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE); }