Search in sources :

Example 31 with Path

use of java.nio.file.Path in project crate by crate.

the class BlobPathITest method testDataStorageWithMultipleDataPaths.

@Test
public void testDataStorageWithMultipleDataPaths() throws Exception {
    Path data1 = createTempDir("data1");
    Path data2 = createTempDir("data2");
    Settings settings = Settings.builder().put(nodeSettings(0)).put("path.data", data1.toString() + "," + data2.toString()).build();
    launchNodeAndInitClient(settings);
    Settings indexSettings = Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_NUMBER_OF_SHARDS, 2).build();
    blobAdminClient.createBlobTable("test", indexSettings).get();
    for (int i = 0; i < 10; i++) {
        client.put("test", "body" + i);
    }
    List<String> data1Files = gatherDigests(data1);
    List<String> data2Files = gatherDigests(data2);
    assertThat(data1Files.size(), Matchers.allOf(lessThan(10), greaterThan(0)));
    assertThat(data2Files.size(), Matchers.allOf(lessThan(10), greaterThan(0)));
    assertThat(data1Files.size() + data2Files.size(), is(10));
}
Also used : Path(java.nio.file.Path) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 32 with Path

use of java.nio.file.Path in project crate by crate.

the class BlobIndicesService method getGlobalBlobPath.

@Nullable
public static Path getGlobalBlobPath(Settings settings) {
    String customGlobalBlobPathSetting = settings.get(SETTING_BLOBS_PATH);
    if (customGlobalBlobPathSetting == null) {
        return null;
    }
    Path globalBlobPath = PathUtils.get(customGlobalBlobPathSetting);
    ensureExistsAndWritable(globalBlobPath);
    return globalBlobPath;
}
Also used : Path(java.nio.file.Path) Nullable(org.elasticsearch.common.Nullable)

Example 33 with Path

use of java.nio.file.Path in project crate by crate.

the class LuceneQueryBuilderTest method prepare.

@Before
public void prepare() throws Exception {
    DocTableInfo users = TestingTableInfo.builder(new TableIdent(null, "users"), null).add("name", DataTypes.STRING).add("x", DataTypes.INTEGER).add("d", DataTypes.DOUBLE).add("d_array", new ArrayType(DataTypes.DOUBLE)).add("y_array", new ArrayType(DataTypes.LONG)).add("shape", DataTypes.GEO_SHAPE).add("point", DataTypes.GEO_POINT).build();
    TableRelation usersTr = new TableRelation(users);
    sources = ImmutableMap.of(new QualifiedName("users"), usersTr);
    expressions = new SqlExpressions(sources, usersTr);
    builder = new LuceneQueryBuilder(expressions.getInstance(Functions.class));
    indexCache = mock(IndexCache.class, Answers.RETURNS_MOCKS.get());
    Path tempDir = createTempDir();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", tempDir).build();
    Index index = new Index(users.ident().indexName());
    when(indexCache.indexSettings()).thenReturn(indexSettings);
    AnalysisService analysisService = createAnalysisService(indexSettings, index);
    mapperService = createMapperService(index, indexSettings, analysisService);
    // @formatter:off
    XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("default").startObject("properties").startObject("name").field("type", "string").endObject().startObject("x").field("type", "integer").endObject().startObject("d").field("type", "double").endObject().startObject("point").field("type", "geo_point").endObject().startObject("shape").field("type", "geo_shape").endObject().startObject("d_array").field("type", "array").startObject("inner").field("type", "double").endObject().endObject().startObject("y_array").field("type", "array").startObject("inner").field("type", "integer").endObject().endObject().endObject().endObject().endObject();
    // @formatter:on
    mapperService.merge("default", new CompressedXContent(xContentBuilder.bytes()), MapperService.MergeReason.MAPPING_UPDATE, true);
    indexFieldDataService = mock(IndexFieldDataService.class);
    IndexFieldData geoFieldData = mock(IndexGeoPointFieldData.class);
    when(geoFieldData.getFieldNames()).thenReturn(new MappedFieldType.Names("point"));
    when(indexFieldDataService.getForField(mapperService.smartNameFieldType("point"))).thenReturn(geoFieldData);
}
Also used : Path(java.nio.file.Path) DocTableInfo(io.crate.metadata.doc.DocTableInfo) QualifiedName(io.crate.sql.tree.QualifiedName) TableIdent(io.crate.metadata.TableIdent) Index(org.elasticsearch.index.Index) TableRelation(io.crate.analyze.relations.TableRelation) ArrayType(io.crate.types.ArrayType) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) IndexCache(org.elasticsearch.index.cache.IndexCache) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) AnalysisService(org.elasticsearch.index.analysis.AnalysisService) SqlExpressions(io.crate.testing.SqlExpressions) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Before(org.junit.Before)

