Search in sources :

Example 6 with BasicAckableForTesting

use of org.apache.gobblin.ack.BasicAckableForTesting in project incubator-gobblin by apache.

the class TestRecordStream method testAcks.

@Test
public void testAcks() throws Exception {
    StreamEntity[] entities = new StreamEntity[] { new RecordEnvelope<>("a"), new BasicTestControlMessage("1"), new RecordEnvelope<>("b"), new BasicTestControlMessage("2") };
    BasicAckableForTesting ackable = new BasicAckableForTesting();
    for (int i = 0; i < entities.length; i++) {
        entities[i].addCallBack(ackable);
    }
    MyExtractor extractor = new MyExtractor(entities);
    MyConverter converter = new MyConverter();
    MyDataWriter writer = new MyDataWriter();
    // Create a TaskState
    TaskState taskState = getEmptyTestTaskState("testRetryTaskId");
    taskState.setProp(ConfigurationKeys.TASK_SYNCHRONOUS_EXECUTION_MODEL_KEY, false);
    // Create a mock TaskContext
    TaskContext mockTaskContext = mock(TaskContext.class);
    when(mockTaskContext.getExtractor()).thenReturn(extractor);
    when(mockTaskContext.getForkOperator()).thenReturn(new IdentityForkOperator());
    when(mockTaskContext.getTaskState()).thenReturn(taskState);
    when(mockTaskContext.getConverters()).thenReturn(Lists.newArrayList(converter));
    when(mockTaskContext.getTaskLevelPolicyChecker(any(TaskState.class), anyInt())).thenReturn(mock(TaskLevelPolicyChecker.class));
    when(mockTaskContext.getRowLevelPolicyChecker()).thenReturn(new RowLevelPolicyChecker(Lists.newArrayList(), "ss", FileSystem.getLocal(new Configuration())));
    when(mockTaskContext.getRowLevelPolicyChecker(anyInt())).thenReturn(new RowLevelPolicyChecker(Lists.newArrayList(), "ss", FileSystem.getLocal(new Configuration())));
    when(mockTaskContext.getDataWriterBuilder(anyInt(), anyInt())).thenReturn(writer);
    // Create a mock TaskPublisher
    TaskPublisher mockTaskPublisher = mock(TaskPublisher.class);
    when(mockTaskPublisher.canPublish()).thenReturn(TaskPublisher.PublisherState.SUCCESS);
    when(mockTaskContext.getTaskPublisher(any(TaskState.class), any(TaskLevelPolicyCheckResults.class))).thenReturn(mockTaskPublisher);
    // Create a mock TaskStateTracker
    TaskStateTracker mockTaskStateTracker = mock(TaskStateTracker.class);
    // Create a TaskExecutor - a real TaskExecutor must be created so a Fork is run in a separate thread
    TaskExecutor taskExecutor = new TaskExecutor(new Properties());
    // Create the Task
    Task realTask = new Task(mockTaskContext, mockTaskStateTracker, taskExecutor, Optional.<CountDownLatch>absent());
    Task task = spy(realTask);
    doNothing().when(task).submitTaskCommittedEvent();
    task.run();
    task.commit();
    Assert.assertEquals(task.getTaskState().getWorkingState(), WorkUnitState.WorkingState.SUCCESSFUL);
    Assert.assertEquals(ackable.acked, 4);
}
Also used : TaskPublisher(org.apache.gobblin.publisher.TaskPublisher) Configuration(org.apache.hadoop.conf.Configuration) RecordEnvelope(org.apache.gobblin.stream.RecordEnvelope) TaskLevelPolicyChecker(org.apache.gobblin.qualitychecker.task.TaskLevelPolicyChecker) StreamEntity(org.apache.gobblin.stream.StreamEntity) TaskLevelPolicyCheckResults(org.apache.gobblin.qualitychecker.task.TaskLevelPolicyCheckResults) Properties(java.util.Properties) IdentityForkOperator(org.apache.gobblin.fork.IdentityForkOperator) RowLevelPolicyChecker(org.apache.gobblin.qualitychecker.row.RowLevelPolicyChecker) BasicAckableForTesting(org.apache.gobblin.ack.BasicAckableForTesting) Test(org.testng.annotations.Test)

Example 7 with BasicAckableForTesting

use of org.apache.gobblin.ack.BasicAckableForTesting in project incubator-gobblin by apache.

the class ConverterTest method testSingleOutputIterable.

@Test
public void testSingleOutputIterable() throws Exception {
    MyConverter converter = new MyConverter();
    BasicAckableForTesting ackable = new BasicAckableForTesting();
    RecordStreamWithMetadata<Integer, String> stream = new RecordStreamWithMetadata<>(Flowable.just(new RecordEnvelope<>(1)), GlobalMetadata.<String>builder().schema("schema").build()).mapRecords(r -> {
        r.addCallBack(ackable);
        return r;
    });
    List<StreamEntity<Integer>> outputRecords = Lists.newArrayList();
    converter.processStream(stream, new WorkUnitState()).getRecordStream().subscribe(outputRecords::add);
    Assert.assertEquals(outputRecords.size(), 1);
    // output record has not been acked
    Assert.assertEquals(ackable.acked, 0);
    outputRecords.get(0).ack();
    // output record acked
    Assert.assertEquals(ackable.acked, 1);
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) StreamEntity(org.apache.gobblin.stream.StreamEntity) BasicAckableForTesting(org.apache.gobblin.ack.BasicAckableForTesting) Test(org.testng.annotations.Test)

