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();
}
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);
}
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;
}
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;
}
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"));
}
Aggregations