Skip to content

Commit

Permalink
set common timer for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Nov 12, 2021
1 parent 5d848da commit 64a1a25
Show file tree
Hide file tree
Showing 24 changed files with 283 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean accept(File dir, String name) {
new File(tempDir, file).delete();
}
}
TaskDeadlinesServiceImpl.dispose();

}

protected static Throwable catchRootCause(ThrowingCallable shouldRaiseThrowable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.drools.core.time.TimerService;
import org.drools.core.time.impl.JDKTimerService;
import org.jbpm.process.core.timer.TimerServiceRegistry;
import org.jbpm.services.task.HumanTaskServiceFactory;
import org.jbpm.services.task.HumanTaskServicesBaseTest;
import org.jbpm.services.task.MvelFilePath;
import org.jbpm.services.task.TaskServiceRegistry;
import org.jbpm.services.task.audit.JPATaskLifeCycleEventListener;
import org.jbpm.services.task.audit.TaskAuditServiceFactory;
import org.jbpm.services.task.impl.TaskDeadlinesServiceImpl;
Expand All @@ -58,9 +62,11 @@ public class LocalTaskAuditWithDeadlineTest extends HumanTaskServicesBaseTest {

protected TaskAuditService taskAuditService;

private String timerServiceId;

@Before
public void setup() {
TaskDeadlinesServiceImpl.reset();

pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" );

Expand All @@ -71,11 +77,18 @@ public void setup() {
.getTaskService();

this.taskAuditService = TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService();
TimerService globalTs = new JDKTimerService(3);
timerServiceId = "null" + TimerServiceRegistry.TIMER_SERVICE_SUFFIX;
// and register it in the registry under 'default' key
TimerServiceRegistry.getInstance().registerTimerService(timerServiceId, globalTs);
TaskServiceRegistry.instance().registerTaskService(null, taskService);
}

@After
public void clean() {

TaskServiceRegistry.instance().remove(null);
TimerServiceRegistry.getInstance().remove(timerServiceId).shutdown();

if (emf != null) {
emf.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public TaskService getTaskService() {
if (AssignmentServiceProvider.get().isEnabled()) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(new AssignmentTaskEventListener());
}
TaskDeadlinesServiceImpl.setFallbackExecutor(commandExecutor);

}
return service;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2017 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.services.task;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.kie.internal.task.api.InternalTaskService;

public final class TaskServiceRegistry {

private static TaskServiceRegistry INSTANCE;

private Map<String, InternalTaskService> taskServices;

private InternalTaskService defaultTaskService;

public TaskServiceRegistry() {
taskServices = new ConcurrentHashMap<>();
}
public static synchronized TaskServiceRegistry instance() {
if (INSTANCE == null) {
INSTANCE = new TaskServiceRegistry();
}
return INSTANCE;
}

public void registerTaskService(String deploymentId, InternalTaskService taskService) {
if(taskService == null) {
return;
}
if (deploymentId == null) {
defaultTaskService = taskService;
} else {
taskServices.put(deploymentId, taskService);
}
}

public InternalTaskService get(String deploymentId) {
return deploymentId != null ? taskServices.get(deploymentId) : defaultTaskService;
}

public void remove(String deploymentId) {
if (deploymentId == null) {
defaultTaskService = null;
} else {
taskServices.remove(deploymentId);
}
}
}
Loading

0 comments on commit 64a1a25

Please sign in to comment.