Example 8 with BasicAckableForTesting

use of org.apache.gobblin.ack.BasicAckableForTesting in project incubator-gobblin by apache.

the class ConverterTest method testEmptyOutputIterable.

@Test
public void testEmptyOutputIterable() throws Exception {
    MyConverter converter = new MyConverter();
    BasicAckableForTesting ackable = new BasicAckableForTesting();
    RecordStreamWithMetadata<Integer, String> stream = new RecordStreamWithMetadata<>(Flowable.just(new RecordEnvelope<>(0)), GlobalMetadata.<String>builder().schema("schema").build()).mapRecords(r -> {
        r.addCallBack(ackable);
        return r;
    });
    List<StreamEntity<Integer>> outputRecords = Lists.newArrayList();
    converter.processStream(stream, new WorkUnitState()).getRecordStream().subscribe(outputRecords::add);
    Assert.assertEquals(outputRecords.size(), 0);
    // record got filtered, acked immediately
    Assert.assertEquals(ackable.acked, 1);
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) StreamEntity(org.apache.gobblin.stream.StreamEntity) BasicAckableForTesting(org.apache.gobblin.ack.BasicAckableForTesting) Test(org.testng.annotations.Test)

Example 9 with BasicAckableForTesting

use of org.apache.gobblin.ack.BasicAckableForTesting in project incubator-gobblin by apache.

the class RecordEnvelopeTest method testMultipleDerivedRecords.

@Test
public void testMultipleDerivedRecords() {
    BasicAckableForTesting ackable = new BasicAckableForTesting();
    RecordEnvelope<String> record = new RecordEnvelope<>("test", new MyWatermark(105));
    record.addCallBack(ackable);
    RecordEnvelope<String>.ForkRecordBuilder<String> forkRecordBuilder = record.forkRecordBuilder();
    RecordEnvelope<String> derivedRecord = forkRecordBuilder.childRecord("testDerived");
    derivedRecord.ack();
    // not acked yet as forkRecordBuilder has not been closed
    Assert.assertEquals(ackable.acked, 0);
    Assert.assertEquals(((MyWatermark) derivedRecord.getWatermark()).getId(), 105);
    RecordEnvelope<String> derivedRecord2 = forkRecordBuilder.childRecord("testDerived2");
    derivedRecord2.ack();
    forkRecordBuilder.close();
    Assert.assertEquals(ackable.acked, 1);
    Assert.assertEquals(((MyWatermark) derivedRecord2.getWatermark()).getId(), 105);
}
Also used : BasicAckableForTesting(org.apache.gobblin.ack.BasicAckableForTesting) Test(org.testng.annotations.Test)

Example 10 with BasicAckableForTesting

use of org.apache.gobblin.ack.BasicAckableForTesting in project incubator-gobblin by apache.

the class RecordEnvelopeTest method testDerivedRecordCreation.

@Test
public void testDerivedRecordCreation() {
    BasicAckableForTesting ackable = new BasicAckableForTesting();
    RecordEnvelope<String> record = new RecordEnvelope<>("test", new MyWatermark(101));
    record.addCallBack(ackable);
    RecordEnvelope<String> derivedRecord = record.withRecord("testDerived");
    derivedRecord.ack();
    Assert.assertEquals(ackable.acked, 1);
    Assert.assertEquals(((MyWatermark) derivedRecord.getWatermark()).getId(), 101);
}
Also used : BasicAckableForTesting(org.apache.gobblin.ack.BasicAckableForTesting) Test(org.testng.annotations.Test)

Aggregations

BasicAckableForTesting (org.apache.gobblin.ack.BasicAckableForTesting)14 Test (org.testng.annotations.Test)14 StreamEntity (org.apache.gobblin.stream.StreamEntity)5 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)4 RecordEnvelope (org.apache.gobblin.stream.RecordEnvelope)2 Properties (java.util.Properties)1 State (org.apache.gobblin.configuration.State)1 IdentityForkOperator (org.apache.gobblin.fork.IdentityForkOperator)1 TaskPublisher (org.apache.gobblin.publisher.TaskPublisher)1 RowLevelPolicyChecker (org.apache.gobblin.qualitychecker.row.RowLevelPolicyChecker)1 TaskLevelPolicyCheckResults (org.apache.gobblin.qualitychecker.task.TaskLevelPolicyCheckResults)1 TaskLevelPolicyChecker (org.apache.gobblin.qualitychecker.task.TaskLevelPolicyChecker)1 FlushControlMessage (org.apache.gobblin.stream.FlushControlMessage)1 TestPartitionAwareWriterBuilder (org.apache.gobblin.writer.test.TestPartitionAwareWriterBuilder)1 TestPartitioner (org.apache.gobblin.writer.test.TestPartitioner)1 Configuration (org.apache.hadoop.conf.Configuration)1