ZEPPELIN-440 HiveInterpreter with multiple configuration

- Fixed some tests
This commit is contained in:
Jongyoul Lee 2015-11-24 13:28:53 +09:00
parent 85e4914855
commit 8aa7601b90
4 changed files with 52 additions and 29 deletions

View file

@ -87,6 +87,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View file

@ -284,8 +284,8 @@ public class HiveInterpreter extends Interpreter {
@Override
public Scheduler getScheduler() {
return SchedulerFactory.singleton().createOrGetParallelScheduler(
HiveInterpreter.class.getName() + this.hashCode(), 10);
return SchedulerFactory.singleton().createOrGetFIFOScheduler(
HiveInterpreter.class.getName() + this.hashCode());
}
@Override

View file

@ -17,32 +17,53 @@
*/
package org.apache.zeppelin.hive;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.*;
import java.sql.Date;
import java.util.*;
import java.util.concurrent.Executor;
import org.apache.zeppelin.display.AngularObjectRegistry;
import org.apache.zeppelin.display.GUI;
import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterContextRunner;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import static java.lang.String.format;
/**
* Hive interpreter unit tests
*/
public class HiveInterpreterTest {
@Before
public void setUp() throws Exception {
static String jdbcConnection;
private static String getJdbcConnection() throws IOException {
if(null == jdbcConnection) {
Path tmpDir = Files.createTempDirectory("h2-test-");
tmpDir.toFile().deleteOnExit();
jdbcConnection = format("jdbc:h2:%s", tmpDir);
}
return jdbcConnection;
}
@BeforeClass
public static void setUp() throws Exception {
Class.forName("org.h2.Driver");
Connection connection = DriverManager.getConnection(getJdbcConnection());
Statement statement = connection.createStatement();
statement.execute(
"DROP TABLE IF EXISTS test_table; " +
"CREATE TABLE test_table(id varchar(255), name varchar(255));");
statement.execute(
"insert into test_table(id, name) values ('a', 'a_name'),('b', 'b_name');"
);
}
@After
@ -50,16 +71,23 @@ public class HiveInterpreterTest {
}
@Test
public void test() {
HiveInterpreter t = new MockHiveInterpreter(new Properties());
public void test() throws IOException {
Properties properties = new Properties();
properties.setProperty("default.driver", "org.h2.Driver");
properties.setProperty("default.url", getJdbcConnection());
properties.setProperty("default.user", "");
properties.setProperty("default.password", "");
HiveInterpreter t = new HiveInterpreter(properties);
t.open();
InterpreterContext interpreterContext = new InterpreterContext(null, "a", null, null, null, null, null, null);
//simple select test
InterpreterResult result = t.interpret("select * from t", null);
InterpreterResult result = t.interpret("select * from test_table", interpreterContext);
assertEquals(result.type(), InterpreterResult.Type.TABLE);
//explain test
result = t.interpret("explain select * from t", null);
result = t.interpret("explain select * from test_table", interpreterContext);
assertEquals(result.type(), InterpreterResult.Type.TEXT);
t.close();
}
@ -71,9 +99,11 @@ public class HiveInterpreterTest {
properties.setProperty("default.url", "defaultUri");
properties.setProperty("default.user", "defaultUser");
HiveInterpreter hi = new HiveInterpreter(properties);
hi.open();
assertNotNull("propertiesMap is not null", hi.getPropertiesMap());
assertNotNull("propertiesMap.get(default) is not null", hi.getPropertiesMap().get("default"));
assertTrue("default exists", "defaultDriver".equals(hi.getPropertiesMap().get("default").getProperty("driver")));
hi.close();
}
@Test
@ -84,8 +114,10 @@ public class HiveInterpreterTest {
properties.setProperty("default.user", "defaultUser");
properties.setProperty("presto.driver", "com.facebook.presto.jdbc.PrestoDriver");
HiveInterpreter hi = new HiveInterpreter(properties);
hi.open();
assertTrue("default exists", hi.getPropertiesMap().containsKey("default"));
assertFalse("presto doesn't exists", hi.getPropertiesMap().containsKey("presto"));
hi.close();
}
@Test
@ -95,22 +127,7 @@ public class HiveInterpreterTest {
assertEquals("get key of default", "default", hi.getPropertyKey(testCommand));
testCommand = "(default) show tables";
assertEquals("get key of default", "default", hi.getPropertyKey(testCommand));
}
@Test
public void prestoTest() {
InterpreterContext interpreterContext = new InterpreterContext("", "a", "", "", new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry("", null), new ArrayList<InterpreterContextRunner>());
Properties properties = new Properties();
properties.setProperty("default.driver", "defaultDriver");
properties.setProperty("default.url", "defaultUri");
properties.setProperty("default.user", "defaultUser");
properties.setProperty("presto.driver", "com.facebook.presto.jdbc.PrestoDriver");
properties.setProperty("presto.url", "jdbc:presto://10.10.36.191:8080/hive");
HiveInterpreter hi = new HiveInterpreter(properties);
hi.open();
InterpreterResult interpreterResult = hi.interpret("(presto)\nshow catalogs", interpreterContext);
System.out.println(interpreterResult.message());
hi.close();
}
}

View file

@ -114,7 +114,7 @@ public class NotebookTest implements JobListenerFactory{
p2.setText("%mock2 hello world");
note.run(p2.getId());
while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield();
assertEquals("repl2: hello world", p2.getResult().message());
assertEquals("repl2: hello world", p2.getResult().message());
}
@Test