Search in sources :

Example 16 with IndexNameExpressionResolver

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();
    }
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Task(org.elasticsearch.tasks.Task) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) RepositoryException(org.elasticsearch.repositories.RepositoryException) ActionFilters(org.elasticsearch.action.support.ActionFilters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateRepositoryAnalyzedStatement(io.crate.analyze.CreateRepositoryAnalyzedStatement) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DeleteRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 17 with IndexNameExpressionResolver

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);
}
Also used : DynamicReference(io.crate.analyze.symbol.DynamicReference) DynamicReference(io.crate.analyze.symbol.DynamicReference) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with IndexNameExpressionResolver

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);
}
Also used : DynamicReference(io.crate.analyze.symbol.DynamicReference) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with IndexNameExpressionResolver

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));
}
Also used : CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkRetryCoordinatorPool(org.elasticsearch.action.bulk.BulkRetryCoordinatorPool) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) ClusterService(org.elasticsearch.cluster.ClusterService) InputColumn(io.crate.analyze.symbol.InputColumn) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportBulkCreateIndicesAction(org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction) BytesRef(org.apache.lucene.util.BytesRef) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 20 with IndexNameExpressionResolver

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);
}
Also used : InputFactory(io.crate.operation.InputFactory) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before)

Aggregations

IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)32 Settings (org.elasticsearch.common.settings.Settings)15 ThreadPool (org.elasticsearch.threadpool.ThreadPool)12 ClusterState (org.elasticsearch.cluster.ClusterState)10 ActionListener (org.elasticsearch.action.ActionListener)9 ActionFilters (org.elasticsearch.action.support.ActionFilters)9 Test (org.junit.Test)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 ClusterService (org.elasticsearch.cluster.ClusterService)7 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)5 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)5 ShardId (org.elasticsearch.index.shard.ShardId)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)5 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)4 TableIdent (io.crate.metadata.TableIdent)4 UUID (java.util.UUID)4 TransportService (org.elasticsearch.transport.TransportService)4 ShardResponse (io.crate.executor.transport.ShardResponse)3