use of com.carrotsearch.hppc.IntArrayList in project crate by crate.
the class InternalCountOperationTest method testCount.
@Test
public void testCount() throws Exception {
execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
execute("refresh table t");
CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
ClusterService clusterService = internalCluster().getDataNodeInstance(ClusterService.class);
CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
Metadata metadata = clusterService.state().getMetadata();
Index index = metadata.index(getFqn("t")).getIndex();
IntArrayList shards = new IntArrayList(1);
shards.add(0);
Map<String, IntIndexedContainer> indexShards = Map.of(index.getName(), shards);
{
CompletableFuture<Long> count = countOperation.count(txnCtx, indexShards, Literal.BOOLEAN_TRUE);
assertThat(count.get(5, TimeUnit.SECONDS), is(3L));
}
Schemas schemas = internalCluster().getInstance(Schemas.class);
TableInfo tableInfo = schemas.getTableInfo(new RelationName(sqlExecutor.getCurrentSchema(), "t"));
TableRelation tableRelation = new TableRelation(tableInfo);
Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
Symbol filter = sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'"));
{
CompletableFuture<Long> count = countOperation.count(txnCtx, indexShards, filter);
assertThat(count.get(5, TimeUnit.SECONDS), is(1L));
}
}
use of com.carrotsearch.hppc.IntArrayList in project crate by crate.
the class FetchTaskTest method testSearcherIsAcquiredForShard.
@Test
public void testSearcherIsAcquiredForShard() throws Exception {
IntArrayList shards = IntArrayList.from(1, 2);
Routing routing = new Routing(Map.of("dummy", Map.of("i1", shards)));
IndexBaseBuilder ibb = new IndexBaseBuilder();
ibb.allocate("i1", shards);
Map<RelationName, Collection<String>> tableIndices = new HashMap<>();
tableIndices.put(new RelationName(Schemas.DOC_SCHEMA_NAME, "i1"), List.of("i1"));
Metadata metadata = Metadata.builder().put(IndexMetadata.builder("i1").settings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_VERSION_CREATED, Version.CURRENT)).build(), true).build();
final FetchTask context = new FetchTask(UUID.randomUUID(), new FetchPhase(1, null, ibb.build(), tableIndices, List.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS), UnaryOperator.identity()), metadata, relationName -> null, List.of(routing));
context.start();
assertThat(context.searcher(1), Matchers.notNullValue());
assertThat(context.searcher(2), Matchers.notNullValue());
}
use of com.carrotsearch.hppc.IntArrayList in project crate by crate.
the class NodeFetchRequestTest method testStreaming.
@Test
public void testStreaming() throws Exception {
IntObjectHashMap<IntArrayList> toFetch = new IntObjectHashMap<>();
IntArrayList docIds = new IntArrayList(3);
toFetch.put(1, docIds);
NodeFetchRequest orig = new NodeFetchRequest(UUID.randomUUID(), 1, true, toFetch);
BytesStreamOutput out = new BytesStreamOutput();
orig.writeTo(out);
StreamInput in = out.bytes().streamInput();
NodeFetchRequest streamed = new NodeFetchRequest(in);
assertThat(orig.jobId(), is(streamed.jobId()));
assertThat(orig.fetchPhaseId(), is(streamed.fetchPhaseId()));
assertThat(orig.isCloseContext(), is(streamed.isCloseContext()));
assertThat(orig.toFetch().toString(), is(streamed.toFetch().toString()));
}
use of com.carrotsearch.hppc.IntArrayList in project crate by crate.
the class TransportFetchOperationTest method test_ram_accounting_on_non_empty_fetch_ids_and_close.
@Test
public void test_ram_accounting_on_non_empty_fetch_ids_and_close() {
var toFetch = new IntObjectHashMap<IntContainer>();
toFetch.put(1, new IntArrayList());
RamAccounting ramAccounting = TransportFetchOperation.ramAccountingForIncomingResponse(RamAccounting.NO_ACCOUNTING, toFetch, true);
assertThat(ramAccounting, instanceOf(BlockBasedRamAccounting.class));
}
Aggregations