use of io.crate.planner.node.dql.RoutedCollectPhase 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.planner.node.dql.RoutedCollectPhase in project crate by crate.
the class SystemCollectSourceTest method testReadIsolation.
@Test
public void testReadIsolation() throws Exception {
SystemCollectSource systemCollectSource = internalCluster().getInstance(SystemCollectSource.class);
RoutedCollectPhase collectPhase = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(ImmutableMap.of()), RowGranularity.SHARD, ImmutableList.of(), ImmutableList.of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
// No read isolation
List<String> noReadIsolationIterable = new ArrayList<>();
noReadIsolationIterable.add("a");
noReadIsolationIterable.add("b");
Iterable<? extends Row> rows = systemCollectSource.toRowsIterableTransformation(collectPhase, false).apply(noReadIsolationIterable);
assertThat(Iterables.size(rows), is(2));
noReadIsolationIterable.add("c");
assertThat(Iterables.size(rows), is(3));
// Read isolation
List<String> readIsolationIterable = new ArrayList<>();
readIsolationIterable.add("a");
readIsolationIterable.add("b");
rows = systemCollectSource.toRowsIterableTransformation(collectPhase, true).apply(readIsolationIterable);
assertThat(Iterables.size(rows), is(2));
readIsolationIterable.add("c");
assertThat(Iterables.size(rows), is(2));
}
use of io.crate.planner.node.dql.RoutedCollectPhase 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.planner.node.dql.RoutedCollectPhase 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.planner.node.dql.RoutedCollectPhase in project crate by crate.
the class DocLevelCollectTest method testCollectWithPartitionedColumns.
@Test
public void testCollectWithPartitionedColumns() throws Throwable {
TableIdent tableIdent = new TableIdent(Schemas.DEFAULT_SCHEMA_NAME, PARTITIONED_TABLE_NAME);
Routing routing = schemas.getTableInfo(tableIdent).getRouting(WhereClause.MATCH_ALL, null);
RoutedCollectPhase collectNode = getCollectNode(Arrays.<Symbol>asList(new Reference(new ReferenceIdent(tableIdent, "id"), RowGranularity.DOC, DataTypes.INTEGER), new Reference(new ReferenceIdent(tableIdent, "date"), RowGranularity.SHARD, DataTypes.TIMESTAMP)), routing, WhereClause.MATCH_ALL);
Bucket result = collect(collectNode);
for (Row row : result) {
System.out.println("Row:" + Arrays.toString(row.materialize()));
}
assertThat(result, containsInAnyOrder(isRow(1, 0L), isRow(2, 1L)));
}
Aggregations