Skip to content

Commit 4a278f0

Browse files
committed
Add test checking InterpreterProperty class
1 parent 14a6300 commit 4a278f0

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterFactory.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.google.common.collect.Maps;
5454
import com.google.gson.Gson;
5555
import com.google.gson.GsonBuilder;
56+
import com.google.gson.internal.StringMap;
5657
import com.google.gson.reflect.TypeToken;
5758
import org.apache.commons.io.FileUtils;
5859
import org.apache.commons.lang.ArrayUtils;
@@ -286,7 +287,7 @@ private InterpreterSetting createFromInterpreterSettingRef(String name) {
286287
private InterpreterSetting createFromInterpreterSettingRef(InterpreterSetting o) {
287288
InterpreterSetting setting =
288289
new InterpreterSetting(o.getName(), o.getName(), o.getInterpreterInfos(),
289-
convertInterpreterProperties((Map <String, InterpreterProperty>) o.getProperties()),
290+
convertInterpreterProperties((Map<String, InterpreterProperty>) o.getProperties()),
290291
o.getDependencies(), o.getOption(), o.getPath());
291292
setting.setInterpreterGroupFactory(this);
292293
return setting;
@@ -382,6 +383,14 @@ private void loadFromFile() throws IOException {
382383
InterpreterSetting setting = infoSaving.interpreterSettings.get(k);
383384
List<InterpreterInfo> infos = setting.getInterpreterInfos();
384385

386+
// Convert json StringMap to Properties
387+
StringMap<String> p = (StringMap<String>) setting.getProperties();
388+
Properties properties = new Properties();
389+
for (String key : p.keySet()) {
390+
properties.put(key, p.get(key));
391+
}
392+
setting.setProperties(properties);
393+
385394
// Always use separate interpreter process
386395
// While we decided to turn this feature on always (without providing
387396
// enable/disable option on GUI).

zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.apache.zeppelin.interpreter;
1919

2020
import java.io.*;
21+
import java.nio.file.Files;
22+
import java.nio.file.Paths;
2123
import java.util.ArrayList;
2224
import java.util.Collections;
2325
import java.util.LinkedList;
@@ -26,6 +28,7 @@
2628
import java.util.HashMap;
2729
import java.util.Properties;
2830

31+
import com.google.gson.Gson;
2932
import org.apache.commons.io.FileUtils;
3033
import org.apache.commons.lang.NullArgumentException;
3134
import org.apache.zeppelin.conf.ZeppelinConfiguration;
@@ -34,7 +37,6 @@
3437
import org.apache.zeppelin.dep.DependencyResolver;
3538
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
3639
import org.apache.zeppelin.interpreter.mock.MockInterpreter2;
37-
import org.apache.zeppelin.notebook.repo.zeppelinhub.security.Authentication;
3840
import org.apache.zeppelin.user.AuthenticationInfo;
3941
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
4042
import org.apache.zeppelin.notebook.JobListenerFactory;
@@ -193,12 +195,43 @@ public void testSaveLoad() throws IOException, RepositoryException {
193195
assertEquals(numInterpreters + 1, factory2.get().size());
194196
}
195197

198+
@Test
199+
public void testInterpreterSettingPropertyClass() throws IOException, RepositoryException {
200+
// check if default interpreter reference's property type is map
201+
Map<String, InterpreterSetting> interpreterSettingRefs = factory.getAvailableInterpreterSettings();
202+
InterpreterSetting intpSetting = interpreterSettingRefs.get("mock1");
203+
Map<String, InterpreterProperty> intpProperties =
204+
(Map<String, InterpreterProperty>) intpSetting.getProperties();
205+
assertTrue(intpProperties instanceof Map);
206+
207+
// check if interpreter instance is saved as Properties in conf/interpreter.json file
208+
Properties properties = new Properties();
209+
properties.put("key1", "value1");
210+
properties.put("key2", "value2");
211+
212+
factory.createNewSetting("newMock", "mock1", new LinkedList<Dependency>(), new InterpreterOption(false), properties);
213+
214+
String confFilePath = conf.getInterpreterSettingPath();
215+
byte[] encoded = Files.readAllBytes(Paths.get(confFilePath));
216+
String json = new String(encoded, "UTF-8");
217+
218+
Gson gson = new Gson();
219+
InterpreterInfoSaving infoSaving = gson.fromJson(json, InterpreterInfoSaving.class);
220+
Map<String, InterpreterSetting> interpreterSettings = infoSaving.interpreterSettings;
221+
for (String key : interpreterSettings.keySet()) {
222+
InterpreterSetting setting = interpreterSettings.get(key);
223+
if (setting.getName().equals("newMock")) {
224+
assertEquals(setting.getProperties().toString(), properties.toString());
225+
}
226+
}
227+
}
228+
196229
@Test
197230
public void testInterpreterAliases() throws IOException, RepositoryException {
198231
factory = new InterpreterFactory(conf, null, null, null, depResolver, false);
199232
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null);
200233
final InterpreterInfo info2 = new InterpreterInfo("className2", "name1", true, null);
201-
factory.add("group1", new ArrayList<InterpreterInfo>(){{
234+
factory.add("group1", new ArrayList<InterpreterInfo>() {{
202235
add(info1);
203236
}}, new ArrayList<Dependency>(), new InterpreterOption(true), Collections.EMPTY_MAP, "/path1");
204237
factory.add("group2", new ArrayList<InterpreterInfo>(){{

0 commit comments

Comments
 (0)