List of usage examples for org.apache.hadoop.fs FileUtil chmod
public static int chmod(String filename, String perm, boolean recursive) throws IOException
From source file:org.talend.components.simplefileio.runtime.SimpleFileIOOutputErrorTest.java
License:Open Source License
/** * Basic unit test using all default values (except for the path) on an in-memory DFS cluster. *//*from w w w. java 2 s. c o m*/ @Test public void testUnauthorizedOverwrite() throws IOException, URISyntaxException { Path parent = new Path(mini.newFolder().toString()); Path dst = new Path(parent, "output"); String fileSpec = mini.getLocalFs().getUri().resolve(dst.toUri()).toString(); // Write something to the file before trying to run. try (OutputStream out = mini.getLocalFs().create(new Path(dst, "part-00000"))) { out.write(0); } // Ensure that the destination is unwritable. FileUtil.chmod(dst.toUri().toString(), "000", true); // Trying to overwrite an unmodifiable destination throws an exception. thrown.expect(TalendRuntimeException.class); thrown.expect(hasProperty("code", is(SimpleFileIOErrorCode.OUTPUT_NOT_AUTHORIZED))); thrown.expectMessage( "Can not write to " + fileSpec + ". Please check user permissions or existence of base directory."); // Now try using the component. try { // Configure the component. SimpleFileIOOutputProperties props = SimpleFileIOOutputRuntimeTest.createOutputComponentProperties(); props.getDatasetProperties().path.setValue(fileSpec); props.overwrite.setValue(true); // Create the runtime. SimpleFileIOOutputRuntime runtime = new SimpleFileIOOutputRuntime(); runtime.initialize(null, props); // Use the runtime in a direct pipeline to test. final Pipeline p = beam.createPipeline(); PCollection<IndexedRecord> input = p.apply( // Create.of(ConvertToIndexedRecord.convertToAvro(new String[] { "1", "one" }), // ConvertToIndexedRecord.convertToAvro(new String[] { "2", "two" }))); // input.apply(runtime); // And run the test. runtime.runAtDriver(null); p.run().waitUntilFinish(); } catch (Pipeline.PipelineExecutionException e) { if (e.getCause() instanceof TalendRuntimeException) throw (TalendRuntimeException) e.getCause(); throw e; } }
From source file:org.talend.components.simplefileio.runtime.SimpleFileIOOutputErrorTest.java
License:Open Source License
/** * Basic unit test using all default values (except for the path) on an in-memory DFS cluster. *///ww w .jav a 2 s .c o m @Test public void testUnauthorizedAccess() throws IOException, URISyntaxException { Path parent = new Path(mini.newFolder().toString()); String fileSpec = mini.getLocalFs().getUri().resolve(new Path(parent, "output.csv").toUri()).toString(); // Ensure that the parent is unwritable. FileUtil.chmod(parent.toUri().toString(), "000", true); // Requesting a wrong execution engine causes an exception. thrown.expect(TalendRuntimeException.class); thrown.expect(hasProperty("code", is(SimpleFileIOErrorCode.OUTPUT_NOT_AUTHORIZED))); thrown.expectMessage( "Can not write to " + fileSpec + ". Please check user permissions or existence of base directory."); // Now try using the component. try { // Configure the component. SimpleFileIOOutputProperties props = SimpleFileIOOutputRuntimeTest.createOutputComponentProperties(); props.getDatasetProperties().path.setValue(fileSpec); // Create the runtime. SimpleFileIOOutputRuntime runtime = new SimpleFileIOOutputRuntime(); runtime.initialize(null, props); // Use the runtime in a direct pipeline to test. final Pipeline p = beam.createPipeline(); PCollection<IndexedRecord> input = p.apply( // Create.of(ConvertToIndexedRecord.convertToAvro(new String[] { "1", "one" }), // ConvertToIndexedRecord.convertToAvro(new String[] { "2", "two" }))); // input.apply(runtime); // And run the test. p.run().waitUntilFinish(); } catch (Pipeline.PipelineExecutionException e) { if (e.getCause() instanceof TalendRuntimeException) throw (TalendRuntimeException) e.getCause(); throw e; } // Check the expected values. mini.assertReadFile(mini.getLocalFs(), fileSpec, "1;one", "2;two"); }