Search in sources :

Example 1 with KillableCallable

use of io.crate.execution.jobs.kill.KillableCallable in project crate by crate.

the class SQLIntegrationTestCase method assertNoTasksAreLeftOpen.

@After
public void assertNoTasksAreLeftOpen() throws Exception {
    final Field activeTasks = TasksService.class.getDeclaredField("activeTasks");
    final Field activeOperationsSb = TransportShardAction.class.getDeclaredField("activeOperations");
    activeTasks.setAccessible(true);
    activeOperationsSb.setAccessible(true);
    try {
        assertBusy(() -> {
            for (TasksService tasksService : internalCluster().getInstances(TasksService.class)) {
                try {
                    // noinspection unchecked
                    Map<UUID, RootTask> contexts = (Map<UUID, RootTask>) activeTasks.get(tasksService);
                    assertThat(contexts.size(), is(0));
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
            for (TransportShardUpsertAction action : internalCluster().getInstances(TransportShardUpsertAction.class)) {
                try {
                    ConcurrentHashMap<TaskId, KillableCallable<?>> operations = (ConcurrentHashMap<TaskId, KillableCallable<?>>) activeOperationsSb.get(action);
                    assertThat(operations.size(), is(0));
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
            for (TransportShardDeleteAction action : internalCluster().getInstances(TransportShardDeleteAction.class)) {
                try {
                    ConcurrentHashMap<TaskId, KillableCallable<?>> operations = (ConcurrentHashMap<TaskId, KillableCallable<?>>) activeOperationsSb.get(action);
                    assertThat(operations.size(), is(0));
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        }, 10L, TimeUnit.SECONDS);
    } catch (AssertionError e) {
        StringBuilder errorMessageBuilder = new StringBuilder();
        String[] nodeNames = internalCluster().getNodeNames();
        for (String nodeName : nodeNames) {
            TasksService tasksService = internalCluster().getInstance(TasksService.class, nodeName);
            try {
                // noinspection unchecked
                Map<UUID, RootTask> contexts = (Map<UUID, RootTask>) activeTasks.get(tasksService);
                String contextsString = contexts.toString();
                if (!"{}".equals(contextsString)) {
                    errorMessageBuilder.append("## node: ");
                    errorMessageBuilder.append(nodeName);
                    errorMessageBuilder.append("\n");
                    errorMessageBuilder.append(contextsString);
                    errorMessageBuilder.append("\n");
                }
                contexts.clear();
            } catch (IllegalAccessException ex) {
                throw new RuntimeException(ex);
            }
        }
        throw new AssertionError(errorMessageBuilder.toString(), e);
    }
}
Also used : TaskId(org.elasticsearch.tasks.TaskId) TransportShardUpsertAction(io.crate.execution.dml.upsert.TransportShardUpsertAction) TransportShardDeleteAction(io.crate.execution.dml.delete.TransportShardDeleteAction) TasksService(io.crate.execution.jobs.TasksService) RootTask(io.crate.execution.jobs.RootTask) KillableCallable(io.crate.execution.jobs.kill.KillableCallable) Field(java.lang.reflect.Field) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) After(org.junit.After)

Aggregations

TransportShardDeleteAction (io.crate.execution.dml.delete.TransportShardDeleteAction)1 TransportShardUpsertAction (io.crate.execution.dml.upsert.TransportShardUpsertAction)1 RootTask (io.crate.execution.jobs.RootTask)1 TasksService (io.crate.execution.jobs.TasksService)1 KillableCallable (io.crate.execution.jobs.kill.KillableCallable)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TaskId (org.elasticsearch.tasks.TaskId)1 After (org.junit.After)1