ManagedExecutors { public static Runnable managedTask(Runnable task, ManagedTaskListener taskListener) throws IllegalArgumentException { return managedTask(task, null, taskListener); } private  ManagedExecutors(); static boolean isCurrentThreadShutdown(); static Runnable managedTask(Runnable task, ManagedTaskListener taskListener); static Runnable managedTask(Runnable task, Map<String, String> executionProperties, ManagedTaskListener taskListener); static Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener); static Callable<V> managedTask(Callable<V> task, Map<String, String> executionProperties, ManagedTaskListener taskListener);  }
@Test public void testManagedTask_Runnable_ManagedTaskListener() { RunnableImpl task = new RunnableImpl(); ManagedTaskListenerImpl taskListener = new ManagedTaskListenerImpl(); Runnable wrapped = ManagedExecutors.managedTask(task, taskListener); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(taskListener == managedTask.getManagedTaskListener()); wrapped.run(); assertTrue(task.ran); }
@Test (expected = IllegalArgumentException.class) public void testManagedTask_null_Callable_task() { Callable<?> task = null; ManagedExecutors.managedTask(task, new ManagedTaskListenerImpl()); }
@Test (expected = IllegalArgumentException.class) public void testManagedTask_null_Callable_task_2() { Callable<?> task = null; ManagedExecutors.managedTask(task, new HashMap<String, String>(), new ManagedTaskListenerImpl()); }
@Test public void testManagedTask_Runnable_executionProperties_ManagedTaskListener() { RunnableImpl task = new RunnableImpl(); ManagedTaskListenerImpl taskListener = new ManagedTaskListenerImpl(); Map<String, String> executionProperties = new HashMap<String, String>(); final String TASK_NAME = "task1"; executionProperties.put(ManagedTask.IDENTITY_NAME, TASK_NAME); executionProperties.put(ManagedTask.LONGRUNNING_HINT, "true"); Runnable wrapped = ManagedExecutors.managedTask(task, executionProperties, taskListener); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(taskListener == managedTask.getManagedTaskListener()); assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.LONGRUNNING_HINT)); assertEquals(TASK_NAME, managedTask.getExecutionProperties().get(ManagedTask.IDENTITY_NAME)); wrapped.run(); assertTrue(task.ran); }
@Test public void testManagedTask_Runnable_ManagedTask() { ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl(); Map<String, String> EXEC_PROPERTIES = new HashMap<String, String>(); EXEC_PROPERTIES.put("custom", "true"); EXEC_PROPERTIES.put(ManagedTask.LONGRUNNING_HINT, "false"); final String TASK_DESCRIPTION = "task1 description"; ManagedTaskRunnableImpl task = new ManagedTaskRunnableImpl(TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER); ManagedTaskListenerImpl taskListener = new ManagedTaskListenerImpl(); Map<String, String> executionProperties = new HashMap<String, String>(); final String TASK_NAME = "task1"; executionProperties.put(ManagedTask.IDENTITY_NAME, TASK_NAME); executionProperties.put(ManagedTask.LONGRUNNING_HINT, "true"); Runnable wrapped = ManagedExecutors.managedTask(task, executionProperties, taskListener); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(taskListener == managedTask.getManagedTaskListener()); assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.LONGRUNNING_HINT)); assertEquals(TASK_NAME, managedTask.getExecutionProperties().get(ManagedTask.IDENTITY_NAME)); assertEquals("true", managedTask.getExecutionProperties().get("custom")); }
@Test public void testManagedTask_Runnable_ManagedTask_null_args() { ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl(); Map<String, String> EXEC_PROPERTIES = new HashMap<String, String>(); EXEC_PROPERTIES.put("custom", "true"); final String TASK_DESCRIPTION = "task1 description"; ManagedTaskRunnableImpl task = new ManagedTaskRunnableImpl(TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER); Runnable wrapped = ManagedExecutors.managedTask(task, null, null); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(TASK_LISTENER == managedTask.getManagedTaskListener()); assertEquals("true", managedTask.getExecutionProperties().get("custom")); }
@Test public void testManagedTask_Callable_ManagedTaskListener() throws Exception { final String RESULT = "result"; CallableImpl<String> task = new CallableImpl<String>(RESULT); ManagedTaskListenerImpl taskListener = new ManagedTaskListenerImpl(); Callable<String> wrapped = ManagedExecutors.managedTask(task, taskListener); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(taskListener == managedTask.getManagedTaskListener()); assertEquals(RESULT, wrapped.call()); }
@Test public void testManagedTask_Callable_executionProperties_ManagedTaskListener() throws Exception { final String RESULT = "result"; CallableImpl<String> task = new CallableImpl<String>(RESULT); ManagedTaskListenerImpl taskListener = new ManagedTaskListenerImpl(); Map<String, String> executionProperties = new HashMap<String, String>(); final String TASK_NAME = "task1"; executionProperties.put(ManagedTask.IDENTITY_NAME, TASK_NAME); executionProperties.put(ManagedTask.LONGRUNNING_HINT, "true"); Callable<String> wrapped = ManagedExecutors.managedTask(task, executionProperties, taskListener); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(taskListener == managedTask.getManagedTaskListener()); assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.LONGRUNNING_HINT)); assertEquals(TASK_NAME, managedTask.getExecutionProperties().get(ManagedTask.IDENTITY_NAME)); assertEquals(RESULT, wrapped.call()); }
@Test public void testManagedTask_Callable_ManagedTask() { final String RESULT = "result"; ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl(); Map<String, String> EXEC_PROPERTIES = new HashMap<String, String>(); EXEC_PROPERTIES.put("custom", "true"); EXEC_PROPERTIES.put(ManagedTask.LONGRUNNING_HINT, "false"); final String TASK_DESCRIPTION = "task1 description"; ManagedTaskCallableImpl<String> task = new ManagedTaskCallableImpl(RESULT, TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER); ManagedTaskListenerImpl taskListener = new ManagedTaskListenerImpl(); Map<String, String> executionProperties = new HashMap<String, String>(); final String TASK_NAME = "task1"; executionProperties.put(ManagedTask.IDENTITY_NAME, TASK_NAME); executionProperties.put(ManagedTask.LONGRUNNING_HINT, "true"); Callable<String> wrapped = ManagedExecutors.managedTask(task, executionProperties, taskListener); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(taskListener == managedTask.getManagedTaskListener()); assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.LONGRUNNING_HINT)); assertEquals(TASK_NAME, managedTask.getExecutionProperties().get(ManagedTask.IDENTITY_NAME)); assertEquals("true", managedTask.getExecutionProperties().get("custom")); }
@Test public void testManagedTask_Callable_ManagedTask_null_args() { final String RESULT = "result"; ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl(); Map<String, String> EXEC_PROPERTIES = new HashMap<String, String>(); EXEC_PROPERTIES.put("custom", "true"); final String TASK_DESCRIPTION = "task1 description"; ManagedTaskCallableImpl<String> task = new ManagedTaskCallableImpl(RESULT, TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER); Callable wrapped = ManagedExecutors.managedTask(task, null, null); ManagedTask managedTask = (ManagedTask) wrapped; assertTrue(TASK_LISTENER == managedTask.getManagedTaskListener()); assertEquals("true", managedTask.getExecutionProperties().get("custom")); }
@Test (expected = IllegalArgumentException.class) public void testManagedTask_null_Runnable_task() { Runnable task = null; ManagedExecutors.managedTask(task, new ManagedTaskListenerImpl()); }
@Test (expected = IllegalArgumentException.class) public void testManagedTask_null_Runnable_task_2() { Runnable task = null; ManagedExecutors.managedTask(task, new HashMap<String, String>(), new ManagedTaskListenerImpl()); }