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

Method testMapReduceOnly

test/org/apache/pig/test/TestCounters.java:166–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

164 }
165
166 @Test
167 public void testMapReduceOnly() throws IOException, ExecException {
168 int count = 0;
169 PrintWriter pw = new PrintWriter(Util.createInputFile(cluster, file));
170 int [] nos = new int[10];
171 for(int i = 0; i < 10; i++)
172 nos[i] = 0;
173
174 for(int i = 0; i < MAX; i++) {
175 int index = r.nextInt(10);
176 int value = r.nextInt(100);
177 nos[index] += value;
178 pw.println(index + "\t" + value);
179 }
180 pw.close();
181
182 for(int i = 0; i < 10; i++) {
183 if(nos[i] > 0) count ++;
184 }
185
186 PigServer pigServer = new PigServer(cluster.getExecType(), cluster.getProperties());
187 pigServer.registerQuery("a = load '" + file + "';");
188 pigServer.registerQuery("b = group a by $0;");
189 pigServer.registerQuery("c = foreach b generate group;");
190
191 ExecJob job = pigServer.store("c", "output");
192 PigStats pigStats = job.getStatistics();
193 InputStream is = FileLocalizer.open(FileLocalizer.fullPath("output",
194 pigServer.getPigContext()), pigServer.getPigContext());
195
196 long filesize = 0;
197 while(is.read() != -1) filesize++;
198
199 is.close();
200
201 cluster.getFileSystem().delete(new Path(file), true);
202 cluster.getFileSystem().delete(new Path("output"), true);
203
204 System.out.println("============================================");
205 System.out.println("Test case MapReduce");
206 System.out.println("============================================");
207
208 JobGraph jp = pigStats.getJobGraph();
209 Iterator<JobStats> iter = jp.iterator();
210 while (iter.hasNext()) {
211 JobStats js = iter.next();
212 System.out.println("Map input records : " + js.getMapInputRecords());
213 assertEquals(MAX, js.getMapInputRecords());
214 System.out.println("Map output records : " + js.getMapOutputRecords());
215 assertEquals(MAX, js.getMapOutputRecords());
216 System.out.println("Reduce input records : " + js.getReduceInputRecords());
217 assertEquals(MAX, js.getReduceInputRecords());
218 System.out.println("Reduce output records : " + js.getReduceOutputRecords());
219 assertEquals(count, js.getReduceOutputRecords());
220 }
221 System.out.println("Hdfs bytes written : " + pigStats.getBytesWritten());
222 assertEquals(filesize, pigStats.getBytesWritten());
223 }

Callers

nothing calls this directly

Calls 15

createInputFileMethod · 0.95
registerQueryMethod · 0.95
storeMethod · 0.95
getStatisticsMethod · 0.95
openMethod · 0.95
fullPathMethod · 0.95
getPigContextMethod · 0.95
getJobGraphMethod · 0.95
iteratorMethod · 0.95
getMapInputRecordsMethod · 0.95
getMapOutputRecordsMethod · 0.95
getReduceInputRecordsMethod · 0.95

Tested by

no test coverage detected