Search in sources :

Example 96 with FileWriter

use of java.io.FileWriter in project hbase by apache.

the class TestZooKeeperACL method testIsZooKeeperSecure.

/**
   * Check if ZooKeeper JaasConfiguration is valid.
   */
@Test
public void testIsZooKeeperSecure() throws Exception {
    boolean testJaasConfig = ZKUtil.isSecureZooKeeper(new Configuration(TEST_UTIL.getConfiguration()));
    assertEquals(testJaasConfig, secureZKAvailable);
    // Define Jaas configuration without ZooKeeper Jaas config
    File saslConfFile = File.createTempFile("tmp", "fakeJaas.conf");
    FileWriter fwriter = new FileWriter(saslConfFile);
    fwriter.write("");
    fwriter.close();
    System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath());
    testJaasConfig = ZKUtil.isSecureZooKeeper(new Configuration(TEST_UTIL.getConfiguration()));
    assertEquals(testJaasConfig, false);
    saslConfFile.delete();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) File(java.io.File) Test(org.junit.Test)

Example 97 with FileWriter

use of java.io.FileWriter in project hbase by apache.

the class TestZooKeeperACL method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    File saslConfFile = File.createTempFile("tmp", "jaas.conf");
    FileWriter fwriter = new FileWriter(saslConfFile);
    fwriter.write("" + "Server {\n" + "org.apache.zookeeper.server.auth.DigestLoginModule required\n" + "user_hbase=\"secret\";\n" + "};\n" + "Client {\n" + "org.apache.zookeeper.server.auth.DigestLoginModule required\n" + "username=\"hbase\"\n" + "password=\"secret\";\n" + "};" + "\n");
    fwriter.close();
    System.setProperty("java.security.auth.login.config", saslConfFile.getAbsolutePath());
    System.setProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
    TEST_UTIL.getConfiguration().setInt("hbase.zookeeper.property.maxClientCnxns", 1000);
    // the JAAS configuration required by ZK being clobbered by Hadoop 
    try {
        TEST_UTIL.startMiniCluster();
    } catch (IOException e) {
        LOG.warn("Hadoop is missing HADOOP-7070", e);
        secureZKAvailable = false;
        return;
    }
    zkw = new ZooKeeperWatcher(new Configuration(TEST_UTIL.getConfiguration()), TestZooKeeper.class.getName(), null);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 98 with FileWriter

use of java.io.FileWriter in project hive by apache.

the class TestSchemaTool method writeDummyPreUpgradeScript.

/**
   * Write out a dummy pre-upgrade script with given SQL statement.
   */
private String writeDummyPreUpgradeScript(int index, String upgradeScriptName, String sql) throws Exception {
    String preUpgradeScript = "pre-" + index + "-" + upgradeScriptName;
    String dummyPreScriptPath = System.getProperty("test.tmp.dir", "target/tmp") + File.separatorChar + "scripts" + File.separatorChar + "metastore" + File.separatorChar + "upgrade" + File.separatorChar + "derby" + File.separatorChar + preUpgradeScript;
    FileWriter fstream = new FileWriter(dummyPreScriptPath);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(sql + System.getProperty("line.separator") + ";");
    out.close();
    return preUpgradeScript;
}
Also used : FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 99 with FileWriter

use of java.io.FileWriter in project tomcat by apache.

the class TestSendFile method generateFile.

public File generateFile(String dir, String suffix, int size) throws IOException {
    String name = "testSendFile-" + System.currentTimeMillis() + suffix + ".txt";
    File f = new File(dir, name);
    try (FileWriter fw = new FileWriter(f, false);
        BufferedWriter w = new BufferedWriter(fw)) {
        int defSize = 8192;
        while (size > 0) {
            int bytes = Math.min(size, defSize);
            char[] b = new char[bytes];
            Arrays.fill(b, 'X');
            w.write(b);
            size = size - bytes;
        }
        w.flush();
    }
    System.out.println("Created file:" + f.getAbsolutePath() + " with " + f.length() + " bytes.");
    return f;
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 100 with FileWriter

use of java.io.FileWriter in project zeppelin by apache.

the class PigInterpreterTezTest method testIncludeJobStats.

@Test
public void testIncludeJobStats() throws IOException {
    setUpTez(true);
    String content = "1\tandy\n" + "2\tpeter\n";
    File tmpFile = File.createTempFile("zeppelin", "test");
    FileWriter writer = new FileWriter(tmpFile);
    IOUtils.write(content, writer);
    writer.close();
    // simple pig script using dump
    String pigscript = "a = load '" + tmpFile.getAbsolutePath() + "';" + "dump a;";
    InterpreterResult result = pigInterpreter.interpret(pigscript, context);
    assertEquals(Type.TEXT, result.message().get(0).getType());
    assertEquals(Code.SUCCESS, result.code());
    assertTrue(result.message().get(0).getData().contains("Vertex Stats"));
    assertTrue(result.message().get(0).getData().contains("(1,andy)\n(2,peter)"));
    // describe
    pigscript = "a = load '" + tmpFile.getAbsolutePath() + "' as (id: int, name: bytearray);" + "describe a;";
    result = pigInterpreter.interpret(pigscript, context);
    assertEquals(Type.TEXT, result.message().get(0).getType());
    assertEquals(Code.SUCCESS, result.code());
    // no job is launched, so no jobStats
    assertTrue(!result.message().get(0).getData().contains("Vertex Stats"));
    assertTrue(result.message().get(0).getData().contains("a: {id: int,name: bytearray}"));
    // syntax error (compilation error)
    pigscript = "a = loa '" + tmpFile.getAbsolutePath() + "';" + "describe a;";
    result = pigInterpreter.interpret(pigscript, context);
    assertEquals(Type.TEXT, result.message().get(0).getType());
    assertEquals(Code.ERROR, result.code());
    // no job is launched, so no jobStats
    assertTrue(!result.message().get(0).getData().contains("Vertex Stats"));
    assertTrue(result.message().get(0).getData().contains("Syntax error, unexpected symbol at or near 'a'"));
    // execution error
    pigscript = "a = load 'invalid_path';" + "dump a;";
    result = pigInterpreter.interpret(pigscript, context);
    assertEquals(Type.TEXT, result.message().get(0).getType());
    assertEquals(Code.ERROR, result.code());
    assertTrue(!result.message().get(0).getData().contains("Vertex Stats"));
    assertTrue(result.message().get(0).getData().contains("Input path does not exist"));
}
Also used : FileWriter(java.io.FileWriter) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) File(java.io.File) Test(org.junit.Test)

Aggregations

FileWriter (java.io.FileWriter)1776 File (java.io.File)1056 IOException (java.io.IOException)741 BufferedWriter (java.io.BufferedWriter)705 PrintWriter (java.io.PrintWriter)285 Test (org.junit.Test)222 Writer (java.io.Writer)162 FileReader (java.io.FileReader)121 BufferedReader (java.io.BufferedReader)107 ArrayList (java.util.ArrayList)101 FileNotFoundException (java.io.FileNotFoundException)68 Date (java.util.Date)61 Properties (java.util.Properties)61 FileOutputStream (java.io.FileOutputStream)58 HashMap (java.util.HashMap)53 StringWriter (java.io.StringWriter)50 Path (org.apache.hadoop.fs.Path)49 FileInputStream (java.io.FileInputStream)47 Map (java.util.Map)33 OutputStreamWriter (java.io.OutputStreamWriter)31