@Override public boolean isClosed() { try { return super.isClosed(); } catch (SQLException e) { // Currently can't happen, since AvaticaConnection.isClosed() never throws // SQLException. throw new DrillRuntimeException( "Unexpected exception from " + getClass().getSuperclass() + ".isClosed(): " + e, e ); } }
public boolean isValid(int timeout) throws SQLException { if (timeout < 0) { throw HELPER.createException("timeout is less than 0"); } // TODO check if connection is actually alive using timeout return !isClosed(); }
protected void checkOpen() throws SQLException { if (isClosed()) { throw HELPER.closed(); } } // Connection methods
public boolean isValid(int timeout) throws SQLException { if (timeout < 0) { throw HELPER.createException("timeout is less than 0"); } // TODO check if connection is actually alive using timeout return !isClosed(); }
protected void checkOpen() throws SQLException { if (isClosed()) { throw HELPER.closed(); } } // Connection methods
@Override public boolean isClosed() { try { return super.isClosed(); } catch (SQLException e) { // Currently can't happen, since AvaticaConnection.isClosed() never throws // SQLException. throw new DrillRuntimeException( "Unexpected exception from " + getClass().getSuperclass() + ".isClosed(): " + e, e ); } }
@Test public void testIsValid() throws SQLException { AvaticaConnection connection = Mockito.mock(AvaticaConnection.class, Mockito.CALLS_REAL_METHODS); try { connection.isValid(-1); Assert.fail("Connection isValid should throw SQLException on negative timeout"); } catch (SQLException expected) { Assert.assertEquals("timeout is less than 0", expected.getMessage()); } Mockito.when(connection.isClosed()).thenReturn(false); Assert.assertTrue(connection.isValid(0)); Mockito.when(connection.isClosed()).thenReturn(true); Assert.assertFalse(connection.isValid(0)); }
@Override protected Connection newInstance() throws Exception { UnregisteredDriver driver = new TestDriver(); AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(), "jdbc:avatica", new Properties()) { }; connection.close(); assertTrue("Connection is not closed", connection.isClosed()); return connection; } }
@Override protected Connection newInstance() throws Exception { UnregisteredDriver driver = new TestDriver(); AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(), "jdbc:avatica", new Properties()) { }; connection.close(); assertTrue("Connection is not closed", connection.isClosed()); return connection; } }
@Test public void testIsValid() throws SQLException { AvaticaConnection connection = Mockito.mock(AvaticaConnection.class, Mockito.CALLS_REAL_METHODS); try { connection.isValid(-1); Assert.fail("Connection isValid should throw SQLException on negative timeout"); } catch (SQLException expected) { Assert.assertEquals("timeout is less than 0", expected.getMessage()); } Mockito.when(connection.isClosed()).thenReturn(false); Assert.assertTrue(connection.isValid(0)); Mockito.when(connection.isClosed()).thenReturn(true); Assert.assertFalse(connection.isValid(0)); }