Fix tests

This commit is contained in:
Lee moon soo 2016-04-13 00:46:45 +02:00
parent 5503f9c100
commit b47ca744b9
6 changed files with 25 additions and 14 deletions

View file

@ -138,13 +138,12 @@ public class DistributedResourcePoolTest {
InterpreterResult ret;
intp1.interpret("put key1 value1", context);
intp2.interpret("put key2 value2", context);
int numInterpreterResult = 2;
ret = intp1.interpret("getAll", context);
assertEquals(numInterpreterResult + 2, gson.fromJson(ret.message(), ResourceSet.class).size());
assertEquals(2, gson.fromJson(ret.message(), ResourceSet.class).size());
ret = intp2.interpret("getAll", context);
assertEquals(numInterpreterResult + 2, gson.fromJson(ret.message(), ResourceSet.class).size());
assertEquals(2, gson.fromJson(ret.message(), ResourceSet.class).size());
ret = intp1.interpret("get key1", context);
assertEquals("value1", gson.fromJson(ret.message(), String.class));
@ -216,16 +215,15 @@ public class DistributedResourcePoolTest {
intp2.interpret("put note2:paragraph1:key1 value1", context);
intp2.interpret("put note2:paragraph2:key2 value2", context);
int numInterpreterResult = 2;
// then get all resources.
assertEquals(numInterpreterResult + 4, ResourcePoolUtils.getAllResources().size());
assertEquals(4, ResourcePoolUtils.getAllResources().size());
// when remove all resources from note1
ResourcePoolUtils.removeResourcesBelongsToNote("note1");
// then resources should be removed.
assertEquals(numInterpreterResult + 2, ResourcePoolUtils.getAllResources().size());
assertEquals(2, ResourcePoolUtils.getAllResources().size());
assertEquals("", gson.fromJson(
intp1.interpret("get note1:paragraph1:key1", context).message(),
String.class));
@ -238,7 +236,7 @@ public class DistributedResourcePoolTest {
ResourcePoolUtils.removeResourcesBelongsToParagraph("note2", "paragraph1");
// then 1
assertEquals(numInterpreterResult + 1, ResourcePoolUtils.getAllResources().size());
assertEquals(1, ResourcePoolUtils.getAllResources().size());
assertEquals("value2", gson.fromJson(
intp1.interpret("get note2:paragraph2:key2", context).message(),
String.class));

View file

@ -86,7 +86,7 @@ public class ZeppelinServer extends Application {
this.depResolver = new DependencyResolver(
conf.getString(ConfVars.ZEPPELIN_INTERPRETER_LOCALREPO));
this.helium = new Helium(conf.getHeliumConfPath());
this.helium = new Helium(conf.getHeliumConfPath(), conf.getHeliumDefaultLocalRegistryPath());
this.heliumApplicationFactory = new HeliumApplicationFactory();
this.schedulerFactory = new SchedulerFactory();
this.replFactory = new InterpreterFactory(conf, notebookWsServer,

View file

@ -346,6 +346,10 @@ public class ZeppelinConfiguration extends XMLConfiguration {
return getRelativeDir(String.format("%s/helium.json", getConfDir()));
}
public String getHeliumDefaultLocalRegistryPath() {
return getRelativeDir(ConfVars.ZEPPELIN_HELIUM_LOCALREGISTRY_DEFAULT);
}
public String getNotebookAuthorizationPath() {
return getRelativeDir(String.format("%s/notebook-authorization.json", getConfDir()));
}
@ -490,6 +494,7 @@ public class ZeppelinConfiguration extends XMLConfiguration {
ZEPPELIN_NOTEBOOK_AUTO_INTERPRETER_BINDING("zeppelin.notebook.autoInterpreterBinding", true),
ZEPPELIN_CONF_DIR("zeppelin.conf.dir", "conf"),
ZEPPELIN_DEP_LOCALREPO("zeppelin.dep.localrepo", "local-repo"),
ZEPPELIN_HELIUM_LOCALREGISTRY_DEFAULT("zeppelin.helium.localregistry.default", "helium"),
// Allows a way to specify a ',' separated list of allowed origins for rest and websockets
// i.e. http://localhost:8080
ZEPPELIN_ALLOWED_ORIGINS("zeppelin.server.allowed.origins", "*"),

View file

@ -46,10 +46,12 @@ public class Helium {
private final HeliumConf heliumConf;
private final String heliumConfPath;
private final String defaultLocalRegistryPath;
private final Gson gson;
public Helium(String heliumConfPath) throws IOException {
public Helium(String heliumConfPath, String defaultLocalRegistryPath) throws IOException {
this.heliumConfPath = heliumConfPath;
this.defaultLocalRegistryPath = defaultLocalRegistryPath;
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
@ -87,7 +89,7 @@ public class Helium {
logger.warn("{} does not exists", path);
HeliumConf conf = new HeliumConf();
LinkedList<HeliumRegistry> defaultRegistry = new LinkedList<HeliumRegistry>();
defaultRegistry.add(new HeliumLocalRegistry("local", "../helium"));
defaultRegistry.add(new HeliumLocalRegistry("local", defaultLocalRegistryPath));
conf.setRegistry(defaultRegistry);
this.registry = conf.getRegistry();
return conf;

View file

@ -547,7 +547,10 @@ public class Note implements Serializable, ParagraphJobListener {
ParagraphJobListener listener = jobListenerFactory.getParagraphJobListener(this);
listener.afterStatusChange(job, before, after);
}
noteEventListener.onParagraphStatusChange((Paragraph) job, after);
if (noteEventListener != null) {
noteEventListener.onParagraphStatusChange((Paragraph) job, after);
}
}
@Override

View file

@ -32,11 +32,14 @@ import static org.junit.Assert.assertTrue;
public class HeliumTest {
private File tmpDir;
private File localRegistryPath;
@Before
public void setUp() throws Exception {
tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
tmpDir.mkdirs();
localRegistryPath = new File(tmpDir, "helium");
localRegistryPath.mkdirs();
}
@After
@ -48,7 +51,7 @@ public class HeliumTest {
public void testSaveLoadConf() throws IOException, URISyntaxException {
// given
File heliumConf = new File(tmpDir, "helium.conf");
Helium helium = new Helium(heliumConf.getAbsolutePath());
Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath());
assertFalse(heliumConf.exists());
HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
helium.addRegistry(registry1);
@ -62,14 +65,14 @@ public class HeliumTest {
assertTrue(heliumConf.exists());
// then
Helium heliumRestored = new Helium(heliumConf.getAbsolutePath());
Helium heliumRestored = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath());
assertEquals(2, heliumRestored.getAllRegistry().size());
}
@Test
public void testRestoreRegistryInstances() throws IOException, URISyntaxException {
File heliumConf = new File(tmpDir, "helium.conf");
Helium helium = new Helium(heliumConf.getAbsolutePath());
Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath());
HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
HeliumTestRegistry registry2 = new HeliumTestRegistry("r2", "r2");
helium.addRegistry(registry1);