Search in sources :

Example 71 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class HiveCopyEntityHelperTest method testAddTableDeregisterSteps.

@Test
public void testAddTableDeregisterSteps() throws Exception {
    HiveDataset dataset = Mockito.mock(HiveDataset.class);
    Mockito.when(dataset.getProperties()).thenReturn(new Properties());
    HiveCopyEntityHelper helper = Mockito.mock(HiveCopyEntityHelper.class);
    Mockito.when(helper.getDeleteMethod()).thenReturn(DeregisterFileDeleteMethod.NO_DELETE);
    Mockito.when(helper.getTargetURI()).thenReturn(Optional.of("/targetURI"));
    Mockito.when(helper.getHiveRegProps()).thenReturn(new HiveRegProps(new State()));
    Mockito.when(helper.getDataset()).thenReturn(dataset);
    Mockito.when(helper.addTableDeregisterSteps(Mockito.any(List.class), Mockito.any(String.class), Mockito.anyInt(), Mockito.any(org.apache.hadoop.hive.ql.metadata.Table.class))).thenCallRealMethod();
    org.apache.hadoop.hive.ql.metadata.Table meta_table = Mockito.mock(org.apache.hadoop.hive.ql.metadata.Table.class);
    org.apache.hadoop.hive.metastore.api.Table api_table = Mockito.mock(org.apache.hadoop.hive.metastore.api.Table.class);
    Mockito.when(api_table.getDbName()).thenReturn("TestDB");
    Mockito.when(api_table.getTableName()).thenReturn("TestTable");
    Mockito.when(meta_table.getTTable()).thenReturn(api_table);
    List<CopyEntity> copyEntities = new ArrayList<CopyEntity>();
    String fileSet = "testFileSet";
    int initialPriority = 0;
    int priority = helper.addTableDeregisterSteps(copyEntities, fileSet, initialPriority, meta_table);
    Assert.assertTrue(priority == 1);
    Assert.assertTrue(copyEntities.size() == 1);
    Assert.assertTrue(copyEntities.get(0) instanceof PostPublishStep);
    PostPublishStep p = (PostPublishStep) (copyEntities.get(0));
    Assert.assertTrue(p.getStep().toString().contains("Deregister table TestDB.TestTable on Hive metastore /targetURI"));
}
Also used : Table(org.apache.hadoop.hive.ql.metadata.Table) CopyEntity(org.apache.gobblin.data.management.copy.CopyEntity) PostPublishStep(org.apache.gobblin.data.management.copy.entities.PostPublishStep) ArrayList(java.util.ArrayList) Table(org.apache.hadoop.hive.ql.metadata.Table) Properties(java.util.Properties) State(org.apache.gobblin.configuration.State) ArrayList(java.util.ArrayList) List(java.util.List) HiveRegProps(org.apache.gobblin.hive.HiveRegProps) Test(org.testng.annotations.Test)

Example 72 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class CopyDataPublisherTest method testPublishOverlappingDatasets.

@Test
@SuppressWarnings("unchecked")
public void testPublishOverlappingDatasets() throws Exception {
    State state = getTestState("testPublishOverlappingDatasets");
    state.setProp(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, "/");
    Path testMethodTempPath = new Path(testClassTempPath, "testPublishOverlappingDatasets");
    CopyDataPublisher copyDataPublisher = closer.register(new CopyDataPublisher(state));
    TestDatasetManager dataset1Manager = new TestDatasetManager(testMethodTempPath, state, "datasetTargetPath", ImmutableList.of("a/b"));
    dataset1Manager.createDatasetFiles();
    TestDatasetManager dataset2Manager = new TestDatasetManager(testMethodTempPath, state, "datasetTargetPath/subDir", ImmutableList.of("a/c", "d/e"));
    dataset2Manager.createDatasetFiles();
    dataset1Manager.verifyDoesntExist();
    dataset2Manager.verifyDoesntExist();
    copyDataPublisher.publishData(combine(dataset1Manager.getWorkUnitStates(), dataset2Manager.getWorkUnitStates()));
    dataset1Manager.verifyExists();
    dataset2Manager.verifyExists();
}
Also used : Path(org.apache.hadoop.fs.Path) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) State(org.apache.gobblin.configuration.State) Test(org.testng.annotations.Test)

Example 73 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class CopyDataPublisherTest method testPublishMultipleDatasets.

