Search in sources :

Example 6 with EmbeddedGobblin

use of org.apache.gobblin.runtime.embedded.EmbeddedGobblin in project incubator-gobblin by apache.

the class CustomTaskTest method testCustomTask.

@Test
public void testCustomTask() throws Exception {
    String eventBusId = UUID.randomUUID().toString();
    EventBusPublishingTaskFactory.EventListener listener = new EventBusPublishingTaskFactory.EventListener();
    EventBus eventBus = TestingEventBuses.getEventBus(eventBusId);
    eventBus.register(listener);
    JobExecutionResult result = new EmbeddedGobblin("testJob").setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, EventBusPublishingTaskFactory.Source.class.getName()).setConfiguration(EventBusPublishingTaskFactory.Source.NUM_TASKS_KEY, "10").setConfiguration(EventBusPublishingTaskFactory.EVENTBUS_ID_KEY, eventBusId).run();
    Assert.assertTrue(result.isSuccessful());
    SetMultimap<String, Integer> seenEvents = HashMultimap.create();
    Set<Integer> expected = Sets.newHashSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    for (EventBusPublishingTaskFactory.Event event : listener.getEvents()) {
        seenEvents.put(event.getType(), event.getId());
    }
    Assert.assertEquals(seenEvents.get("run"), expected);
    Assert.assertEquals(seenEvents.get("commit"), expected);
    Assert.assertEquals(seenEvents.get("publish"), expected);
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EventBus(com.google.common.eventbus.EventBus) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) Test(org.testng.annotations.Test)

Example 7 with EmbeddedGobblin

use of org.apache.gobblin.runtime.embedded.EmbeddedGobblin in project incubator-gobblin by apache.

the class CustomTaskTest method testTaskFailsWithException.

@Test(timeOut = 30000)
public void testTaskFailsWithException() throws Exception {
    // Test that the job runner fails with a reasonable amount of time if a custom task throws an exception
    JobExecutionResult result = new EmbeddedGobblin("alwaysThrowsJob").setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, FailsWithExceptionTaskFactory.Source.class.getName()).run();
    Assert.assertFalse(result.isSuccessful());
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) Test(org.testng.annotations.Test)

Example 8 with EmbeddedGobblin

use of org.apache.gobblin.runtime.embedded.EmbeddedGobblin in project incubator-gobblin by apache.

the class TextFileBasedSourceTest method test.

@Test(enabled = false, groups = { "disabledOnTravis" })
public void test() throws Exception {
    File stateStoreDir = Files.createTempDir();
    stateStoreDir.deleteOnExit();
    File dataDir = Files.createTempDir();
    dataDir.deleteOnExit();
    String eventBusId = UUID.randomUUID().toString();
    TestingEventBusAsserter asserter = new TestingEventBusAsserter(eventBusId);
    EmbeddedGobblin gobblin = new EmbeddedGobblin().setTemplate("resource:///templates/textFileBasedSourceTest.template").setConfiguration(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, dataDir.getAbsolutePath()).setConfiguration(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, stateStoreDir.getAbsolutePath()).setConfiguration(GobblinTestEventBusWriter.FULL_EVENTBUSID_KEY, eventBusId).setConfiguration(ConfigurationKeys.STATE_STORE_ENABLED, "true");
    Files.write("record1\nrecord2\nrecord3", new File(dataDir, "file1"), Charsets.UTF_8);
    Files.write("record4\nrecord5", new File(dataDir, "file2"), Charsets.UTF_8);
    gobblin.run();
    Set<Object> events = asserter.getEvents().stream().map(TestingEventBuses.Event::getValue).collect(Collectors.toSet());
    Assert.assertEquals(events, Sets.newHashSet("record1", "record2", "record3", "record4", "record5"));
    asserter.clear();
    // should only pull new files
    Files.write("record6\nrecord7", new File(dataDir, "file3"), Charsets.UTF_8);
    gobblin.run();
    events = asserter.getEvents().stream().map(TestingEventBuses.Event::getValue).collect(Collectors.toSet());
    Assert.assertEquals(events, Sets.newHashSet("record6", "record7"));
    asserter.clear();
    // if we replace old file, it should repull that file
    Assert.assertTrue(new File(dataDir, "file2").delete());
    // Some systems don't provide modtime so gobblin can't keep of changed files.
    // run gobblin once with file2 deleted to update the snapshot
    gobblin.run();
    events = asserter.getEvents().stream().map(TestingEventBuses.Event::getValue).collect(Collectors.toSet());
    Assert.assertTrue(events.isEmpty());
    asserter.clear();
    Files.write("record8\nrecord9", new File(dataDir, "file2"), Charsets.UTF_8);
    gobblin.run();
    events = asserter.getEvents().stream().map(TestingEventBuses.Event::getValue).collect(Collectors.toSet());
    Assert.assertEquals(events, Sets.newHashSet("record8", "record9"));
    asserter.clear();
}
Also used : TestingEventBuses(org.apache.gobblin.writer.test.TestingEventBuses) TestingEventBusAsserter(org.apache.gobblin.writer.test.TestingEventBusAsserter) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) File(java.io.File) Test(org.testng.annotations.Test)

