Search in sources :

Example 1 with NonObservingFSJobCatalog

use of org.apache.gobblin.runtime.job_catalog.NonObservingFSJobCatalog in project incubator-gobblin by apache.

the class StreamingKafkaSpecExecutorTest method testAddSpec.

@Test
public void testAddSpec() throws Exception {
    _closer = Closer.create();
    _properties = new Properties();
    // Properties for Producer
    _properties.setProperty(KafkaWriterConfigurationKeys.KAFKA_TOPIC, TOPIC);
    _properties.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX + "bootstrap.servers", _kafkaBrokers);
    _properties.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX + "value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    // Properties for Consumer
    _properties.setProperty("jobSpecMonitor.kafka.zookeeper.connect", zkConnect);
    _properties.setProperty(SimpleKafkaSpecExecutor.SPEC_KAFKA_TOPICS_KEY, TOPIC);
    _properties.setProperty("gobblin.cluster.jobconf.fullyQualifiedPath", _JOBS_DIR_PATH);
    Config config = ConfigUtils.propertiesToConfig(_properties);
    // SEI Producer
    _seip = _closer.register(new SimpleKafkaSpecProducer(config));
    String addedSpecUriString = "/foo/bar/addedSpec";
    Spec spec = initJobSpec(addedSpecUriString);
    WriteResponse writeResponse = (WriteResponse) _seip.addSpec(spec).get();
    log.info("WriteResponse: " + writeResponse);
    _jobCatalog = new NonObservingFSJobCatalog(config.getConfig("gobblin.cluster"));
    _jobCatalog.startAsync().awaitRunning();
    // SEI Consumer
    _seic = _closer.register(new StreamingKafkaSpecConsumer(config, _jobCatalog));
    _seic.startAsync().awaitRunning();
    List<Pair<SpecExecutor.Verb, Spec>> consumedEvent = _seic.changedSpecs().get();
    Assert.assertTrue(consumedEvent.size() == 1, "Consumption did not match production");
    Map.Entry<SpecExecutor.Verb, Spec> consumedSpecAction = consumedEvent.get(0);
    Assert.assertTrue(consumedSpecAction.getKey().equals(SpecExecutor.Verb.ADD), "Verb did not match");
    Assert.assertTrue(consumedSpecAction.getValue().getUri().toString().equals(addedSpecUriString), "Expected URI did not match");
    Assert.assertTrue(consumedSpecAction.getValue() instanceof JobSpec, "Expected JobSpec");
}
Also used : Config(com.typesafe.config.Config) WriteResponse(org.apache.gobblin.writer.WriteResponse) Properties(java.util.Properties) NonObservingFSJobCatalog(org.apache.gobblin.runtime.job_catalog.NonObservingFSJobCatalog) SpecExecutor(org.apache.gobblin.runtime.api.SpecExecutor) JobSpec(org.apache.gobblin.runtime.api.JobSpec) JobSpec(org.apache.gobblin.runtime.api.JobSpec) Spec(org.apache.gobblin.runtime.api.Spec) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Aggregations

Config (com.typesafe.config.Config)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Pair (org.apache.commons.lang3.tuple.Pair)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 Spec (org.apache.gobblin.runtime.api.Spec)1 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)1 NonObservingFSJobCatalog (org.apache.gobblin.runtime.job_catalog.NonObservingFSJobCatalog)1 WriteResponse (org.apache.gobblin.writer.WriteResponse)1 Test (org.testng.annotations.Test)1