@Test
@SuppressWarnings("unchecked")
public void testPublishMultipleDatasets() throws Exception {
    State state = getTestState("testPublishMultipleDatasets");
    state.setProp(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, "/");
    Path testMethodTempPath = new Path(testClassTempPath, "testPublishMultipleDatasets");
    CopyDataPublisher copyDataPublisher = closer.register(new CopyDataPublisher(state));
    TestDatasetManager dataset1Manager = new TestDatasetManager(testMethodTempPath, state, "dataset1TargetPath", ImmutableList.of("a/b", "a/c", "d/e"));
    dataset1Manager.createDatasetFiles();
    TestDatasetManager dataset2Manager = new TestDatasetManager(testMethodTempPath, state, "dataset2TargetPath", ImmutableList.of("a/b", "a/c", "d/e"));
    dataset2Manager.createDatasetFiles();
    dataset1Manager.verifyDoesntExist();
    dataset2Manager.verifyDoesntExist();
    copyDataPublisher.publishData(combine(dataset1Manager.getWorkUnitStates(), dataset2Manager.getWorkUnitStates()));
    dataset1Manager.verifyExists();
    dataset2Manager.verifyExists();
}
Also used : Path(org.apache.hadoop.fs.Path) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) State(org.apache.gobblin.configuration.State) Test(org.testng.annotations.Test)

Example 74 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class DeletingCopyDataPublisherTest method testDeleteOnSource.

@Test
public void testDeleteOnSource() throws Exception {
    State state = getTestState("testDeleteOnSource");
    Path testMethodTempPath = new Path(testClassTempPath, "testDeleteOnSource");
    DeletingCopyDataPublisher copyDataPublisher = closer.register(new DeletingCopyDataPublisher(state));
    File outputDir = new File(testMethodTempPath.toString(), "task-output/jobid/1f042f494d1fe2198e0e71a17faa233f33b5099b");
    outputDir.mkdirs();
    outputDir.deleteOnExit();
    WorkUnitState wus = new WorkUnitState();
    CopyableDataset copyableDataset = new TestCopyableDataset(new Path("origin"));
    CopyableDatasetMetadata metadata = new CopyableDatasetMetadata(copyableDataset);
    CopyEntity cf = CopyableFileUtils.createTestCopyableFile(new Path(testMethodTempPath, "test.txt").toString());
    CopySource.serializeCopyableDataset(wus, metadata);
    CopySource.serializeCopyEntity(wus, cf);
    Assert.assertTrue(fs.exists(new Path(testMethodTempPath, "test.txt")));
    wus.setWorkingState(WorkingState.SUCCESSFUL);
    copyDataPublisher.publishData(ImmutableList.of(wus));
    Assert.assertFalse(fs.exists(new Path(testMethodTempPath, "test.txt")));
}
Also used : Path(org.apache.hadoop.fs.Path) TestCopyableDataset(org.apache.gobblin.data.management.copy.TestCopyableDataset) CopyableDataset(org.apache.gobblin.data.management.copy.CopyableDataset) TestCopyableDataset(org.apache.gobblin.data.management.copy.TestCopyableDataset) CopyEntity(org.apache.gobblin.data.management.copy.CopyEntity) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) State(org.apache.gobblin.configuration.State) WorkingState(org.apache.gobblin.configuration.WorkUnitState.WorkingState) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) CopyableDatasetMetadata(org.apache.gobblin.data.management.copy.CopyableDatasetMetadata) File(java.io.File) Test(org.testng.annotations.Test)

Example 75 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class RecoveryHelperTest method testGetPersistDir.

@Test
public void testGetPersistDir() throws Exception {
    State state = new State();
    Assert.assertFalse(RecoveryHelper.getPersistDir(state).isPresent());
    state.setProp(RecoveryHelper.PERSIST_DIR_KEY, this.tmpDir.getAbsolutePath());
    Assert.assertTrue(RecoveryHelper.getPersistDir(state).isPresent());
    Assert.assertTrue(RecoveryHelper.getPersistDir(state).get().toUri().getPath().startsWith(this.tmpDir.getAbsolutePath()));
}
Also used : State(org.apache.gobblin.configuration.State) Test(org.testng.annotations.Test)

Aggregations

State (org.apache.gobblin.configuration.State)195 Test (org.testng.annotations.Test)103 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)74 SourceState (org.apache.gobblin.configuration.SourceState)38 Path (org.apache.hadoop.fs.Path)30 File (java.io.File)20 IOException (java.io.IOException)16 Map (java.util.Map)14 WorkingState (org.apache.gobblin.configuration.WorkUnitState.WorkingState)14 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)14 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)13 Properties (java.util.Properties)12 FinalState (org.apache.gobblin.util.FinalState)12 Configuration (org.apache.hadoop.conf.Configuration)12 TaskLevelPolicyCheckResults (org.apache.gobblin.qualitychecker.task.TaskLevelPolicyCheckResults)9 Config (com.typesafe.config.Config)8 ArrayList (java.util.ArrayList)8 GenericRecord (org.apache.avro.generic.GenericRecord)8 LongWatermark (org.apache.gobblin.source.extractor.extract.LongWatermark)7 FileInputStream (java.io.FileInputStream)6