Example 9 with EmbeddedGobblin

use of org.apache.gobblin.runtime.embedded.EmbeddedGobblin in project incubator-gobblin by apache.

the class TextFileBasedSourceTest method testFileLimit.

@Test(enabled = false)
public void testFileLimit() throws Exception {
    File stateStoreDir = Files.createTempDir();
    stateStoreDir.deleteOnExit();
    File dataDir = Files.createTempDir();
    dataDir.deleteOnExit();
    String eventBusId = UUID.randomUUID().toString();
    TestingEventBusAsserter asserter = new TestingEventBusAsserter(eventBusId);
    EmbeddedGobblin gobblin = new EmbeddedGobblin().setTemplate("resource:///templates/textFileBasedSourceTest.template").setConfiguration(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, dataDir.getAbsolutePath()).setConfiguration(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, stateStoreDir.getAbsolutePath()).setConfiguration(GobblinTestEventBusWriter.FULL_EVENTBUSID_KEY, eventBusId).setConfiguration(ConfigurationKeys.STATE_STORE_ENABLED, "true").setConfiguration(ConfigurationKeys.SOURCE_FILEBASED_MAX_FILES_PER_RUN, "2");
    Files.write("record1\nrecord2\nrecord3", new File(dataDir, "file1"), Charsets.UTF_8);
    Files.write("record4\nrecord5", new File(dataDir, "file2"), Charsets.UTF_8);
    Files.write("record6\nrecord7", new File(dataDir, "file3"), Charsets.UTF_8);
    gobblin.run();
    // should only pull first 2 files
    Set<Object> events = asserter.getEvents().stream().map(TestingEventBuses.Event::getValue).collect(Collectors.toSet());
    Assert.assertEquals(events, Sets.newHashSet("record1", "record2", "record3", "record4", "record5"));
    asserter.clear();
    gobblin.run();
    events = asserter.getEvents().stream().map(TestingEventBuses.Event::getValue).collect(Collectors.toSet());
    Assert.assertEquals(events, Sets.newHashSet("record6", "record7"));
    asserter.clear();
}
Also used : TestingEventBuses(org.apache.gobblin.writer.test.TestingEventBuses) TestingEventBusAsserter(org.apache.gobblin.writer.test.TestingEventBusAsserter) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) File(java.io.File) Test(org.testng.annotations.Test)

Example 10 with EmbeddedGobblin

use of org.apache.gobblin.runtime.embedded.EmbeddedGobblin in project incubator-gobblin by apache.

the class CustomTaskTest method testStatePersistence.

@Test
public void testStatePersistence() throws Exception {
    File stateStore = Files.createTempDir();
    stateStore.deleteOnExit();
    String eventBusId = UUID.randomUUID().toString();
    EventBusPublishingTaskFactory.EventListener listener = new EventBusPublishingTaskFactory.EventListener();
    EventBus eventBus = TestingEventBuses.getEventBus(eventBusId);
    eventBus.register(listener);
    EmbeddedGobblin embeddedGobblin = new EmbeddedGobblin("testJob").setConfiguration(EventBusPublishingTaskFactory.EVENTBUS_ID_KEY, eventBusId).setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, EventBusPublishingTaskFactory.Source.class.getName()).setConfiguration(EventBusPublishingTaskFactory.Source.NUM_TASKS_KEY, "2").setConfiguration(ConfigurationKeys.STATE_STORE_ENABLED, Boolean.toString(true)).setConfiguration(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, stateStore.getAbsolutePath());
    JobExecutionResult result = embeddedGobblin.run();
    Assert.assertTrue(result.isSuccessful());
    SetMultimap<String, Integer> seenEvents = HashMultimap.create();
    for (EventBusPublishingTaskFactory.Event event : listener.getEvents()) {
        seenEvents.put(event.getType(), event.getId());
    }
    Assert.assertEquals(seenEvents.get("previousState").size(), 0);
    result = embeddedGobblin.run();
    Assert.assertTrue(result.isSuccessful());
    seenEvents = HashMultimap.create();
    for (EventBusPublishingTaskFactory.Event event : listener.getEvents()) {
        seenEvents.put(event.getType(), event.getId());
    }
    Assert.assertEquals(seenEvents.get("previousState"), Sets.newHashSet(0, 1));
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EventBus(com.google.common.eventbus.EventBus) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

EmbeddedGobblin (org.apache.gobblin.runtime.embedded.EmbeddedGobblin)16 Test (org.testng.annotations.Test)14 JobExecutionResult (org.apache.gobblin.runtime.api.JobExecutionResult)12 File (java.io.File)11 GenericRecord (org.apache.avro.generic.GenericRecord)7 EventBus (com.google.common.eventbus.EventBus)3 TestingEventBusAsserter (org.apache.gobblin.writer.test.TestingEventBusAsserter)2 TestingEventBuses (org.apache.gobblin.writer.test.TestingEventBuses)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 JobExecutionDriver (org.apache.gobblin.runtime.api.JobExecutionDriver)1 ClassAliasResolver (org.apache.gobblin.util.ClassAliasResolver)1 GobblinTestEventBusWriter (org.apache.gobblin.writer.test.GobblinTestEventBusWriter)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1