use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.
@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
expectedException.expect(RepositoryException.class);
// add repo to cluster service so that it exists..
RepositoriesMetaData repos = new RepositoriesMetaData(new RepositoryMetaData("repo1", "fs", Settings.EMPTY));
ClusterState state = ClusterState.builder(new ClusterName("dummy")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repos)).build();
ClusterService clusterService = new NoopClusterService(state);
final ActionFilters actionFilters = mock(ActionFilters.class, Answers.RETURNS_MOCKS.get());
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {
@Override
protected void doExecute(Task task, DeleteRepositoryRequest request, ActionListener<DeleteRepositoryResponse> listener) {
deleteRepoCalled.set(true);
listener.onResponse(mock(DeleteRepositoryResponse.class));
}
};
TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {
@Override
protected void doExecute(Task task, PutRepositoryRequest request, ActionListener<PutRepositoryResponse> listener) {
listener.onFailure(new RepositoryException(request.name(), "failure"));
}
};
RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
try {
repositoryService.execute(new CreateRepositoryAnalyzedStatement("repo1", "fs", Settings.EMPTY)).get(10, TimeUnit.SECONDS);
} catch (ExecutionException e) {
assertThat(deleteRepoCalled.get(), is(true));
throw e.getCause();
}
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class DocTableInfoTest method testGetColumnInfo.
@Test
public void testGetColumnInfo() throws Exception {
TableIdent tableIdent = new TableIdent(null, "dummy");
DocTableInfo info = new DocTableInfo(tableIdent, ImmutableList.of(new Reference(new ReferenceIdent(tableIdent, new ColumnIdent("o", ImmutableList.of())), RowGranularity.DOC, DataTypes.OBJECT)), ImmutableList.of(), ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableList.of(), null, false, true, new String[0], null, new IndexNameExpressionResolver(Settings.EMPTY), 5, new BytesRef("0"), ImmutableMap.of(), ImmutableList.of(), ImmutableList.of(), ColumnPolicy.DYNAMIC, DocIndexMetaData.DEFAULT_ROUTING_HASH_FUNCTION, Version.CURRENT, null, Operation.ALL, executorService);
Reference foobar = info.getReference(new ColumnIdent("o", ImmutableList.of("foobar")));
assertNull(foobar);
DynamicReference reference = info.getDynamic(new ColumnIdent("o", ImmutableList.of("foobar")), false);
assertNull(reference);
reference = info.getDynamic(new ColumnIdent("o", ImmutableList.of("foobar")), true);
assertNotNull(reference);
assertSame(reference.valueType(), DataTypes.UNDEFINED);
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class DocTableInfoTest method testGetColumnInfoStrictParent.
@Test
public void testGetColumnInfoStrictParent() throws Exception {
TableIdent dummy = new TableIdent(null, "dummy");
ReferenceIdent foobarIdent = new ReferenceIdent(dummy, new ColumnIdent("foobar"));
Reference strictParent = new Reference(foobarIdent, RowGranularity.DOC, DataTypes.OBJECT, ColumnPolicy.STRICT, Reference.IndexType.NOT_ANALYZED, true);
ImmutableMap<ColumnIdent, Reference> references = ImmutableMap.<ColumnIdent, Reference>builder().put(new ColumnIdent("foobar"), strictParent).build();
DocTableInfo info = new DocTableInfo(dummy, ImmutableList.of(strictParent), ImmutableList.of(), ImmutableList.of(), ImmutableMap.of(), references, ImmutableMap.of(), ImmutableList.of(), null, false, true, new String[0], null, new IndexNameExpressionResolver(Settings.EMPTY), 5, new BytesRef("0"), ImmutableMap.of(), ImmutableList.of(), ImmutableList.of(), ColumnPolicy.DYNAMIC, DocIndexMetaData.DEFAULT_ROUTING_HASH_FUNCTION, Version.CURRENT, null, Operation.ALL, executorService);
ColumnIdent columnIdent = new ColumnIdent("foobar", Arrays.asList("foo", "bar"));
assertNull(info.getReference(columnIdent));
assertNull(info.getDynamic(columnIdent, false));
columnIdent = new ColumnIdent("foobar", Collections.singletonList("foo"));
assertNull(info.getReference(columnIdent));
assertNull(info.getDynamic(columnIdent, false));
Reference colInfo = info.getReference(new ColumnIdent("foobar"));
assertNotNull(colInfo);
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class IndexWriterProjectorTest method testIndexWriter.
@Test
public void testIndexWriter() throws Throwable {
execute("create table bulk_import (id int primary key, name string) with (number_of_replicas=0)");
ensureGreen();
InputCollectExpression sourceInput = new InputCollectExpression(1);
List<CollectExpression<Row, ?>> collectExpressions = Collections.<CollectExpression<Row, ?>>singletonList(sourceInput);
IndexWriterProjector writerProjector = new IndexWriterProjector(internalCluster().getInstance(ClusterService.class), internalCluster().getInstance(Functions.class), new IndexNameExpressionResolver(Settings.EMPTY), Settings.EMPTY, internalCluster().getInstance(TransportBulkCreateIndicesAction.class), internalCluster().getInstance(TransportShardUpsertAction.class)::execute, IndexNameResolver.forTable(new TableIdent(null, "bulk_import")), internalCluster().getInstance(BulkRetryCoordinatorPool.class), new Reference(new ReferenceIdent(bulkImportIdent, DocSysColumns.RAW), RowGranularity.DOC, DataTypes.STRING), Arrays.asList(ID_IDENT), Arrays.<Symbol>asList(new InputColumn(0)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID());
BatchIterator rowsIterator = RowsBatchIterator.newInstance(IntStream.range(0, 100).mapToObj(i -> new RowN(new Object[] { i, new BytesRef("{\"id\": " + i + ", \"name\": \"Arthur\"}") })).collect(Collectors.toList()), 2);
TestingBatchConsumer consumer = new TestingBatchConsumer();
consumer.accept(writerProjector.apply(rowsIterator), null);
Bucket objects = consumer.getBucket();
assertThat(objects, contains(isRow(100L)));
execute("refresh table bulk_import");
execute("select count(*) from bulk_import");
assertThat(response.rowCount(), is(1L));
assertThat(response.rows()[0][0], is(100L));
}
use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project crate by crate.
the class ProjectionToProjectorVisitorTest method prepare.
@Before
public void prepare() {
MockitoAnnotations.initMocks(this);
functions = getFunctions();
threadPool = new ThreadPool("testing");
visitor = new ProjectionToProjectorVisitor(mock(ClusterService.class), functions, new IndexNameExpressionResolver(Settings.EMPTY), threadPool, Settings.EMPTY, mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS.get()), mock(BulkRetryCoordinatorPool.class), new InputFactory(functions), EvaluatingNormalizer.functionOnlyNormalizer(functions, ReplaceMode.COPY), null);
countInfo = new FunctionInfo(new FunctionIdent(CountAggregation.NAME, Collections.singletonList(DataTypes.STRING)), DataTypes.LONG);
avgInfo = new FunctionInfo(new FunctionIdent(AverageAggregation.NAME, Collections.singletonList(DataTypes.INTEGER)), DataTypes.DOUBLE);
}
Aggregations