Example 34 with Path

use of java.nio.file.Path in project crate by crate.

the class FileWriterProjectorTest method testWriteRawToFile.

@Test
public void testWriteRawToFile() throws Exception {
    Path file = createTempFile("out", "json");
    FileWriterProjector fileWriterProjector = new FileWriterProjector(executorService, file.toUri().toString(), null, null, ImmutableSet.of(), new HashMap<>(), null, WriterProjection.OutputFormat.JSON_OBJECT);
    new TestingBatchConsumer().accept(fileWriterProjector.apply(sourceSupplier.get()), null);
    assertEquals("input line 00\n" + "input line 01\n" + "input line 02\n" + "input line 03\n" + "input line 04\n", TestingHelpers.readFile(file.toAbsolutePath().toString()));
}
Also used : Path(java.nio.file.Path) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 35 with Path

use of java.nio.file.Path in project crate by crate.

the class SysShardsExpressionsTest method mockIndexShard.

private IndexShard mockIndexShard() {
    IndexService indexService = mock(IndexService.class);
    Index index = new Index(indexName);
    ShardId shardId = new ShardId(indexName, 1);
    IndexShard indexShard = mock(IndexShard.class);
    when(indexService.index()).thenReturn(index);
    when(indexShard.indexService()).thenReturn(indexService);
    when(indexShard.shardId()).thenReturn(shardId);
    when(indexShard.state()).thenReturn(IndexShardState.STARTED);
    StoreStats storeStats = mock(StoreStats.class);
    when(storeStats.getSizeInBytes()).thenReturn(123456L);
    when(indexShard.storeStats()).thenReturn(storeStats);
    Path dataPath = Paths.get("/dummy/" + indexName + "/1");
    when(indexShard.shardPath()).thenReturn(new ShardPath(false, dataPath, dataPath, "123", shardId));
    DocsStats docsStats = new DocsStats(654321L, 0L);
    when(indexShard.docStats()).thenReturn(docsStats).thenThrow(IllegalIndexShardStateException.class);
    ShardRouting shardRouting = ShardRouting.newUnassigned(index.name(), shardId.id(), null, true, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    ShardRoutingHelper.initialize(shardRouting, "node1");
    ShardRoutingHelper.moveToStarted(shardRouting);
    ShardRoutingHelper.relocate(shardRouting, "node_X");
    when(indexShard.routingEntry()).thenReturn(shardRouting);
    when(indexShard.minimumCompatibleVersion()).thenReturn(Version.LATEST);
    RecoveryState recoveryState = mock(RecoveryState.class);
    when(indexShard.recoveryState()).thenReturn(recoveryState);
    RecoveryState.Index recoveryStateIndex = mock(RecoveryState.Index.class);
    RecoveryState.Timer recoveryStateTimer = mock(RecoveryState.Timer.class);
    when(recoveryState.getIndex()).thenReturn(recoveryStateIndex);
    when(recoveryState.getStage()).thenReturn(RecoveryState.Stage.DONE);
    when(recoveryState.getTimer()).thenReturn(recoveryStateTimer);
    when(recoveryState.getType()).thenReturn(RecoveryState.Type.REPLICA);
    when(recoveryStateIndex.totalBytes()).thenReturn(2048L);
    when(recoveryStateIndex.reusedBytes()).thenReturn(1024L);
    when(recoveryStateIndex.recoveredBytes()).thenReturn(1024L);
    when(recoveryStateIndex.totalFileCount()).thenReturn(2);
    when(recoveryStateIndex.reusedFileCount()).thenReturn(1);
    when(recoveryStateIndex.recoveredFileCount()).thenReturn(1);
    when(recoveryStateTimer.time()).thenReturn(10000L);
    return indexShard;
}
Also used : Path(java.nio.file.Path) StoreStats(org.elasticsearch.index.store.StoreStats) IndexService(org.elasticsearch.index.IndexService) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) Index(org.elasticsearch.index.Index) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Aggregations

Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException (java.io.IOException)829 File (java.io.File)445 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream (java.io.InputStream)210 ImmutableList (com.google.common.collect.ImmutableList)175 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap (com.google.common.collect.ImmutableMap)157 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146