use of io.crate.metadata.Routing in project crate by crate.
the class CollectTaskTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
localNodeId = "dummyLocalNodeId";
collectPhase = Mockito.mock(RoutedCollectPhase.class);
Routing routing = Mockito.mock(Routing.class);
when(routing.containsShards(localNodeId)).thenReturn(true);
when(collectPhase.routing()).thenReturn(routing);
when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
collectOperation = mock(MapSideDataCollectOperation.class);
Mockito.doAnswer(new Answer<>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}
}).when(collectOperation).launch(Mockito.any(), Mockito.anyString());
consumer = new TestingRowConsumer();
collectTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), collectOperation, RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), consumer, mock(SharedShardContexts.class), Version.CURRENT, 4096);
}
use of io.crate.metadata.Routing in project crate by crate.
the class RoutingBuilderTest method testAllocateRouting.
@Test
public void testAllocateRouting() {
RoutingBuilder routingBuilder = new RoutingBuilder(clusterService.state(), routingProvider);
WhereClause whereClause = new WhereClause(new Function(EqOperator.SIGNATURE, List.of(tableInfo.getReference(new ColumnIdent("id")), Literal.of(2)), EqOperator.RETURN_TYPE));
routingBuilder.newAllocations();
routingBuilder.allocateRouting(tableInfo, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, null);
routingBuilder.allocateRouting(tableInfo, whereClause, RoutingProvider.ShardSelection.ANY, null);
// 2 routing allocations with different where clause must result in 2 allocated routings
List<Routing> tableRoutings = routingBuilder.routingListByTableStack.pop().get(relationName);
assertThat(tableRoutings.size(), is(2));
// The routings are the same because the RoutingProvider enforces this - this test doesn't reflect that fact
// currently because the used routing are stubbed via the TestingTableInfo
Routing routing1 = tableRoutings.get(0);
Routing routing2 = tableRoutings.get(1);
assertThat(routing1, is(routing2));
}
use of io.crate.metadata.Routing in project crate by crate.
the class RoutedCollectPhaseTest method testNormalizeNoop.
@Test
public void testNormalizeNoop() throws Exception {
RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(Literal.of(10)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
assertThat(normalizedCollect, sameInstance(collect));
}
use of io.crate.metadata.Routing in project crate by crate.
the class RoutedCollectPhaseTest method testNormalizeDoesNotRemoveOrderBy.
@Test
public void testNormalizeDoesNotRemoveOrderBy() throws Exception {
Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
collect.orderBy(new OrderBy(Collections.singletonList(toInt10)));
EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
assertThat(normalizedCollect.orderBy(), notNullValue());
}
use of io.crate.metadata.Routing in project crate by crate.
the class RoutedCollectPhaseTest method testNormalizePreservesNodePageSizeHint.
@Test
public void testNormalizePreservesNodePageSizeHint() throws Exception {
Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
collect.nodePageSizeHint(10);
EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
assertThat(normalizedCollect.nodePageSizeHint(), is(10));
}
Aggregations