mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
ZEPPELIN-70: Closed previous connection before open new one. Register psql in ZeppelinConfiguration
This commit is contained in:
parent
886eab5c59
commit
a7d26ddd90
3 changed files with 29 additions and 2 deletions
|
|
@ -108,6 +108,9 @@ public class PostgreSqlInterpreter extends Interpreter {
|
|||
|
||||
logger.info("Open psql connection!");
|
||||
|
||||
// Ensure that no previous connections are left open.
|
||||
close();
|
||||
|
||||
try {
|
||||
|
||||
String driverName = getProperty(POSTGRESQL_SERVER_DRIVER_NAME);
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@
|
|||
package org.apache.zeppelin.postgresql;
|
||||
|
||||
import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
|
@ -27,6 +28,8 @@ import java.util.Properties;
|
|||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter;
|
||||
import com.mockrunner.jdbc.StatementResultSetHandler;
|
||||
|
|
@ -49,10 +52,27 @@ public class PostgreSqlInterpreterTest extends BasicJDBCTestCaseAdapter {
|
|||
result = statementHandler.createResultSet();
|
||||
statementHandler.prepareGlobalResultSet(result);
|
||||
|
||||
psqlInterpreter = spy(new PostgreSqlInterpreter(new Properties()));
|
||||
Properties properties = new Properties();
|
||||
properties.put(POSTGRESQL_SERVER_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME);
|
||||
properties.put(POSTGRESQL_SERVER_URL, DEFAULT_JDBC_URL);
|
||||
properties.put(POSTGRESQL_SERVER_USER, DEFAULT_JDBC_USER_NAME);
|
||||
properties.put(POSTGRESQL_SERVER_PASSWORD, DEFAULT_JDBC_USER_PASSWORD);
|
||||
properties.put(POSTGRESQL_SERVER_MAX_RESULT, DEFAULT_MAX_RESULT);
|
||||
|
||||
psqlInterpreter = spy(new PostgreSqlInterpreter(properties));
|
||||
when(psqlInterpreter.getJdbcConnection()).thenReturn(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenCommandIndempotency() throws SQLException {
|
||||
// Ensure that an attempt to open new connection will clean any remaining connections
|
||||
psqlInterpreter.open();
|
||||
psqlInterpreter.open();
|
||||
psqlInterpreter.open();
|
||||
|
||||
verify(psqlInterpreter, times(3)).open();
|
||||
verify(psqlInterpreter, times(3)).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultProperties() throws SQLException {
|
||||
|
|
|
|||
|
|
@ -395,7 +395,11 @@ public class ZeppelinConfiguration extends XMLConfiguration {
|
|||
+ "org.apache.zeppelin.ignite.IgniteSqlInterpreter,"
|
||||
+ "org.apache.zeppelin.lens.LensInterpreter,"
|
||||
+ "org.apache.zeppelin.cassandra.CassandraInterpreter,"
|
||||
<<<<<<< HEAD
|
||||
+ "org.apache.zeppelin.geode.GeodeOqlInterpreter"),
|
||||
=======
|
||||
+ "org.apache.zeppelin.postgresql.PostgreSqlInterpreter"),
|
||||
>>>>>>> ZEPPELIN-70: Closed previous connection before open new one. Register psql in ZeppelinConfiguration
|
||||
ZEPPELIN_INTERPRETER_DIR("zeppelin.interpreter.dir", "interpreter"),
|
||||
ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT("zeppelin.interpreter.connect.timeout", 30000),
|
||||
ZEPPELIN_ENCODING("zeppelin.encoding", "UTF-8"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue