Search in sources :

Example 21 with Exception

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();
    }
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) RuntimeException(java.lang.RuntimeException) FileNotFoundException(java.io.FileNotFoundException) Exception(java.lang.Exception) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RuntimeException(java.lang.RuntimeException) WindowsFS(org.apache.lucene.mockfile.WindowsFS)

Example 22 with Exception

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);
    }
}
Also used : String(java.lang.String) SQLTimeoutException(java.sql.SQLTimeoutException) ParseException(java.text.ParseException) Exception(java.lang.Exception) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 23 with Exception

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();
    }
}
Also used : ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) String(java.lang.String) DatabaseMetaData(java.sql.DatabaseMetaData) SQLTimeoutException(java.sql.SQLTimeoutException) ParseException(java.text.ParseException) Exception(java.lang.Exception) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) Test(org.junit.Test)

Example 24 with Exception

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();
}
Also used : Path(org.apache.hadoop.fs.Path) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) String(java.lang.String) SQLTimeoutException(java.sql.SQLTimeoutException) ParseException(java.text.ParseException) Exception(java.lang.Exception) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) Test(org.junit.Test)

Example 25 with Exception

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();
    }
}
Also used : Connection(java.sql.Connection) SQLTimeoutException(java.sql.SQLTimeoutException) ParseException(java.text.ParseException) Exception(java.lang.Exception) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) Test(org.junit.Test)

Aggregations

Exception (java.lang.Exception)32 IOException (java.io.IOException)15 ParseException (java.text.ParseException)12 Test (org.junit.Test)12 String (java.lang.String)11 SQLException (java.sql.SQLException)11 SQLTimeoutException (java.sql.SQLTimeoutException)11 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)11 ExpectedException (org.junit.rules.ExpectedException)11 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)7 RuntimeException (java.lang.RuntimeException)6 Statement (java.sql.Statement)6 ArrayList (java.util.ArrayList)5 IllegalArgumentException (java.lang.IllegalArgumentException)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IllegalStateException (java.lang.IllegalStateException)3 NumberFormatException (java.lang.NumberFormatException)3 Object (java.lang.Object)3