Search in sources :

Example 6 with NestableInput

use of io.crate.expression.NestableInput in project crate by crate.

the class SysShardsExpressionsTest method testRecoveryShardField.

@Test
public void testRecoveryShardField() throws Exception {
    Reference refInfo = refInfo("sys.shards.recovery", DataTypes.UNTYPED_OBJECT, RowGranularity.SHARD);
    NestableInput<Map<String, Object>> ref = (NestableInput<Map<String, Object>>) resolver.getImplementation(refInfo);
    Map<String, Object> recovery = ref.value();
    assertEquals(RecoveryState.Stage.DONE.name(), recovery.get("stage"));
    assertEquals(10_000L, recovery.get("total_time"));
    Map<String, Object> expectedFiles = new HashMap<String, Object>() {

        {
            put("used", 2);
            put("reused", 1);
            put("recovered", 1);
            put("percent", 0.0f);
        }
    };
    assertEquals(expectedFiles, recovery.get("files"));
    Map<String, Object> expectedBytes = new HashMap<String, Object>() {

        {
            put("used", 2_048L);
            put("reused", 1_024L);
            put("recovered", 1_024L);
            put("percent", 0.0f);
        }
    };
    assertEquals(expectedBytes, recovery.get("size"));
}
Also used : NestableInput(io.crate.expression.NestableInput) HashMap(java.util.HashMap) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) Map(java.util.Map) HashMap(java.util.HashMap) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 7 with NestableInput

use of io.crate.expression.NestableInput in project crate by crate.

the class SysShardsExpressionsTest method testRoutingState.

@Test
public void testRoutingState() throws Exception {
    Reference refInfo = refInfo("sys.shards.routing_state", DataTypes.STRING, RowGranularity.SHARD);
    NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
    assertEquals("RELOCATING", shardExpression.value());
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 8 with NestableInput

use of io.crate.expression.NestableInput in project crate by crate.

the class SysShardsExpressionsTest method testTableNameOfPartition.

@Test
public void testTableNameOfPartition() throws Exception {
    // expression should return the real table name
    indexName = IndexParts.toIndexName("doc", "wikipedia_de", "foo");
    prepare();
    Reference refInfo = refInfo("sys.shards.table_name", DataTypes.STRING, RowGranularity.SHARD);
    NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
    assertEquals("wikipedia_de", shardExpression.value());
    // reset indexName
    indexName = "wikipedia_de";
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 9 with NestableInput

use of io.crate.expression.NestableInput 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 10 with NestableInput

use of io.crate.expression.NestableInput in project crate by crate.

the class SysShardsExpressionsTest method testCustomSchemaName.

@Test
public void testCustomSchemaName() throws Exception {
    indexName = "my_schema.wikipedia_de";
    prepare();
    Reference refInfo = refInfo("sys.shards.schema_name", DataTypes.STRING, RowGranularity.SHARD);
    NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
    assertEquals("my_schema", shardExpression.value());
    // reset indexName
    indexName = "wikipedia_de";
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

NestableInput (io.crate.expression.NestableInput)23 Reference (io.crate.metadata.Reference)22 Test (org.junit.Test)21 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)20 TestingHelpers.resolveCanonicalString (io.crate.testing.TestingHelpers.resolveCanonicalString)14 ShardRowContext (io.crate.expression.reference.sys.shard.ShardRowContext)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 MapBackedRefResolver (io.crate.metadata.MapBackedRefResolver)2 RelationName (io.crate.metadata.RelationName)2 ShardReferenceResolver (io.crate.metadata.shard.ShardReferenceResolver)2 HashMap (java.util.HashMap)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 IndexShard (org.elasticsearch.index.shard.IndexShard)2 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)1 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 PartitionName (io.crate.metadata.PartitionName)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 Map (java.util.Map)1 IndexShardClosedException (org.elasticsearch.index.shard.IndexShardClosedException)1