MCPcopy Create free account
hub / github.com/apache/pig / testImportList

Method testImportList

test/org/apache/pig/test/TestPigContext.java:126–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124 }
125
126 @Test
127 // See PIG-832
128 public void testImportList() throws Exception {
129
130 String FILE_SEPARATOR = System.getProperty("file.separator");
131 File tmpDir = File.createTempFile("test", "");
132 tmpDir.delete();
133 tmpDir.mkdir();
134
135 File udf1Dir = new File(tmpDir.getAbsolutePath() + FILE_SEPARATOR + "com" + FILE_SEPARATOR
136 + "xxx" + FILE_SEPARATOR + "udf1");
137 udf1Dir.mkdirs();
138 File udf2Dir = new File(tmpDir.getAbsolutePath() + FILE_SEPARATOR + "com" + FILE_SEPARATOR
139 + "xxx" + FILE_SEPARATOR + "udf2");
140 udf2Dir.mkdirs();
141
142 String udf1Src = new String("package com.xxx.udf1;\n" +
143 "import java.io.IOException;\n" +
144 "import org.apache.pig.EvalFunc;\n" +
145 "import org.apache.pig.data.Tuple;\n" +
146 "public class TestUDF1 extends EvalFunc<Integer>{\n" +
147 "public Integer exec(Tuple input) throws IOException {\n" +
148 "return 1;}\n" +
149 "}");
150
151 String udf2Src = new String("package com.xxx.udf2;\n" +
152 "import org.apache.pig.builtin.PigStorage;\n" +
153 "public class TestUDF2 extends PigStorage { }\n");
154
155 // compile
156 JavaCompilerHelper javaCompilerHelper = new JavaCompilerHelper();
157 javaCompilerHelper.compile(tmpDir.getAbsolutePath(),
158 new JavaCompilerHelper.JavaSourceFromString("com.xxx.udf1.TestUDF1", udf1Src),
159 new JavaCompilerHelper.JavaSourceFromString("com.xxx.udf2.TestUDF2", udf2Src));
160
161 // generate jar file
162 String jarName = "TestUDFJar.jar";
163 String jarFile = tmpDir.getAbsolutePath() + FILE_SEPARATOR + jarName;
164 int status = Util.executeJavaCommand("jar -cf " + jarFile +
165 " -C " + tmpDir.getAbsolutePath() + " " + "com");
166 assertEquals(0, status);
167 Util.resetStateForExecModeSwitch();
168 PigContext localPigContext = new PigContext(cluster.getExecType(), properties);
169
170 // register jar using properties
171 localPigContext.getProperties().setProperty("pig.additional.jars", jarFile);
172 PigServer pigServer = new PigServer(localPigContext);
173
174 PigContext.initializeImportList("com.xxx.udf1:com.xxx.udf2.");
175 ArrayList<String> importList = PigContext.getPackageImportList();
176 assertEquals(6, importList.size());
177 assertEquals("", importList.get(0));
178 assertEquals("com.xxx.udf1.", importList.get(1));
179 assertEquals("com.xxx.udf2.", importList.get(2));
180 assertEquals("java.lang.", importList.get(3));
181 assertEquals("org.apache.pig.builtin.", importList.get(4));
182 assertEquals("org.apache.pig.impl.builtin.", importList.get(5));
183

Callers

nothing calls this directly

Calls 15

compileMethod · 0.95
executeJavaCommandMethod · 0.95
getPropertiesMethod · 0.95
initializeImportListMethod · 0.95
getPackageImportListMethod · 0.95
getMethod · 0.95
removeColonMethod · 0.95
createInputFileMethod · 0.95
deleteTempFilesMethod · 0.95
registerQueryMethod · 0.95

Tested by

no test coverage detected