ProcessManagerContext { synchronized void tryAcceptTask(TaskHandle taskHandle) throws IllegalStateException { tryCheckLoad(); TaskExclusivity prevExclusivity = currentExclusivity; String prevExclusiveId = currentExclusiveId; boolean canAccept = tryChangeExclusivity(taskHandle); if (canAccept) { try { taskHandle.setAccepted(); acceptedTasks.add(taskHandle.getTaskId()); } catch (IllegalStateException e) { setExclusivity(prevExclusivity, prevExclusiveId); throw e; } } else { throw new IllegalStateException("Exclusivity cannot be satisfied"); } updateHostInfo(); } ProcessManagerContext(ClusterContext clusterContext, RuntimeInfo hostInfo); void killTask(String id); synchronized void updateMonitoringSample(MonitorSample sample); synchronized void updateTaskDirs();  }
@Test(expected = IllegalStateException.class) public void testRejectSecondContextExclusiveInContextExclusiveDifferentContext() throws IOException { RuntimeInfo runtimeInfo = createRuntimeInfo(); ProcessManagerContext managerContext = new ProcessManagerContext(clusterContext, runtimeInfo); setUpTaskHandle(taskHandle1, CONTEXT_EXCLUSIVE, taskId1, contextId1); setUpTaskHandle(taskHandle2, CONTEXT_EXCLUSIVE, taskId2, contextId2); try { managerContext.tryAcceptTask(taskHandle1); } catch (Exception e) { assertFalse(true); } try { managerContext.tryAcceptTask(taskHandle2); } finally { verifySetAcceptedCalled(taskHandle1); verifySetAcceptedNotCalled(taskHandle2); verifyMangerContext(managerContext, 1, CONTEXT_EXCLUSIVE, contextId1, runtimeInfo); } }