use of io.crate.execution.dml.delete.TransportShardDeleteAction 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);
}
}
Aggregations