Search in sources :

Example 86 with State

use of org.apache.gobblin.configuration.State 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());
}
Also used : SourceState(org.apache.gobblin.configuration.SourceState) JobState(org.apache.gobblin.runtime.JobState) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) SourceState(org.apache.gobblin.configuration.SourceState) State(org.apache.gobblin.configuration.State) TaskState(org.apache.gobblin.runtime.TaskState) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) JobState(org.apache.gobblin.runtime.JobState) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TaskState(org.apache.gobblin.runtime.TaskState) Test(org.testng.annotations.Test)

Example 87 with State

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

the class JobMetricsTest method testCustomTags.

@Test
public void testCustomTags() {
    Properties testProperties = new Properties();
    Tag<String> expectedPropertyTag = new Tag<>("key1", "value1");
    GobblinMetrics.addCustomTagToProperties(testProperties, expectedPropertyTag);
    State testState = new State(testProperties);
    List<Tag<?>> tags = GobblinMetrics.getCustomTagsFromState(testState);
    Assert.assertEquals(Iterables.getFirst(tags, null), expectedPropertyTag);
    Tag<String> expectedStateTag = new Tag<>("key2", "value2");
    GobblinMetrics.addCustomTagToState(testState, expectedStateTag);
    tags = GobblinMetrics.getCustomTagsFromState(testState);
    Assert.assertTrue(tags.containsAll(ImmutableList.of(expectedPropertyTag, expectedStateTag)));
}
Also used : JobState(org.apache.gobblin.runtime.JobState) State(org.apache.gobblin.configuration.State) Tag(org.apache.gobblin.metrics.Tag) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 88 with State

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

the class ForkOperatorUtilsTest method testGetPathForBranch.

@Test
public void testGetPathForBranch() {
    State state = new State();
    state.setProp(ConfigurationKeys.FORK_BRANCH_NAME_KEY + ".0", FORK_BRANCH_NAME_0);
    state.setProp(ConfigurationKeys.FORK_BRANCH_NAME_KEY + ".1", FORK_BRANCH_NAME_1);
    Assert.assertEquals(ForkOperatorUtils.getPathForBranch(state, PATH_FOO, 2, 0), PATH_FOO + "/" + FORK_BRANCH_NAME_0);
    Assert.assertEquals(ForkOperatorUtils.getPathForBranch(state, PATH_FOO, 2, 1), PATH_FOO + "/" + FORK_BRANCH_NAME_1);
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) State(org.apache.gobblin.configuration.State) Test(org.testng.annotations.Test)

Example 89 with State

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

the class HadoopUtilsTest method testEncryptedStateToConfiguration.

@Test
public void testEncryptedStateToConfiguration() throws IOException {
    Map<String, String> vals = Maps.newHashMap();
    vals.put("test_key1", "test_val1");
    vals.put("test_key2", "test_val2");
    State state = new State();
    for (Map.Entry<String, String> entry : vals.entrySet()) {
        state.setProp(entry.getKey(), entry.getValue());
    }
    Map<String, String> encryptedVals = Maps.newHashMap();
    encryptedVals.put("key1", "val1");
    encryptedVals.put("key2", "val2");
    final String encryptedPath = "encrypted.name.space";
    for (Map.Entry<String, String> entry : encryptedVals.entrySet()) {
        state.setProp(encryptedPath + "." + entry.getKey(), entry.getValue());
    }
    Configuration configuration = HadoopUtils.getConfFromState(state, Optional.of(encryptedPath));
    for (Map.Entry<String, String> entry : vals.entrySet()) {
        String val = configuration.get(entry.getKey());
        Assert.assertEquals(val, entry.getValue());
    }
    for (Map.Entry<String, String> entry : encryptedVals.entrySet()) {
        // Verify key with child path exist as decryption is unit tested in ConfigUtil.
        Assert.assertNotNull(configuration.get(entry.getKey()));
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) State(org.apache.gobblin.configuration.State) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 90 with State

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

the class HadoopUtilsTest method fsShortSerializationTest.

@Test
public void fsShortSerializationTest() {
    State state = new State();
    short mode = 420;
    FsPermission perms = new FsPermission(mode);
    HadoopUtils.serializeWriterFilePermissions(state, 0, 0, perms);
    FsPermission deserializedPerms = HadoopUtils.deserializeWriterFilePermissions(state, 0, 0);
    Assert.assertEquals(mode, deserializedPerms.toShort());
}
Also used : State(org.apache.gobblin.configuration.State) FsPermission(org.apache.hadoop.fs.permission.FsPermission) 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