use of io.crate.metadata.Routing in project crate by crate.
the class JobExecutionContextTest method testFailureClosesAllSubContexts.
@Test
public void testFailureClosesAllSubContexts() throws Exception {
String localNodeId = "localNodeId";
RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(routing.containsShards(localNodeId)).thenReturn(false);
when(collectPhase.routing()).thenReturn(routing);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
JobExecutionContext.Builder builder = new JobExecutionContext.Builder(UUID.randomUUID(), coordinatorNode, Collections.emptyList(), mock(JobsLogs.class));
JobCollectContext jobCollectContext = new JobCollectContext(collectPhase, mock(MapSideDataCollectOperation.class), localNodeId, mock(RamAccountingContext.class), new TestingBatchConsumer(), mock(SharedShardContexts.class));
TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
PageDownstreamContext pageDownstreamContext = spy(new PageDownstreamContext(Loggers.getLogger(PageDownstreamContext.class), "n1", 2, "dummy", batchConsumer, PassThroughPagingIterator.oneShot(), new Streamer[] { IntegerType.INSTANCE.streamer() }, mock(RamAccountingContext.class), 1));
builder.addSubContext(jobCollectContext);
builder.addSubContext(pageDownstreamContext);
JobExecutionContext jobExecutionContext = builder.build();
Exception failure = new Exception("failure!");
jobCollectContext.close(failure);
// other contexts must be killed with same failure
verify(pageDownstreamContext, times(1)).innerKill(failure);
final Field subContexts = JobExecutionContext.class.getDeclaredField("subContexts");
subContexts.setAccessible(true);
int size = ((ConcurrentMap<Integer, ExecutionSubContext>) subContexts.get(jobExecutionContext)).size();
assertThat(size, is(0));
}
use of io.crate.metadata.Routing in project crate by crate.
the class FetchContextTest method testSearcherIsAcquiredForShard.
@Test
public void testSearcherIsAcquiredForShard() throws Exception {
Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("dummy", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", ImmutableList.of(1, 2)).map()).map());
IndexBaseVisitor ibv = new IndexBaseVisitor();
routing.walkLocations(ibv);
HashMultimap<TableIdent, String> tableIndices = HashMultimap.create();
tableIndices.put(new TableIdent(null, "i1"), "i1");
final FetchContext context = new FetchContext(new FetchPhase(1, null, ibv.build(), tableIndices, ImmutableList.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS)), ImmutableList.of(routing));
context.prepare();
assertThat(context.searcher(1), Matchers.notNullValue());
assertThat(context.searcher(2), Matchers.notNullValue());
}
use of io.crate.metadata.Routing in project crate by crate.
the class ExecutionPhasesTaskTest method testGroupByServer.
@Test
public void testGroupByServer() throws Exception {
Routing twoNodeRouting = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("node1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(1, 2)).map()).put("node2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("t1", Arrays.asList(3, 4)).map()).map());
UUID jobId = UUID.randomUUID();
RoutedCollectPhase c1 = new RoutedCollectPhase(jobId, 1, "c1", twoNodeRouting, RowGranularity.DOC, ImmutableList.of(), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
MergePhase m1 = new MergePhase(jobId, 2, "merge1", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
m1.executionNodes(Sets.newHashSet("node3", "node4"));
MergePhase m2 = new MergePhase(jobId, 3, "merge2", 2, Collections.emptyList(), ImmutableList.of(), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
m2.executionNodes(Sets.newHashSet("node1", "node3"));
String localNodeId = "node1";
NodeOperation n1 = NodeOperation.withDownstream(c1, m1, (byte) 0, localNodeId);
NodeOperation n2 = NodeOperation.withDownstream(m1, m2, (byte) 0, localNodeId);
NodeOperation n3 = NodeOperation.withDownstream(m2, mock(ExecutionPhase.class), (byte) 0, localNodeId);
Map<String, Collection<NodeOperation>> groupByServer = NodeOperationGrouper.groupByServer(ImmutableList.of(n1, n2, n3));
assertThat(groupByServer.containsKey("node1"), is(true));
assertThat(groupByServer.get("node1"), Matchers.containsInAnyOrder(n1, n3));
assertThat(groupByServer.containsKey("node2"), is(true));
assertThat(groupByServer.get("node2"), Matchers.containsInAnyOrder(n1));
assertThat(groupByServer.containsKey("node3"), is(true));
assertThat(groupByServer.get("node3"), Matchers.containsInAnyOrder(n2, n3));
assertThat(groupByServer.containsKey("node4"), is(true));
assertThat(groupByServer.get("node4"), Matchers.containsInAnyOrder(n2));
}
use of io.crate.metadata.Routing in project crate by crate.
the class RemoteCollectorTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
UUID jobId = UUID.randomUUID();
RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of("remoteNode", ImmutableMap.of("dummyTable", Collections.singletonList(1)))), RowGranularity.DOC, Collections.<Symbol>singletonList(createReference("name", DataTypes.STRING)), Collections.<Projection>emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
transportJobAction = mock(TransportJobAction.class);
transportKillJobsNodeAction = mock(TransportKillJobsNodeAction.class);
consumer = new TestingBatchConsumer();
JobsLogs jobsLogs = new JobsLogs(() -> true);
JobContextService jobContextService = new JobContextService(Settings.EMPTY, new NoopClusterService(), jobsLogs);
remoteCollector = new RemoteCollector(jobId, "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, jobContextService, mock(RamAccountingContext.class), consumer, collectPhase);
}
use of io.crate.metadata.Routing in project crate by crate.
the class JobCollectContextTest method testThreadPoolNameForNonDocTables.
@Test
public void testThreadPoolNameForNonDocTables() throws Exception {
RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(collectPhase.routing()).thenReturn(routing);
when(routing.containsShards(localNodeId)).thenReturn(false);
// sys.cluster (single row collector)
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.CLUSTER);
String threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
// partition values only of a partitioned doc table (single row collector)
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.PARTITION);
threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
// sys.nodes (single row collector)
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.NODE);
threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
// sys.shards
when(routing.containsShards(localNodeId)).thenReturn(true);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.SHARD);
threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
when(routing.containsShards(localNodeId)).thenReturn(false);
// information_schema.*
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
}
Aggregations