Example #1
0
 public void run() {
   // TODO Auto-generated method stub
   run = true;
   System.out.println("Running a map");
   while (run) {
     // Figure out how to read input file
     // Evaluate it
     Map<String, List<String>> input = reader.getKeyValuePairs();
     if (input == null) {
       map.setStatus(-1);
       Message msg = new Message();
       msg.setTask(map);
       msg.setType('f');
       coord.conn.sendMessage(msg);
       return;
     }
     OutputCollector<String, String> collect = new OutputCollector<String, String>();
     Set<String> keySet = input.keySet();
     for (String key : keySet) {
       List<String> values = input.get(key);
       for (String value : values) {
         map.getJob().map(key, value, collect);
       }
     }
     List<Pair> results = collect.getResults();
     int length = results.size();
     FileOutputStream out;
     try {
       System.out.println("Trying to Write to File");
       out = new FileOutputStream(new File(map.getOutput().get(0)));
       BufferedWriter dw = new BufferedWriter(new OutputStreamWriter(out));
       for (Pair p : results) {
         dw.append(p.toString());
         dw.newLine();
       }
       dw.newLine();
       dw.flush();
       dw.close();
       out.close();
       coord.dataNode.addFileToDFS(map.getOutput().get(0), coord.conn.port, false);
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       map.setStatus(-1);
       Message msg = new Message();
       msg.setTask(map);
       msg.setType('f');
       coord.conn.sendMessage(msg);
       return;
     }
     map.setStatus(1);
     Message msg = new Message();
     msg.setTask(map);
     msg.setType('f');
     coord.conn.sendMessage(msg);
     break;
   }
 }
Example #2
0
 /**
  * Test whether the pair returns the correct string relating to the values of its first and second
  * values.
  */
 @Test
 public void testString() {
   Pair<Double> testPair = new Pair<Double>(testFirst, testSecond);
   assertEquals(testString, testPair.toString());
 }