Search in sources :

Example 1 with WriteResponse

use of org.apache.gobblin.writer.WriteResponse in project incubator-gobblin by apache.

the class Kafka09DataWriterTest method testStringSerialization.

@Test
public void testStringSerialization() throws IOException, InterruptedException, ExecutionException {
    String topic = "testStringSerialization08";
    _kafkaTestHelper.provisionTopic(topic);
    Properties props = new Properties();
    props.setProperty(KafkaWriterConfigurationKeys.KAFKA_TOPIC, topic);
    props.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX + "bootstrap.servers", "localhost:" + _kafkaTestHelper.getKafkaServerPort());
    props.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX + "value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    Kafka09DataWriter<String> kafka09DataWriter = new Kafka09DataWriter<String>(props);
    String messageString = "foobar";
    WriteCallback callback = mock(WriteCallback.class);
    Future<WriteResponse> future;
    try {
        future = kafka09DataWriter.write(messageString, callback);
        kafka09DataWriter.flush();
        verify(callback, times(1)).onSuccess(isA(WriteResponse.class));
        verify(callback, never()).onFailure(isA(Exception.class));
        Assert.assertTrue(future.isDone(), "Future should be done");
        System.out.println(future.get().getStringResponse());
        byte[] message = _kafkaTestHelper.getIteratorForTopic(topic).next().message();
        String messageReceived = new String(message);
        Assert.assertEquals(messageReceived, messageString);
    } finally {
        kafka09DataWriter.close();
    }
}
Also used : WriteResponse(org.apache.gobblin.writer.WriteResponse) WriteCallback(org.apache.gobblin.writer.WriteCallback) Properties(java.util.Properties) SchemaRegistryException(org.apache.gobblin.kafka.schemareg.SchemaRegistryException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 2 with WriteResponse

use of org.apache.gobblin.writer.WriteResponse 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)

Example 3 with WriteResponse

use of org.apache.gobblin.writer.WriteResponse in project incubator-gobblin by apache.

the class StreamingKafkaSpecExecutorTest method testDeleteSpec.

@Test(dependsOnMethods = "testUpdateSpec")
public void testDeleteSpec() throws Exception {
    // delete needs to be on a job spec that exists to get notification
    String deletedSpecUriString = "/foo/bar/addedSpec";
    WriteResponse writeResponse = (WriteResponse) _seip.deleteSpec(new URI(deletedSpecUriString)).get();
    log.info("WriteResponse: " + writeResponse);
    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.DELETE), "Verb did not match");
    Assert.assertTrue(consumedSpecAction.getValue().getUri().toString().equals(deletedSpecUriString), "Expected URI did not match");
    Assert.assertTrue(consumedSpecAction.getValue() instanceof JobSpec, "Expected JobSpec");
}
Also used : WriteResponse(org.apache.gobblin.writer.WriteResponse) 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) URI(java.net.URI) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Example 4 with WriteResponse

use of org.apache.gobblin.writer.WriteResponse in project incubator-gobblin by apache.

the class SimpleKafkaSpecExecutorTest method testDeleteSpec.

@Test(dependsOnMethods = "testUpdateSpec")
public void testDeleteSpec() throws Exception {
    String deletedSpecUriString = "/foo/bar/deletedSpec";
    WriteResponse writeResponse = (WriteResponse) _seip.deleteSpec(new URI(deletedSpecUriString)).get();
    log.info("WriteResponse: " + writeResponse);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    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.DELETE), "Verb did not match");
    Assert.assertTrue(consumedSpecAction.getValue().getUri().toString().equals(deletedSpecUriString), "Expected URI did not match");
    Assert.assertTrue(consumedSpecAction.getValue() instanceof JobSpec, "Expected JobSpec");
}
Also used : WriteResponse(org.apache.gobblin.writer.WriteResponse) 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) URI(java.net.URI) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Example 5 with WriteResponse

use of org.apache.gobblin.writer.WriteResponse in project incubator-gobblin by apache.

the class SimpleKafkaSpecExecutorTest method testUpdateSpec.

@Test(dependsOnMethods = "testAddSpec")
public void testUpdateSpec() throws Exception {
    String updatedSpecUriString = "/foo/bar/updatedSpec";
    Spec spec = initJobSpec(updatedSpecUriString);
    WriteResponse writeResponse = (WriteResponse) _seip.updateSpec(spec).get();
    log.info("WriteResponse: " + writeResponse);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    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.UPDATE), "Verb did not match");
    Assert.assertTrue(consumedSpecAction.getValue().getUri().toString().equals(updatedSpecUriString), "Expected URI did not match");
    Assert.assertTrue(consumedSpecAction.getValue() instanceof JobSpec, "Expected JobSpec");
}
Also used : WriteResponse(org.apache.gobblin.writer.WriteResponse) 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

WriteResponse (org.apache.gobblin.writer.WriteResponse)9 Test (org.testng.annotations.Test)8 Map (java.util.Map)6 Pair (org.apache.commons.lang3.tuple.Pair)6 JobSpec (org.apache.gobblin.runtime.api.JobSpec)6 Spec (org.apache.gobblin.runtime.api.Spec)6 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)6 Properties (java.util.Properties)4 IOException (java.io.IOException)2 URI (java.net.URI)2 WriteCallback (org.apache.gobblin.writer.WriteCallback)2 Config (com.typesafe.config.Config)1 LinkedList (java.util.LinkedList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Pair (org.apache.commons.math3.util.Pair)1