SimpleTriangleClosingComputation extends BasicComputation<
  IntWritable, SimpleTriangleClosingComputation.IntArrayListWritable,
  NullWritable, IntWritable> { @Override public void compute( Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex, Iterable<IntWritable> messages) throws IOException { if (getSuperstep() == 0) { for (Edge<IntWritable, NullWritable> edge : vertex.getEdges()) { sendMessageToAllEdges(vertex, edge.getTargetVertexId()); } } else { for (IntWritable message : messages) { final int current = (closeMap.get(message) == null) ? 0 : closeMap.get(message) + 1; closeMap.put(message, current); } Set<Pair> sortedResults = Sets.<Pair>newTreeSet(); for (Map.Entry<IntWritable, Integer> entry : closeMap.entrySet()) { sortedResults.add(new Pair(entry.getKey(), entry.getValue())); } IntArrayListWritable outputList = new IntArrayListWritable(); for (Pair pair : sortedResults) { if (pair.value > 0) { outputList.add(pair.key); } else { break; } } vertex.setValue(outputList); } vertex.voteToHalt(); }  @Override void compute(
      Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex,
      Iterable<IntWritable> messages);  }
@Test public void testSuperstepZero() throws Exception { Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex = new DefaultVertex<IntWritable, IntArrayListWritable, NullWritable>(); IntArrayListWritable alw = new IntArrayListWritable(); SimpleTriangleClosingComputation computation = new SimpleTriangleClosingComputation(); MockUtils.MockedEnvironment env = MockUtils.prepareVertexAndComputation( vertex, new IntWritable(1), alw, false, computation, 0L); vertex.addEdge(EdgeFactory.create(new IntWritable(5))); vertex.addEdge(EdgeFactory.create(new IntWritable(7))); computation.compute(vertex, Lists.<IntWritable>newArrayList( new IntWritable(83), new IntWritable(42))); env.verifyMessageSentToAllEdges(vertex, new IntWritable(5)); env.verifyMessageSentToAllEdges(vertex, new IntWritable(7)); }
@Test public void testSuperstepOne() throws Exception { Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex = new DefaultVertex<IntWritable, IntArrayListWritable, NullWritable>(); SimpleTriangleClosingComputation computation = new SimpleTriangleClosingComputation(); MockUtils.MockedEnvironment env = MockUtils.prepareVertexAndComputation( vertex, new IntWritable(1), null, false, computation, 1L); computation.compute(vertex, Lists.<IntWritable>newArrayList( new IntWritable(7), new IntWritable(3), new IntWritable(4), new IntWritable(7), new IntWritable(4), new IntWritable(2), new IntWritable(4))); final String pairCheck = "[4, 7]"; assertEquals(pairCheck, vertex.getValue().toString()); }