use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.
the class ClusterEventMetadataGeneratorTest method testErrorMessage.
@Test
public void testErrorMessage() throws Exception {
JobContext jobContext = Mockito.mock(JobContext.class);
JobState jobState = new JobState("jobName", "1234");
TaskState taskState1 = new TaskState();
TaskState taskState2 = new TaskState();
taskState1.setTaskId("1");
taskState1.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, "exception1");
taskState2.setTaskId("2");
taskState2.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, "exception2");
taskState2.setProp(EventMetadataUtils.TASK_FAILURE_MESSAGE_KEY, "failureMessage2");
jobState.addTaskState(taskState1);
jobState.addTaskState(taskState2);
Mockito.when(jobContext.getJobState()).thenReturn(jobState);
ClusterEventMetadataGenerator metadataGenerator = new ClusterEventMetadataGenerator();
Map<String, String> metadata;
// error message is not in job commit event
metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_COMMIT);
Assert.assertEquals(metadata.get("message"), null);
// error message is in job failed event
metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_FAILED);
Assert.assertTrue(metadata.get("message").startsWith("failureMessage"));
Assert.assertTrue(metadata.get("message").contains("exception1"));
Assert.assertTrue(metadata.get("message").contains("exception2"));
}
use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.
the class TaskMetricsTest method testTaskGetMetrics.
@Test
public void testTaskGetMetrics() {
String jobId = "job_456";
String taskId = "task_456";
String jobName = "jobName";
JobState jobState = new JobState(jobName, jobId);
JobMetrics jobMetrics = JobMetrics.get(jobState);
State props = new State();
props.setProp(ConfigurationKeys.JOB_ID_KEY, jobId);
props.setProp(ConfigurationKeys.TASK_ID_KEY, taskId);
SourceState sourceState = new SourceState(props, new ArrayList<WorkUnitState>());
WorkUnit workUnit = new WorkUnit(sourceState, null);
WorkUnitState workUnitState = new WorkUnitState(workUnit);
TaskState taskState = new TaskState(workUnitState);
TaskMetrics taskMetrics = new TaskMetrics(taskState);
Assert.assertNotNull(taskMetrics.getMetricContext());
Assert.assertTrue(taskMetrics.getMetricContext().getParent().isPresent());
Assert.assertEquals(taskMetrics.getMetricContext().getParent().get(), jobMetrics.getMetricContext());
}
use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.
the class TaskIFaceWrapper method getTaskState.
@Override
public TaskState getTaskState() {
TaskState taskState = this.taskContext.getTaskState();
taskState.setTaskId(getTaskId());
taskState.setJobId(getJobId());
taskState.setWorkingState(getWorkingState());
taskState.addAll(getExecutionMetadata());
taskState.addAll(getPersistentState());
return taskState;
}
use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.
the class ClusterEventMetadataGeneratorTest method testProcessedCount.
@Test
public void testProcessedCount() throws Exception {
JobContext jobContext = Mockito.mock(JobContext.class);
JobState jobState = new JobState("jobName", "1234");
TaskState taskState1 = new TaskState();
TaskState taskState2 = new TaskState();
taskState1.setTaskId("1");
taskState1.setProp(ConfigurationKeys.WRITER_RECORDS_WRITTEN, "1");
taskState2.setTaskId("2");
taskState2.setProp(ConfigurationKeys.WRITER_RECORDS_WRITTEN, "22");
jobState.addTaskState(taskState1);
jobState.addTaskState(taskState2);
Mockito.when(jobContext.getJobState()).thenReturn(jobState);
ClusterEventMetadataGenerator metadataGenerator = new ClusterEventMetadataGenerator();
Map<String, String> metadata;
// processed count is not in job cancel event
metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_CANCEL);
Assert.assertEquals(metadata.get("processedCount"), null);
// processed count is in job complete event
metadata = metadataGenerator.getMetadata(jobContext, EventName.getEnumFromEventId("JobCompleteTimer"));
Assert.assertEquals(metadata.get("processedCount"), "23");
}
Aggregations