Search in sources :

Example 21 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method testSelfIndirectlyImportDescendant.

@Test
public void testSelfIndirectlyImportDescendant() {
    ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag");
    ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag");
    ConfigKeyPath nertzHighPriorityTag = highPriorityTag.createChild("nertzHighPriorityTag");
    ConfigKeyPath tag2 = SingleLinkedListConfigKeyPath.ROOT.createChild("tag2");
    ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
    when(mockConfigStore.getCurrentVersion()).thenReturn(version);
    addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag, tag2);
    addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag);
    addConfigStoreChildren(mockConfigStore, version, highPriorityTag, nertzHighPriorityTag);
    // self import descendant
    // formed the loop /tag -> /tag2 -> /tag/highPriorityTag/nertzHighPriorityTag -> /tag/highPriorityTag -> /tag
    addConfigStoreImports(mockConfigStore, version, tag, tag2);
    addConfigStoreImports(mockConfigStore, version, tag2, nertzHighPriorityTag);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    try {
        inMemory.getImportsRecursively(tag);
        Assert.fail("Did not catch expected CircularDependencyException");
    } catch (CircularDependencyException e) {
        Assert.assertTrue(e.getMessage().indexOf("/tag/highPriorityTag/nertzHighPriorityTag") > 0 && e.getMessage().indexOf("/tag/highPriorityTag ") > 0 && e.getMessage().indexOf("/tag ") > 0 && e.getMessage().indexOf("/tag2 ") > 0);
    }
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 22 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method testSelfImportChild.

@Test
public void testSelfImportChild() {
    ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag");
    ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag");
    ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
    when(mockConfigStore.getCurrentVersion()).thenReturn(version);
    addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag);
    addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag);
    // parent import direct child
    addConfigStoreImports(mockConfigStore, version, tag, highPriorityTag);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    try {
        inMemory.getImportsRecursively(tag);
        Assert.fail("Did not catch expected CircularDependencyException");
    } catch (CircularDependencyException e) {
        Assert.assertTrue(e.getMessage().indexOf("/tag/highPriorityTag") > 0 && e.getMessage().indexOf("/tag ") > 0);
    }
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 23 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method testNoCircular.

@Test
public void testNoCircular() {
    ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag");
    ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag");
    ConfigKeyPath nertzHighPriorityTag = highPriorityTag.createChild("nertzHighPriorityTag");
    ConfigKeyPath tag2 = SingleLinkedListConfigKeyPath.ROOT.createChild("tag2");
    ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
    when(mockConfigStore.getCurrentVersion()).thenReturn(version);
    addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag, tag2);
    addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag);
    addConfigStoreChildren(mockConfigStore, version, highPriorityTag, nertzHighPriorityTag);
    // mock up imports, point to same node but without circular
    addConfigStoreImports(mockConfigStore, version, nertzHighPriorityTag, tag2);
    addConfigStoreImports(mockConfigStore, version, tag2, tag);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    List<ConfigKeyPath> result = inMemory.getImportsRecursively(nertzHighPriorityTag);
    Assert.assertEquals(result.size(), 4);
    Iterator<ConfigKeyPath> it = result.iterator();
    Assert.assertEquals(it.next(), tag2);
    Assert.assertEquals(it.next(), tag);
    Assert.assertTrue(it.next().isRootPath());
    Assert.assertEquals(it.next(), highPriorityTag);
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 24 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestCircularDependency method testSelfImportSelf.

@Test
public void testSelfImportSelf() {
    ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag");
    ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS);
    when(mockConfigStore.getCurrentVersion()).thenReturn(version);
    addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag);
    // self import self
    addConfigStoreImports(mockConfigStore, version, tag, tag);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    try {
        inMemory.getImportsRecursively(tag);
        Assert.fail("Did not catch expected CircularDependencyException");
    } catch (CircularDependencyException e) {
        Assert.assertTrue(e.getMessage().indexOf("/tag") > 0);
    }
}
Also used : ConfigStore(org.apache.gobblin.config.store.api.ConfigStore) ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) Test(org.testng.annotations.Test)

Example 25 with ConfigKeyPath

use of org.apache.gobblin.config.store.api.ConfigKeyPath in project incubator-gobblin by apache.

the class TestInMemoryTopology method testNonRootTopology.

@Test
public void testNonRootTopology() {
    Assert.assertEquals(mockConfigStore.getCurrentVersion(), version);
    ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(this.mockConfigStore, this.version);
    InMemoryTopology inMemory = new InMemoryTopology(csTopology);
    Collection<ConfigKeyPath> result = inMemory.getChildren(data);
    Assert.assertTrue(result.size() == 1);
    Assert.assertEquals(result.iterator().next(), databases);
    // test own imports
    result = inMemory.getOwnImports(identity);
    Assert.assertTrue(result.size() == 2);
    Iterator<ConfigKeyPath> it = result.iterator();
    Assert.assertEquals(it.next(), espressoTag);
    Assert.assertEquals(it.next(), highPriorityTag);
    // test import recursively
    result = inMemory.getImportsRecursively(identity);
    Assert.assertEquals(result.size(), 8);
    Assert.assertEquals(result, Lists.newArrayList(highPriorityTag, tag, SingleLinkedListConfigKeyPath.ROOT, espressoTag, nertzTag2, tag2, databases, data));
    // test own imported by
    result = inMemory.getImportedBy(nertzTag2);
    Assert.assertTrue(result.size() == 1);
    Assert.assertEquals(result.iterator().next(), espressoTag);
    // test imported by recursively, as the imported by recursively do not care about
    // order, need to use HashSet to test
    result = inMemory.getImportedByRecursively(nertzTag2);
    Set<ConfigKeyPath> expected = new HashSet<ConfigKeyPath>();
    expected.add(espressoTag);
    expected.add(identity);
    Assert.assertTrue(result.size() == 2);
    it = result.iterator();
    while (it.hasNext()) {
        ConfigKeyPath tmp = it.next();
        Assert.assertTrue(expected.contains(tmp));
        expected.remove(tmp);
    }
}
Also used : ConfigKeyPath(org.apache.gobblin.config.store.api.ConfigKeyPath) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ConfigKeyPath (org.apache.gobblin.config.store.api.ConfigKeyPath)37 Test (org.testng.annotations.Test)18 SingleLinkedListConfigKeyPath (org.apache.gobblin.config.common.impl.SingleLinkedListConfigKeyPath)15 ArrayList (java.util.ArrayList)10 Path (org.apache.hadoop.fs.Path)9 ConfigStore (org.apache.gobblin.config.store.api.ConfigStore)8 Config (com.typesafe.config.Config)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 BufferedWriter (java.io.BufferedWriter)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Path (java.nio.file.Path)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 InputStreamReader (java.io.InputStreamReader)2 HashSet (java.util.HashSet)2 FsDeploymentConfig (org.apache.gobblin.config.store.deploy.FsDeploymentConfig)2 SeekableFSInputStream (org.apache.gobblin.util.io.SeekableFSInputStream)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1