Search in sources :

Example 1 with JobContext

use of org.apache.gobblin.runtime.JobContext 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"));
}
Also used : JobState(org.apache.gobblin.runtime.JobState) JobContext(org.apache.gobblin.runtime.JobContext) TaskState(org.apache.gobblin.runtime.TaskState) Test(org.testng.annotations.Test)

Example 2 with JobContext

use of org.apache.gobblin.runtime.JobContext 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");
}
Also used : JobState(org.apache.gobblin.runtime.JobState) JobContext(org.apache.gobblin.runtime.JobContext) TaskState(org.apache.gobblin.runtime.TaskState) Test(org.testng.annotations.Test)

Aggregations

JobContext (org.apache.gobblin.runtime.JobContext)2 JobState (org.apache.gobblin.runtime.JobState)2 TaskState (org.apache.gobblin.runtime.TaskState)2 Test (org.testng.annotations.Test)2