Search in sources :

Example 1 with TransportShardUpsertAction

use of io.crate.executor.transport.TransportShardUpsertAction in project crate by crate.

the class SQLTransportIntegrationTest method assertNoJobExecutionContextAreLeftOpen.

@After
public void assertNoJobExecutionContextAreLeftOpen() throws Exception {
    final Field activeContexts = JobContextService.class.getDeclaredField("activeContexts");
    final Field activeOperationsSb = TransportShardAction.class.getDeclaredField("activeOperations");
    activeContexts.setAccessible(true);
    activeOperationsSb.setAccessible(true);
    try {
        assertBusy(new Runnable() {

            @Override
            public void run() {
                for (JobContextService jobContextService : internalCluster().getInstances(JobContextService.class)) {
                    try {
                        //noinspection unchecked
                        Map<UUID, JobExecutionContext> contexts = (Map<UUID, JobExecutionContext>) activeContexts.get(jobContextService);
                        assertThat(contexts.size(), is(0));
                    } catch (IllegalAccessException e) {
                        throw Throwables.propagate(e);
                    }
                }
                for (TransportShardUpsertAction action : internalCluster().getInstances(TransportShardUpsertAction.class)) {
                    try {
                        Multimap<UUID, KillableCallable> operations = (Multimap<UUID, KillableCallable>) activeOperationsSb.get(action);
                        assertThat(operations.size(), is(0));
                    } catch (IllegalAccessException e) {
                        throw Throwables.propagate(e);
                    }
                }
                for (TransportShardDeleteAction action : internalCluster().getInstances(TransportShardDeleteAction.class)) {
                    try {
                        Multimap<UUID, KillableCallable> operations = (Multimap<UUID, KillableCallable>) activeOperationsSb.get(action);
                        assertThat(operations.size(), is(0));
                    } catch (IllegalAccessException e) {
                        throw Throwables.propagate(e);
                    }
                }
            }
        }, 10L, TimeUnit.SECONDS);
    } catch (AssertionError e) {
        StringBuilder errorMessageBuilder = new StringBuilder();
        String[] nodeNames = internalCluster().getNodeNames();
        for (String nodeName : nodeNames) {
            JobContextService jobContextService = internalCluster().getInstance(JobContextService.class, nodeName);
            try {
                //noinspection unchecked
                Map<UUID, JobExecutionContext> contexts = (Map<UUID, JobExecutionContext>) activeContexts.get(jobContextService);
                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 Throwables.propagate(e);
            }
        }
        throw new AssertionError(errorMessageBuilder.toString(), e);
    }
}
Also used : TransportShardUpsertAction(io.crate.executor.transport.TransportShardUpsertAction) TransportShardDeleteAction(io.crate.executor.transport.TransportShardDeleteAction) KillableCallable(io.crate.executor.transport.kill.KillableCallable) Field(java.lang.reflect.Field) Multimap(com.google.common.collect.Multimap) JobExecutionContext(io.crate.jobs.JobExecutionContext) JobContextService(io.crate.jobs.JobContextService) After(org.junit.After)

Aggregations

Multimap (com.google.common.collect.Multimap)1 TransportShardDeleteAction (io.crate.executor.transport.TransportShardDeleteAction)1 TransportShardUpsertAction (io.crate.executor.transport.TransportShardUpsertAction)1 KillableCallable (io.crate.executor.transport.kill.KillableCallable)1 JobContextService (io.crate.jobs.JobContextService)1 JobExecutionContext (io.crate.jobs.JobExecutionContext)1 Field (java.lang.reflect.Field)1 After (org.junit.After)1