Example #1
0
  @Test(dependsOnMethods = {"testSetAndGet"})
  public void testSerDe() throws IOException {
    Closer closer = Closer.create();
    try {
      ByteArrayOutputStream baos = closer.register(new ByteArrayOutputStream());
      DataOutputStream dos = closer.register(new DataOutputStream(baos));
      this.taskState.write(dos);

      ByteArrayInputStream bais = closer.register((new ByteArrayInputStream(baos.toByteArray())));
      DataInputStream dis = closer.register((new DataInputStream(bais)));
      TaskState newTaskState = new TaskState();
      newTaskState.readFields(dis);

      Assert.assertEquals(newTaskState.getJobId(), "Job-1");
      Assert.assertEquals(newTaskState.getTaskId(), "Task-1");
      Assert.assertEquals(this.taskState.getHighWaterMark(), 2000);
      Assert.assertEquals(newTaskState.getStartTime(), this.startTime);
      Assert.assertEquals(newTaskState.getEndTime(), this.startTime + 1000);
      Assert.assertEquals(newTaskState.getTaskDuration(), 1000);
      Assert.assertEquals(newTaskState.getWorkingState(), WorkUnitState.WorkingState.COMMITTED);
      Assert.assertEquals(newTaskState.getProp("foo"), "bar");
    } catch (Throwable t) {
      throw closer.rethrow(t);
    } finally {
      closer.close();
    }
  }
  @Test(dependsOnMethods = "testPersistJobState")
  public void testGetJobState() throws IOException {
    JobState jobState =
        this.fsDatasetStateStore.get(
            TEST_JOB_NAME,
            FsDatasetStateStore.CURRENT_DATASET_STATE_FILE_SUFFIX
                + FsDatasetStateStore.DATASET_STATE_STORE_TABLE_SUFFIX,
            TEST_JOB_ID);

    Assert.assertEquals(jobState.getJobName(), TEST_JOB_NAME);
    Assert.assertEquals(jobState.getJobId(), TEST_JOB_ID);
    Assert.assertEquals(jobState.getState(), JobState.RunningState.COMMITTED);
    Assert.assertEquals(jobState.getProp("foo"), "bar");
    Assert.assertEquals(jobState.getStartTime(), this.startTime);
    Assert.assertEquals(jobState.getEndTime(), this.startTime + 1000);
    Assert.assertEquals(jobState.getDuration(), 1000);

    Assert.assertEquals(jobState.getCompletedTasks(), 3);
    for (int i = 0; i < jobState.getCompletedTasks(); i++) {
      TaskState taskState = jobState.getTaskStates().get(i);
      Assert.assertEquals(taskState.getJobId(), TEST_JOB_ID);
      Assert.assertEquals(taskState.getTaskId(), TEST_TASK_ID_PREFIX + i);
      Assert.assertEquals(taskState.getId(), TEST_TASK_ID_PREFIX + i);
      Assert.assertEquals(taskState.getWorkingState(), WorkUnitState.WorkingState.COMMITTED);
    }
  }