Esempio n. 1
0
  @Override
  public Result getResult() {
    JobExecutionResult res = env.getLastJobExecutionResult();

    long vertexCount = res.getAccumulatorResult(id + "-0");
    long edgeCount = res.getAccumulatorResult(id + "-1");
    long tripletCount = res.getAccumulatorResult(id + "-2");

    return new Result(vertexCount, edgeCount / 2, tripletCount);
  }
  @Test
  public void testSerialization() {
    try {
      final ClassLoader classloader = getClass().getClassLoader();

      JobID origJobId = new JobID();
      long origTime = 65927436589267L;

      Map<String, SerializedValue<Object>> origMap = new HashMap<String, SerializedValue<Object>>();
      origMap.put("name1", new SerializedValue<Object>(723L));
      origMap.put("name2", new SerializedValue<Object>("peter"));

      SerializedJobExecutionResult result =
          new SerializedJobExecutionResult(origJobId, origTime, origMap);

      // serialize and deserialize the object
      SerializedJobExecutionResult cloned = CommonTestUtils.createCopySerializable(result);

      assertEquals(origJobId, cloned.getJobId());
      assertEquals(origTime, cloned.getNetRuntime());
      assertEquals(origTime, cloned.getNetRuntime(TimeUnit.MILLISECONDS));
      assertEquals(origMap, cloned.getSerializedAccumulatorResults());

      // convert to deserialized result
      JobExecutionResult jResult = result.toJobExecutionResult(classloader);
      JobExecutionResult jResultCopied = result.toJobExecutionResult(classloader);

      assertEquals(origJobId, jResult.getJobID());
      assertEquals(origJobId, jResultCopied.getJobID());
      assertEquals(origTime, jResult.getNetRuntime());
      assertEquals(origTime, jResult.getNetRuntime(TimeUnit.MILLISECONDS));
      assertEquals(origTime, jResultCopied.getNetRuntime());
      assertEquals(origTime, jResultCopied.getNetRuntime(TimeUnit.MILLISECONDS));

      for (Map.Entry<String, SerializedValue<Object>> entry : origMap.entrySet()) {
        String name = entry.getKey();
        Object value = entry.getValue().deserializeValue(classloader);
        assertEquals(value, jResult.getAccumulatorResult(name));
        assertEquals(value, jResultCopied.getAccumulatorResult(name));
      }
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }