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