Search in sources :

Example 11 with GobblinScopeTypes

use of org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes in project incubator-gobblin by apache.

the class DefaultGobblinBrokerTest method testSharedObjects.

@Test
public void testSharedObjects() throws Exception {
    // Correct creation behavior
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> taskBroker = jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskabc")).withAdditionalParentBroker(containerBroker).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> taskBroker2 = jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskxyz")).withAdditionalParentBroker(containerBroker).build();
    // create a shared resource
    TestFactory.SharedResource resource = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.JOB);
    Assert.assertEquals(resource.getKey(), "myKey");
    // using same broker with same scope and key returns same object
    Assert.assertEquals(taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.JOB), resource);
    // using different broker with same scope and key returns same object
    Assert.assertEquals(taskBroker2.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.JOB), resource);
    Assert.assertEquals(jobBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.JOB), resource);
    // Using different key returns a different object
    Assert.assertNotEquals(taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("otherKey"), GobblinScopeTypes.JOB), resource);
    // Using different scope returns different object
    Assert.assertNotEquals(taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.TASK), resource);
    // Requesting unscoped resource returns different object
    Assert.assertNotEquals(taskBroker.getSharedResource(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey")), resource);
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Example 12 with GobblinScopeTypes

use of org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes in project incubator-gobblin by apache.

the class DefaultGobblinBrokerTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> taskBroker = jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskabc")).withAdditionalParentBroker(containerBroker).build();
    // create a shared resource
    TestFactory.SharedResource jobResource = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.JOB);
    TestFactory.SharedResource taskResource = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.TASK);
    Assert.assertFalse(jobResource.isClosed());
    Assert.assertFalse(taskResource.isClosed());
    taskBroker.close();
    // only resources at lower scopes than task should be closed
    Assert.assertFalse(jobResource.isClosed());
    Assert.assertTrue(taskResource.isClosed());
    // since taskResource has been closed, broker should return a new instance of the object
    TestFactory.SharedResource taskResource2 = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.TASK);
    Assert.assertNotEquals(taskResource, taskResource2);
    topBroker.close();
    Assert.assertTrue(jobResource.isClosed());
    Assert.assertTrue(taskResource.isClosed());
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Example 13 with GobblinScopeTypes

use of org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes in project incubator-gobblin by apache.

the class GobblinBrokerConfTest method testCorrectConfigInjection.

@Test
public void testCorrectConfigInjection() {
    String key = "myKey";
    Config config = ConfigFactory.parseMap(ImmutableMap.of(JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, "key1"), "value1", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, "key2"), "value2", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, GobblinScopeTypes.CONTAINER.name(), "key2"), "value2scope", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, key, "key2"), "value2key", JOINER.join(BrokerConstants.GOBBLIN_BROKER_CONFIG_PREFIX, TestFactory.NAME, GobblinScopeTypes.CONTAINER.name(), key, "key2"), "value2scopekey"));
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    KeyedScopedConfigViewImpl<GobblinScopeTypes, TestResourceKey> configView = topBroker.getConfigView(GobblinScopeTypes.CONTAINER, new TestResourceKey(key), TestFactory.NAME);
    Assert.assertEquals(configView.getScope(), GobblinScopeTypes.CONTAINER);
    Assert.assertEquals(configView.getKey().toConfigurationKey(), key);
    Assert.assertEquals(configView.getKeyedConfig().getString("key2"), "value2key");
    Assert.assertEquals(configView.getScopedConfig().getString("key2"), "value2scope");
    Assert.assertEquals(configView.getKeyedScopedConfig().getString("key2"), "value2scopekey");
    Assert.assertEquals(configView.getFactorySpecificConfig().getString("key1"), "value1");
    Assert.assertEquals(configView.getFactorySpecificConfig().getString("key2"), "value2");
    Assert.assertEquals(configView.getConfig().getString("key2"), "value2scopekey");
    Assert.assertEquals(configView.getConfig().getString("key1"), "value1");
    configView = topBroker.getConfigView(GobblinScopeTypes.TASK, new TestResourceKey(key), TestFactory.NAME);
    Assert.assertEquals(configView.getConfig().getString("key2"), "value2key");
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) Config(com.typesafe.config.Config) Test(org.testng.annotations.Test)

Example 14 with GobblinScopeTypes

use of org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes in project incubator-gobblin by apache.

the class GobblinBrokerCreationTest method testFailIfDifferentAncestors.

@Test
public void testFailIfDifferentAncestors() throws Exception {
    // Correct creation behavior
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker2 = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker2.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    try {
        jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskxyz")).withAdditionalParentBroker(containerBroker).build();
        Assert.fail();
    } catch (IllegalArgumentException iae) {
    // expected
    }
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Example 15 with GobblinScopeTypes

use of org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes in project incubator-gobblin by apache.

the class GobblinBrokerCreationTest method testCreationOfBrokers.

@Test
public void testCreationOfBrokers() throws Exception {
    // Correct creation behavior
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, new SimpleScope<GobblinScopeTypes>(GobblinScopeTypes.GLOBAL, "myGlobalScope"));
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> taskBroker = jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskabc")).withAdditionalParentBroker(containerBroker).build();
    Assert.assertEquals(taskBroker.selfScope().getType(), GobblinScopeTypes.TASK);
    Assert.assertEquals(((TaskScopeInstance) taskBroker.selfScope()).getTaskId(), "taskabc");
    Assert.assertEquals(taskBroker.getScope(GobblinScopeTypes.CONTAINER).getType(), GobblinScopeTypes.CONTAINER);
    Assert.assertEquals(((GobblinScopeInstance) taskBroker.getScope(GobblinScopeTypes.CONTAINER)).getScopeId(), "container");
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Aggregations

GobblinScopeTypes (org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes)19 Config (com.typesafe.config.Config)16 Test (org.testng.annotations.Test)15 JobScopeInstance (org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance)12 TaskScopeInstance (org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance)9 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)2 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)2 Predicate (com.google.common.base.Predicate)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 EmptyKey (org.apache.gobblin.broker.EmptyKey)1 GobblinScopeInstance (org.apache.gobblin.broker.gobblin_scopes.GobblinScopeInstance)1 NoSuchScopeException (org.apache.gobblin.broker.iface.NoSuchScopeException)1 NotConfiguredException (org.apache.gobblin.broker.iface.NotConfiguredException)1 SubscopedBrokerBuilder (org.apache.gobblin.broker.iface.SubscopedBrokerBuilder)1 State (org.apache.gobblin.configuration.State)1 CopyConfiguration (org.apache.gobblin.data.management.copy.CopyConfiguration)1 JobState (org.apache.gobblin.runtime.JobState)1 MultiWorkUnit (org.apache.gobblin.source.workunit.MultiWorkUnit)1 StreamCopier (org.apache.gobblin.util.io.StreamCopier)1