Search in sources :

Example 1 with ShardReferenceResolver

use of io.crate.metadata.shard.ShardReferenceResolver in project crate by crate.

the class SysShardsExpressionsTest method prepare.

@Before
public void prepare() throws Exception {
    ClusterService clusterService = new NoopClusterService();
    indexShard = mockIndexShard();
    schemas = new Schemas(Settings.EMPTY, ImmutableMap.of("sys", new SysSchemaInfo(clusterService)), clusterService, new DocSchemaInfoFactory(new TestingDocTableInfoFactory(Collections.emptyMap())));
    ShardReferenceResolver shardRefResolver = new ShardReferenceResolver(clusterService, schemas, indexShard);
    resolver = new RecoveryShardReferenceResolver(shardRefResolver, indexShard);
}
Also used : SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) RecoveryShardReferenceResolver(io.crate.metadata.shard.RecoveryShardReferenceResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DocSchemaInfoFactory(io.crate.metadata.doc.DocSchemaInfoFactory) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ShardReferenceResolver(io.crate.metadata.shard.ShardReferenceResolver) RecoveryShardReferenceResolver(io.crate.metadata.shard.RecoveryShardReferenceResolver) Before(org.junit.Before)

Example 2 with ShardReferenceResolver

use of io.crate.metadata.shard.ShardReferenceResolver in project crate by crate.

the class SysShardsExpressionsTest method prepare.

@Before
public void prepare() {
    NodeContext nodeCtx = createNodeContext();
    indexShard = mockIndexShard();
    CrateSettings crateSettings = new CrateSettings(clusterService, clusterService.getSettings());
    UserDefinedFunctionService udfService = new UserDefinedFunctionService(clusterService, nodeCtx);
    schemas = new Schemas(Map.of("sys", new SysSchemaInfo(this.clusterService, crateSettings)), clusterService, new DocSchemaInfoFactory(new TestingDocTableInfoFactory(Collections.emptyMap()), (ident, state) -> null, nodeCtx, udfService));
    resolver = new ShardReferenceResolver(schemas, new ShardRowContext(indexShard, clusterService));
    sysShards = schemas.getTableInfo(SysShardsTableInfo.IDENT);
}
Also used : UserDefinedFunctionService(io.crate.expression.udf.UserDefinedFunctionService) ShardRowContext(io.crate.expression.reference.sys.shard.ShardRowContext) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) DocSchemaInfoFactory(io.crate.metadata.doc.DocSchemaInfoFactory) CrateSettings(io.crate.metadata.settings.CrateSettings) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) NodeContext(io.crate.metadata.NodeContext) Schemas(io.crate.metadata.Schemas) ShardReferenceResolver(io.crate.metadata.shard.ShardReferenceResolver) Before(org.junit.Before)

Example 3 with ShardReferenceResolver

use of io.crate.metadata.shard.ShardReferenceResolver in project crate by crate.

the class SysShardsExpressionsTest method testShardSizeExpressionWhenIndexShardHasBeenClosed.

@Test
public void testShardSizeExpressionWhenIndexShardHasBeenClosed() {
    IndexShard mock = mockIndexShard();
    when(mock.storeStats()).thenThrow(new AlreadyClosedException("shard already closed"));
    ShardReferenceResolver resolver = new ShardReferenceResolver(schemas, new ShardRowContext(mock, clusterService));
    Reference refInfo = refInfo("sys.shards.size", DataTypes.LONG, RowGranularity.SHARD);
    NestableInput<Long> shardSizeExpression = (NestableInput<Long>) resolver.getImplementation(refInfo);
    assertThat(shardSizeExpression.value(), is(0L));
}
Also used : ShardRowContext(io.crate.expression.reference.sys.shard.ShardRowContext) NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) IndexShard(org.elasticsearch.index.shard.IndexShard) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ShardReferenceResolver(io.crate.metadata.shard.ShardReferenceResolver) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 4 with ShardReferenceResolver

use of io.crate.metadata.shard.ShardReferenceResolver in project crate by crate.

the class SysShardsExpressionsTest method test_retention_lease_is_null_on_index_shard_closed_exception.

@Test
public void test_retention_lease_is_null_on_index_shard_closed_exception() throws Exception {
    IndexShard mock = mockIndexShard();
    var shardId = mock.shardId();
    doThrow(new IndexShardClosedException(shardId)).when(mock).getRetentionLeaseStats();
    ShardReferenceResolver resolver = new ShardReferenceResolver(schemas, new ShardRowContext(mock, clusterService));
    Reference refInfo = refInfo("sys.shards.retention_leases", DataTypes.LONG, RowGranularity.SHARD, "version");
    NestableInput<Long> input = (NestableInput<Long>) resolver.getImplementation(refInfo);
    assertThat(input.value(), Matchers.nullValue());
}
Also used : ShardRowContext(io.crate.expression.reference.sys.shard.ShardRowContext) NestableInput(io.crate.expression.NestableInput) IndexShardClosedException(org.elasticsearch.index.shard.IndexShardClosedException) Reference(io.crate.metadata.Reference) IndexShard(org.elasticsearch.index.shard.IndexShard) ShardReferenceResolver(io.crate.metadata.shard.ShardReferenceResolver) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

ShardReferenceResolver (io.crate.metadata.shard.ShardReferenceResolver)4 ShardRowContext (io.crate.expression.reference.sys.shard.ShardRowContext)3 NestableInput (io.crate.expression.NestableInput)2 Reference (io.crate.metadata.Reference)2 DocSchemaInfoFactory (io.crate.metadata.doc.DocSchemaInfoFactory)2 TestingDocTableInfoFactory (io.crate.metadata.doc.TestingDocTableInfoFactory)2 SysSchemaInfo (io.crate.metadata.sys.SysSchemaInfo)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 IndexShard (org.elasticsearch.index.shard.IndexShard)2 Before (org.junit.Before)2 Test (org.junit.Test)2 UserDefinedFunctionService (io.crate.expression.udf.UserDefinedFunctionService)1 NodeContext (io.crate.metadata.NodeContext)1 Schemas (io.crate.metadata.Schemas)1 CrateSettings (io.crate.metadata.settings.CrateSettings)1 RecoveryShardReferenceResolver (io.crate.metadata.shard.RecoveryShardReferenceResolver)1 TestingHelpers.createNodeContext (io.crate.testing.TestingHelpers.createNodeContext)1 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 IndexShardClosedException (org.elasticsearch.index.shard.IndexShardClosedException)1