Search in sources :

Example 66 with Path

use of java.nio.file.Path in project druid by druid-io.

the class HadoopConverterJobTest method corrupt.

private static void corrupt(DataSegment segment) throws IOException {
    final Map<String, Object> localLoadSpec = segment.getLoadSpec();
    final Path segmentPath = Paths.get(localLoadSpec.get("path").toString());
    final MappedByteBuffer buffer = Files.map(segmentPath.toFile(), FileChannel.MapMode.READ_WRITE);
    while (buffer.hasRemaining()) {
        buffer.put((byte) 0xFF);
    }
}
Also used : Path(java.nio.file.Path) MappedByteBuffer(java.nio.MappedByteBuffer)

Example 67 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class ScriptServiceTests method setup.

@Before
public void setup() throws IOException {
    Path genericConfigFolder = createTempDir();
    baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder).put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 10000).build();
    resourceWatcherService = new ResourceWatcherService(baseSettings, null);
    scriptEngineService = new TestEngineService();
    dangerousScriptEngineService = new TestDangerousEngineService();
    TestEngineService defaultScriptServiceEngine = new TestEngineService(Script.DEFAULT_SCRIPT_LANG) {
    };
    scriptEnginesByLangMap = ScriptModesTests.buildScriptEnginesByLangMap(new HashSet<>(Arrays.asList(scriptEngineService, defaultScriptServiceEngine)));
    //randomly register custom script contexts
    int randomInt = randomIntBetween(0, 3);
    //prevent duplicates using map
    Map<String, ScriptContext.Plugin> contexts = new HashMap<>();
    for (int i = 0; i < randomInt; i++) {
        String plugin;
        do {
            plugin = randomAsciiOfLength(randomIntBetween(1, 10));
        } while (ScriptContextRegistry.RESERVED_SCRIPT_CONTEXTS.contains(plugin));
        String operation;
        do {
            operation = randomAsciiOfLength(randomIntBetween(1, 30));
        } while (ScriptContextRegistry.RESERVED_SCRIPT_CONTEXTS.contains(operation));
        String context = plugin + "_" + operation;
        contexts.put(context, new ScriptContext.Plugin(plugin, operation));
    }
    scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(scriptEngineService, dangerousScriptEngineService, defaultScriptServiceEngine));
    scriptContextRegistry = new ScriptContextRegistry(contexts.values());
    scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]);
    logger.info("--> setup script service");
    scriptsFilePath = genericConfigFolder.resolve("scripts");
    Files.createDirectories(scriptsFilePath);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 68 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class ScriptedMetricIT method nodeSettings.

@Override
protected Settings nodeSettings(int nodeOrdinal) {
    Path config = createTempDir().resolve("config");
    Path scripts = config.resolve("scripts");
    try {
        Files.createDirectories(scripts);
        // When using the MockScriptPlugin we can map File scripts to inline scripts:
        // the name of the file script is used in test method while the source of the file script
        // must match a predefined script from CustomScriptPlugin.pluginScripts() method
        Files.write(scripts.resolve("init_script.mockscript"), "vars.multiplier = 3".getBytes("UTF-8"));
        Files.write(scripts.resolve("map_script.mockscript"), "_agg.add(vars.multiplier)".getBytes("UTF-8"));
        Files.write(scripts.resolve("combine_script.mockscript"), "sum agg values as a new aggregation".getBytes("UTF-8"));
        Files.write(scripts.resolve("reduce_script.mockscript"), "sum aggs of agg values as a new aggregation".getBytes("UTF-8"));
    } catch (IOException e) {
        throw new RuntimeException("failed to create scripts");
    }
    return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(Environment.PATH_CONF_SETTING.getKey(), config).build();
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException)

Example 69 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class AbstractSortTestCase method init.

@BeforeClass
public static void init() throws IOException {
    Path genericConfigFolder = createTempDir();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder).build();
    Environment environment = new Environment(baseSettings);
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngineService()));
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptService = new ScriptService(baseSettings, environment, new ResourceWatcherService(baseSettings, null), scriptEngineRegistry, scriptContextRegistry, scriptSettings) {

        @Override
        public CompiledScript compile(Script script, ScriptContext scriptContext) {
            return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);
        }
    };
    SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : Path(java.nio.file.Path) ContentPath(org.elasticsearch.index.mapper.ContentPath) CompiledScript(org.elasticsearch.script.CompiledScript) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ScriptContext(org.elasticsearch.script.ScriptContext) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) ScriptService(org.elasticsearch.script.ScriptService) ScriptSettings(org.elasticsearch.script.ScriptSettings) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) Environment(org.elasticsearch.env.Environment) SearchModule(org.elasticsearch.search.SearchModule) TestEngineService(org.elasticsearch.script.ScriptServiceTests.TestEngineService) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings) IndexSettings(org.elasticsearch.index.IndexSettings) BeforeClass(org.junit.BeforeClass)

Example 70 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDeleteSnapshotWithMissingMetadata.

public void testDeleteSnapshotWithMissingMetadata() throws Exception {
    Client client = client();
    Path repo = randomRepoPath();
    logger.info("-->  creating repository at {}", repo.toAbsolutePath());
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repo).put("compress", false).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    createIndex("test-idx-1", "test-idx-2");
    logger.info("--> indexing some data");
    indexRandom(true, client().prepareIndex("test-idx-1", "doc").setSource("foo", "bar"), client().prepareIndex("test-idx-2", "doc").setSource("foo", "bar"));
    logger.info("--> creating snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).setIndices("test-idx-*").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> delete index metadata and shard metadata");
    Path metadata = repo.resolve("meta-" + createSnapshotResponse.getSnapshotInfo().snapshotId().getUUID() + ".dat");
    Files.delete(metadata);
    logger.info("--> delete snapshot");
    client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
    logger.info("--> make sure snapshot doesn't exist");
    assertThrows(client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap-1"), SnapshotMissingException.class);
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Client(org.elasticsearch.client.Client)

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