Search in sources :

Example 16 with Files

use of com.google.common.io.Files in project incubator-gobblin by apache.

the class FsSpecProducerTest method testAddSpec.

@Test
public void testAddSpec() throws URISyntaxException, ExecutionException, InterruptedException, IOException {
    this._fsSpecProducer.addSpec(createTestJobSpec());
    // Add some random files(with non-avro extension name) into the folder observed by consumer, they shall not be picked up.
    File randomFile = new File(workDir, "random");
    Assert.assertTrue(randomFile.createNewFile());
    randomFile.deleteOnExit();
    List<Pair<SpecExecutor.Verb, Spec>> jobSpecs = this._fsSpecConsumer.changedSpecs().get();
    Assert.assertEquals(jobSpecs.size(), 1);
    Assert.assertEquals(jobSpecs.get(0).getLeft(), SpecExecutor.Verb.ADD);
    Assert.assertEquals(jobSpecs.get(0).getRight().getUri().toString(), "testJob");
    Assert.assertEquals(((JobSpec) jobSpecs.get(0).getRight()).getConfig().getString("key1"), "val1");
    Assert.assertEquals(((JobSpec) jobSpecs.get(0).getRight()).getConfig().getString("key2"), "val2");
    Assert.assertEquals(((JobSpec) jobSpecs.get(0).getRight()).getConfig().getString("key3.1" + ConfigUtils.STRIP_SUFFIX), "val3");
    Assert.assertEquals(((JobSpec) jobSpecs.get(0).getRight()).getConfig().getString("key3.1.1"), "val4");
    jobSpecs.clear();
    // If there are other jobSpec in .avro files added by testSpecProducer, they shall still be found.
    this._fsSpecProducer.addSpec(createTestJobSpec("newTestJob"));
    jobSpecs = this._fsSpecConsumer.changedSpecs().get();
    Assert.assertEquals(jobSpecs.size(), 2);
    Assert.assertEquals(jobSpecs.get(0).getLeft(), SpecExecutor.Verb.ADD);
    Assert.assertEquals(jobSpecs.get(1).getLeft(), SpecExecutor.Verb.ADD);
    List<String> uriList = jobSpecs.stream().map(s -> s.getRight().getUri().toString()).collect(Collectors.toList());
    Assert.assertTrue(uriList.contains("testJob"));
    Assert.assertTrue(uriList.contains("newTestJob"));
}
Also used : Properties(java.util.Properties) Config(com.typesafe.config.Config) URISyntaxException(java.net.URISyntaxException) BeforeMethod(org.testng.annotations.BeforeMethod) IOException(java.io.IOException) Test(org.testng.annotations.Test) ConfigValueFactory(com.typesafe.config.ConfigValueFactory) ConfigUtils(org.apache.gobblin.util.ConfigUtils) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Files(com.google.common.io.Files) ConfigFactory(com.typesafe.config.ConfigFactory) URI(java.net.URI) File(java.io.File) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Aggregations

Files (com.google.common.io.Files)16 File (java.io.File)13 IOException (java.io.IOException)11 List (java.util.List)9 StandardCharsets (java.nio.charset.StandardCharsets)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Stream (java.util.stream.Stream)5 Joiner (com.google.common.base.Joiner)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Optional (java.util.Optional)3 Before (org.junit.Before)3 Compiler (com.facebook.buck.cxx.Compiler)2 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 Flavor (com.facebook.buck.model.Flavor)2 InternalFlavor (com.facebook.buck.model.InternalFlavor)2 BuildRule (com.facebook.buck.rules.BuildRule)2