private static void closeSession(SessionState ss) { try { ss.close(); } catch (IOException e1) { LOG.error("Failed to close the session", e1); } }
@Override public void close() { try { super.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
/** * Wrapper for System.exit that makes sure we close our SessionState * before we exit. This ignores any error generated by attempting to * close the session state, merely printing out the error. The return * code is not changed in such an occurrence because we want to retain * the success code of whatever command we already ran. */ private static void sysExit(SessionState ss, int retCode) { try { ss.close(); } catch (IOException e) { // If we got an error attempting to ss.close, then it's not likely that // ss.err is valid. So we're back to System.err. Also, we don't change // the return code, we simply log a warning, and return whatever return // code we expected to do already. System.err.println(e.getMessage()); e.printStackTrace(System.err); } System.exit(retCode); }
@AfterClass public static void cleanUp() throws IOException { if(sessionState != null) { sessionState.close(); } }
LOG.error("Analyze command failed: " + cmd, e); try { ss.close(); } catch (IOException e1) { LOG.warn("Failed to close a bad session", e1);
localSession.close();
if (localSession != null) { try { localSession.close(); } catch (IOException ex) { LOG.warn(ci + ": localSession.close() failed due to: " + ex.getMessage(), ex);
@After public void tearDown() throws Exception { SessionState.get().close(); utils = null; work = null; task = null; path = null; fs = null; }
@Test public void testDuplicateAdds() throws URISyntaxException, IOException { SessionState ss = Mockito.spy(SessionState.start(conf).get()); String query = "testQuery"; List<URI> list = new LinkedList<URI>(); List<String> addList = new LinkedList<String>(); list.add(createURI(TEST_JAR_DIR + "testjar1.jar")); list.add(createURI(TEST_JAR_DIR + "testjar2.jar")); list.add(createURI(TEST_JAR_DIR + "testjar3.jar")); list.add(createURI(TEST_JAR_DIR + "testjar4.jar")); list.add(createURI(TEST_JAR_DIR + "testjar5.jar")); Collections.sort(list); Mockito.when(ss.resolveAndDownload(t, query, false)).thenReturn(list); for (int i = 0; i < 10; i++) { addList.add(query); } ss.add_resources(t, addList); Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { actual.add(createURI(dependency)); } Collections.sort(actual); assertEquals(list, actual); ss.close(); }
@Test public void testSanity() throws URISyntaxException, IOException { SessionState ss = Mockito.spy(SessionState.start(conf).get()); String query = "testQuery"; // add all the dependencies to a list List<URI> list = new LinkedList<URI>(); List<String> addList = new LinkedList<String>(); list.add(createURI(TEST_JAR_DIR + "testjar1.jar")); list.add(createURI(TEST_JAR_DIR + "testjar2.jar")); list.add(createURI(TEST_JAR_DIR + "testjar3.jar")); list.add(createURI(TEST_JAR_DIR + "testjar4.jar")); list.add(createURI(TEST_JAR_DIR + "testjar5.jar")); //return all the dependency urls Mockito.when(ss.resolveAndDownload(t, query, false)).thenReturn(list); addList.add(query); ss.add_resources(t, addList); Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { actual.add(createURI(dependency)); } // sort both the lists Collections.sort(list); Collections.sort(actual); assertEquals(list, actual); ss.close(); }
assertEquals(dependencies.isEmpty(), true); ss.close();
ss.close();
assertEquals(dependencies.isEmpty(), true); ss.close();
if (!isOk) { try { sessionState.close(); // This also resets SessionState.get. } catch (Throwable th) { LOG.warn("Failed to close a bad session", th);
@Test public void testReloadAuxJars2() { HiveConf conf = new HiveConf(); HiveConf.setVar(conf, ConfVars.HIVERELOADABLEJARS, hiveReloadPath); SessionState ss = new SessionState(conf); SessionState.start(ss); ss = SessionState.get(); File dist = null; try { dist = new File(reloadFolder.getAbsolutePath() + File.separator + reloadClazzFileName); Files.copy(new File(HiveTestUtils.getFileFromClasspath(clazzDistFileName)), dist); ss.loadReloadableAuxJars(); Assert.assertEquals("version1", getReloadedClazzVersion(ss.getConf().getClassLoader())); } catch (Exception e) { LOG.error("Reload auxiliary jar test fail with message: ", e); Assert.fail(e.getMessage()); } finally { FileUtils.deleteQuietly(dist); try { ss.close(); } catch (IOException ioException) { Assert.fail(ioException.getMessage()); LOG.error("Fail to close the created session: ", ioException); } } }
@Test public void testClose() throws Exception { SessionState ss = SessionState.get(); assertNull(ss.getTezSession()); ss.close(); assertNull(ss.getTezSession()); }
FileUtils.deleteQuietly(dist); try { ss.close(); } catch (IOException ioException) { Assert.fail(ioException.getMessage());