|
18 | 18 | package org.apache.zeppelin.interpreter; |
19 | 19 |
|
20 | 20 | import java.io.*; |
| 21 | +import java.nio.file.Files; |
| 22 | +import java.nio.file.Paths; |
21 | 23 | import java.util.ArrayList; |
22 | 24 | import java.util.Collections; |
23 | 25 | import java.util.LinkedList; |
|
26 | 28 | import java.util.HashMap; |
27 | 29 | import java.util.Properties; |
28 | 30 |
|
| 31 | +import com.google.gson.Gson; |
29 | 32 | import org.apache.commons.io.FileUtils; |
30 | 33 | import org.apache.commons.lang.NullArgumentException; |
31 | 34 | import org.apache.zeppelin.conf.ZeppelinConfiguration; |
|
34 | 37 | import org.apache.zeppelin.dep.DependencyResolver; |
35 | 38 | import org.apache.zeppelin.interpreter.mock.MockInterpreter1; |
36 | 39 | import org.apache.zeppelin.interpreter.mock.MockInterpreter2; |
37 | | -import org.apache.zeppelin.notebook.repo.zeppelinhub.security.Authentication; |
38 | 40 | import org.apache.zeppelin.user.AuthenticationInfo; |
39 | 41 | import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; |
40 | 42 | import org.apache.zeppelin.notebook.JobListenerFactory; |
@@ -193,12 +195,43 @@ public void testSaveLoad() throws IOException, RepositoryException { |
193 | 195 | assertEquals(numInterpreters + 1, factory2.get().size()); |
194 | 196 | } |
195 | 197 |
|
| 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 | + |
196 | 229 | @Test |
197 | 230 | public void testInterpreterAliases() throws IOException, RepositoryException { |
198 | 231 | factory = new InterpreterFactory(conf, null, null, null, depResolver, false); |
199 | 232 | final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null); |
200 | 233 | final InterpreterInfo info2 = new InterpreterInfo("className2", "name1", true, null); |
201 | | - factory.add("group1", new ArrayList<InterpreterInfo>(){{ |
| 234 | + factory.add("group1", new ArrayList<InterpreterInfo>() {{ |
202 | 235 | add(info1); |
203 | 236 | }}, new ArrayList<Dependency>(), new InterpreterOption(true), Collections.EMPTY_MAP, "/path1"); |
204 | 237 | factory.add("group2", new ArrayList<InterpreterInfo>(){{ |
|
0 commit comments