use of java.lang.Exception in project lucene-solr by apache.
the class TestWindowsFS method testOpenDeleteConcurrently.
public void testOpenDeleteConcurrently() throws IOException, Exception {
final Path dir = wrap(createTempDir());
final Path file = dir.resolve("thefile");
final CyclicBarrier barrier = new CyclicBarrier(2);
final AtomicBoolean stopped = new AtomicBoolean(false);
Thread t = new Thread() {
@Override
public void run() {
try {
barrier.await();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
while (stopped.get() == false) {
try {
if (random().nextBoolean()) {
Files.delete(file);
} else if (random().nextBoolean()) {
Files.deleteIfExists(file);
} else {
Path target = file.resolveSibling("other");
Files.move(file, target);
Files.delete(target);
}
} catch (IOException ex) {
// continue
}
}
}
};
t.start();
barrier.await();
try {
final int iters = 10 + random().nextInt(100);
for (int i = 0; i < iters; i++) {
boolean opened = false;
try (OutputStream stream = Files.newOutputStream(file)) {
opened = true;
stream.write(0);
// just create
} catch (FileNotFoundException | NoSuchFileException ex) {
assertEquals("File handle leaked - file is closed but still registered", 0, ((WindowsFS) dir.getFileSystem().provider()).openFiles.size());
assertFalse("caught FNF on close", opened);
}
assertEquals("File handle leaked - file is closed but still registered", 0, ((WindowsFS) dir.getFileSystem().provider()).openFiles.size());
Files.deleteIfExists(file);
}
} finally {
stopped.set(true);
t.join();
}
}
use of java.lang.Exception in project hive by apache.
the class TestJdbcDriver2 method checkResultSetExpected.
private void checkResultSetExpected(Statement stmt, List<String> setupQueries, String testQuery, boolean isExpectedResultSet) throws Exception {
boolean hasResultSet;
// execute the setup queries
for (String setupQuery : setupQueries) {
try {
stmt.execute(setupQuery);
} catch (Exception e) {
failWithExceptionMsg(e);
}
}
// execute the test query
try {
hasResultSet = stmt.execute(testQuery);
assertEquals(hasResultSet, isExpectedResultSet);
} catch (Exception e) {
failWithExceptionMsg(e);
}
}
use of java.lang.Exception in project hive by apache.
the class TestJdbcDriver2 method testClientInfo.
@Test
public void testClientInfo() throws SQLException {
DatabaseMetaData meta = con.getMetaData();
ResultSet res = meta.getClientInfoProperties();
try {
assertTrue(res.next());
assertEquals("ApplicationName", res.getString(1));
assertEquals(1000, res.getInt("MAX_LEN"));
assertFalse(res.next());
} catch (Exception e) {
String msg = "Unexpected exception: " + e;
LOG.info(msg, e);
fail(msg);
}
Connection conn = getConnection("");
try {
conn.setClientInfo("ApplicationName", "test");
assertEquals("test", conn.getClientInfo("ApplicationName"));
} finally {
conn.close();
}
}
use of java.lang.Exception in project hive by apache.
the class TestJdbcDriver2 method testNonAsciiReturnValues.
/**
* Loads data from a table containing non-ascii value column
* Runs a query and compares the return value
* @throws Exception
*/
@Test
public void testNonAsciiReturnValues() throws Exception {
String nonAsciiTableName = "nonAsciiTable";
String nonAsciiString = "Garçu Kôkaku kidôtai";
Path nonAsciiFilePath = new Path(dataFileDir, "non_ascii_tbl.txt");
Statement stmt = con.createStatement();
stmt.execute("set hive.support.concurrency = false");
// Create table
stmt.execute("create table " + nonAsciiTableName + " (key int, value string) " + "row format delimited fields terminated by '|'");
// Load data
stmt.execute("load data local inpath '" + nonAsciiFilePath.toString() + "' into table " + nonAsciiTableName);
ResultSet rs = stmt.executeQuery("select value from " + nonAsciiTableName + " limit 1");
while (rs.next()) {
String resultValue = rs.getString(1);
assertTrue(resultValue.equalsIgnoreCase(nonAsciiString));
}
// Drop table, ignore error.
try {
stmt.execute("drop table " + nonAsciiTableName);
} catch (Exception ex) {
// no-op
}
stmt.close();
}
use of java.lang.Exception in project hive by apache.
the class TestJdbcDriver2 method testSetOnConnection.
@Test
public void testSetOnConnection() throws Exception {
Connection connection = getConnection(testDbName + "?conf1=conf2;conf3=conf4#var1=var2;var3=var4");
try {
verifyConfValue(connection, "conf1", "conf2");
verifyConfValue(connection, "conf3", "conf4");
verifyConfValue(connection, "var1", "var2");
verifyConfValue(connection, "var3", "var4");
} catch (Exception e) {
connection.close();
}
}
Aggregations