Search in sources :

Example 1 with DummySubContext

use of io.crate.jobs.DummySubContext in project crate by crate.

the class NodeDisconnectJobMonitorServiceTest method testOnParticipatingNodeDisconnectedKillsJob.

@Test
public void testOnParticipatingNodeDisconnectedKillsJob() throws Exception {
    JobContextService jobContextService = jobContextService();
    DiscoveryNode coordinator_node = new DiscoveryNode("coordinator_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
    DiscoveryNode data_node = new DiscoveryNode("data_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().localNodeId("coordinator_node_id").put(coordinator_node).put(data_node).build();
    JobExecutionContext.Builder builder = jobContextService.newBuilder(UUID.randomUUID(), coordinator_node.getId(), Arrays.asList(coordinator_node.getId(), data_node.getId()));
    builder.addSubContext(new DummySubContext());
    jobContextService.createContext(builder);
    TransportKillJobsNodeAction killAction = mock(TransportKillJobsNodeAction.class);
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(Settings.EMPTY, mock(ThreadPool.class), jobContextService, mock(TransportService.class), killAction);
    monitorService.onNodeDisconnected(discoveryNodes.get("data_node_id"));
    verify(killAction, times(1)).broadcast(any(KillJobsRequest.class), any(ActionListener.class), eq(Arrays.asList(discoveryNodes.get("data_node_id").getId())));
}
Also used : TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DummySubContext(io.crate.jobs.DummySubContext) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) KillJobsRequest(io.crate.executor.transport.kill.KillJobsRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) JobExecutionContext(io.crate.jobs.JobExecutionContext) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with DummySubContext

use of io.crate.jobs.DummySubContext in project crate by crate.

the class NodeDisconnectJobMonitorServiceTest method testOnNodeDisconnectedKillsJobOriginatingFromThatNode.

@Test
public void testOnNodeDisconnectedKillsJobOriginatingFromThatNode() throws Exception {
    JobContextService jobContextService = jobContextService();
    JobExecutionContext.Builder builder = jobContextService.newBuilder(UUID.randomUUID());
    builder.addSubContext(new DummySubContext());
    JobExecutionContext context = jobContextService.createContext(builder);
    ThreadPool threadPool = mock(ThreadPool.class);
    when(threadPool.schedule(any(TimeValue.class), anyString(), any(Runnable.class))).thenAnswer((Answer<Object>) invocation -> {
        ((Runnable) invocation.getArguments()[2]).run();
        return null;
    });
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(Settings.EMPTY, threadPool, jobContextService, mock(TransportService.class), mock(TransportKillJobsNodeAction.class));
    monitorService.onNodeDisconnected(new DiscoveryNode("noop_id", DummyTransportAddress.INSTANCE, Version.CURRENT));
    expectedException.expect(ContextMissingException.class);
    jobContextService.getContext(context.jobId());
}
Also used : Arrays(java.util.Arrays) DummySubContext(io.crate.jobs.DummySubContext) Matchers.anyString(org.mockito.Matchers.anyString) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Answer(org.mockito.stubbing.Answer) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) KillJobsRequest(io.crate.executor.transport.kill.KillJobsRequest) DummyTransportAddress(org.elasticsearch.common.transport.DummyTransportAddress) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ContextMissingException(io.crate.exceptions.ContextMissingException) Test(org.junit.Test) UUID(java.util.UUID) JobsLogs(io.crate.operation.collect.stats.JobsLogs) CrateUnitTest(io.crate.test.integration.CrateUnitTest) JobExecutionContext(io.crate.jobs.JobExecutionContext) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Version(org.elasticsearch.Version) JobContextService(io.crate.jobs.JobContextService) ActionListener(org.elasticsearch.action.ActionListener) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ThreadPool(org.elasticsearch.threadpool.ThreadPool) DummySubContext(io.crate.jobs.DummySubContext) TransportService(org.elasticsearch.transport.TransportService) JobExecutionContext(io.crate.jobs.JobExecutionContext) TimeValue(org.elasticsearch.common.unit.TimeValue) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

KillJobsRequest (io.crate.executor.transport.kill.KillJobsRequest)2 TransportKillJobsNodeAction (io.crate.executor.transport.kill.TransportKillJobsNodeAction)2 DummySubContext (io.crate.jobs.DummySubContext)2 JobContextService (io.crate.jobs.JobContextService)2 JobExecutionContext (io.crate.jobs.JobExecutionContext)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 ActionListener (org.elasticsearch.action.ActionListener)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)2 ThreadPool (org.elasticsearch.threadpool.ThreadPool)2 TransportService (org.elasticsearch.transport.TransportService)2 Test (org.junit.Test)2 ContextMissingException (io.crate.exceptions.ContextMissingException)1 JobsLogs (io.crate.operation.collect.stats.JobsLogs)1 Arrays (java.util.Arrays)1 UUID (java.util.UUID)1 Version (org.elasticsearch.Version)1 Settings (org.elasticsearch.common.settings.Settings)1 DummyTransportAddress (org.elasticsearch.common.transport.DummyTransportAddress)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1