Search in sources :

Example 26 with Exception

use of java.lang.Exception in project hive by apache.

the class TestJdbcDriver2 method testShowRoleGrant.

@Test
public void testShowRoleGrant() throws SQLException {
    Statement stmt = con.createStatement();
    // drop role. ignore error.
    try {
        stmt.execute("drop role role1");
    } catch (Exception ex) {
        LOG.warn("Ignoring error during drop role: " + ex);
    }
    stmt.execute("create role role1");
    stmt.execute("grant role role1 to user hive_test_user");
    stmt.execute("show role grant user hive_test_user");
    ResultSet res = stmt.getResultSet();
    assertTrue(res.next());
    assertEquals("public", res.getString(1));
    assertTrue(res.next());
    assertEquals("role1", res.getString(1));
    res.close();
    stmt.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) 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 27 with Exception

use of java.lang.Exception in project hive by apache.

the class TestJdbcDriver2 method testQueryCancelTwice.

@Test
public void testQueryCancelTwice() throws Exception {
    String udfName = SleepMsUDF.class.getName();
    Statement stmt1 = con.createStatement();
    stmt1.execute("create temporary function sleepMsUDF as '" + udfName + "'");
    stmt1.close();
    final Statement stmt = con.createStatement();
    // Thread executing the query
    Thread tExecute = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                System.out.println("Executing query: ");
                // The test table has 500 rows, so total query time should be ~ 500*500ms
                stmt.executeQuery("select sleepMsUDF(t1.under_col, 1) as u0, t1.under_col as u1, " + "t2.under_col as u2 from " + tableName + " t1 join " + tableName + " t2 on t1.under_col = t2.under_col");
                fail("Expecting SQLException");
            } catch (SQLException e) {
                // This thread should throw an exception
                assertNotNull(e);
                System.out.println(e.toString());
            }
        }
    });
    // Thread cancelling the query
    Thread tCancel = new Thread(new Runnable() {

        @Override
        public void run() {
            // 1st Cancel
            try {
                // Sleep for 100ms
                Thread.sleep(100);
                System.out.println("Cancelling query: ");
                stmt.cancel();
            } catch (Exception e) {
            // No-op
            }
            // 2nd cancel
            try {
                // Sleep for 5ms and cancel again
                Thread.sleep(5);
                System.out.println("Cancelling query again: ");
                stmt.cancel();
            } catch (Exception e) {
            // No-op
            }
        }
    });
    tExecute.start();
    tCancel.start();
    tExecute.join();
    tCancel.join();
    stmt.close();
}
Also used : SQLException(java.sql.SQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) 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 28 with Exception

use of java.lang.Exception in project hive by apache.

the class TestJdbcDriver2 method testPrepareSetDate.

@Test
public void testPrepareSetDate() throws Exception {
    try {
        String sql = "select * from " + dataTypeTableName + " where c20 = ?";
        PreparedStatement ps = con.prepareStatement(sql);
        java.sql.Date dtValue = java.sql.Date.valueOf("2013-01-01");
        ps.setDate(1, dtValue);
        ResultSet res = ps.executeQuery();
        assertTrue(res.next());
        assertEquals("2013-01-01", res.getString(20));
        ps.close();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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 29 with Exception

use of java.lang.Exception in project tigervnc by TigerVNC.

the class DesktopWindow method enableLionFS.

void enableLionFS() {
    try {
        String version = System.getProperty("os.version");
        int firstDot = version.indexOf('.');
        int lastDot = version.lastIndexOf('.');
        if (lastDot > firstDot && lastDot >= 0) {
            version = version.substring(0, version.indexOf('.', firstDot + 1));
        }
        double v = Double.parseDouble(version);
        if (v < 10.7)
            throw new Exception("Operating system version is " + v);
        Class fsuClass = Class.forName("com.apple.eawt.FullScreenUtilities");
        Class[] argClasses = new Class[] { Window.class, Boolean.TYPE };
        Method setWindowCanFullScreen = fsuClass.getMethod("setWindowCanFullScreen", argClasses);
        setWindowCanFullScreen.invoke(fsuClass, this, true);
        canDoLionFS = true;
    } catch (Exception e) {
        vlog.debug("Could not enable OS X 10.7+ full-screen mode: " + e.getMessage());
    }
}
Also used : Point(com.tigervnc.rfb.Point) Exception(java.lang.Exception)

Example 30 with Exception

use of java.lang.Exception in project Payara by payara.

the class MultipleSPETest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS-bookstore application. Deployment should fail
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/basic-spe-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNull(appName);
    } catch (Exception e) {
        System.out.println("$$$$$$$$$$$$$$$$Exception$$$$$$");
    } finally {
        // 3. Register one of the plugins as the default S.P.E
        ServiceLocator habitat = Globals.getDefaultHabitat();
        org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        ActionReport report = habitat.getService(ActionReport.class);
        org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("register-service-provisioning-engine", report);
        ParameterMap parameterMap = new ParameterMap();
        parameterMap.add("type", "Database");
        parameterMap.add("defaultservice", "true");
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Registered a default SPE :" + !report.hasFailures());
        // 4. Deploy the application. Deployment should succeed.
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        // 5. Access the app to make sure PaaS-basic-shared-service-test app is correctly
        // provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/basic-spe-test/list", "Here is a list of animals in the zoo.");
        // Retrieve the  port number used by the connection pool
        invocation = commandRunner.getCommandInvocation("get", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "server.resources.jdbc-connection-pool.jdbc/__multiple_spe_paas_sample.property.PortNumber");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                if (commandResult.getOutput().contains("Nothing to list.")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
        commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        invocation = commandRunner.getCommandInvocation("unregister-service-provisioning-engine", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Unregistered the default SPE :" + !report.hasFailures());
    }
}
Also used : PrintStream(java.io.PrintStream) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) PaaSDeploymentException(org.glassfish.paas.orchestrator.PaaSDeploymentException) IOException(java.io.IOException) Exception(java.lang.Exception) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) 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