Search in sources :

Example 1 with PubSubOutputProperties

use of org.talend.components.pubsub.output.PubSubOutputProperties in project components by Talend.

the class PubSubTestConstants method createOutput.

public static PubSubOutputProperties createOutput(PubSubDatasetProperties dataset) {
    PubSubOutputProperties output = new PubSubOutputProperties("output");
    output.init();
    output.setDatasetProperties(dataset);
    output.topicOperation.setValue(PubSubOutputProperties.TopicOperation.NONE);
    return output;
}
Also used : PubSubOutputProperties(org.talend.components.pubsub.output.PubSubOutputProperties)

Example 2 with PubSubOutputProperties

use of org.talend.components.pubsub.output.PubSubOutputProperties in project components by Talend.

the class PubSubOutputRuntimeTestIT method createTopicSub.

private void createTopicSub(Pipeline pipeline) throws IOException {
    String testID = "createTopicSubTest" + new Random().nextInt();
    final String newTopicName = "tcomp-pubsub-createTopicSub" + uuid;
    final String newSubName = "tcomp-pubsub-createTopicSub-sub" + uuid;
    final String fieldDelimited = ";";
    List<Person> expectedPersons = Person.genRandomList(testID, maxRecords);
    List<String> expectedMessages = new ArrayList<>();
    List<String[]> sendMessages = new ArrayList<>();
    for (Person person : expectedPersons) {
        expectedMessages.add(person.toCSV(fieldDelimited));
        sendMessages.add(person.toCSV(fieldDelimited).split(fieldDelimited));
    }
    PubSubOutputRuntime outputRuntime = new PubSubOutputRuntime();
    PubSubOutputProperties outputProperties = createOutput(addSubscriptionForDataset(createDatasetFromCSV(createDatastore(), newTopicName, fieldDelimited), newSubName));
    outputProperties.topicOperation.setValue(PubSubOutputProperties.TopicOperation.CREATE_IF_NOT_EXISTS);
    outputRuntime.initialize(runtimeContainer, outputProperties);
    PCollection<IndexedRecord> records = (PCollection<IndexedRecord>) pipeline.apply(Create.of(sendMessages)).apply((PTransform) ConvertToIndexedRecord.of());
    records.setCoder(LazyAvroCoder.of()).apply(outputRuntime);
    pipeline.run().waitUntilFinish();
    List<String> actual = new ArrayList<>();
    while (true) {
        List<ReceivedMessage> messages = client.pull(newSubName, maxRecords);
        List<String> ackIds = new ArrayList<>();
        for (ReceivedMessage message : messages) {
            actual.add(new String(message.getMessage().decodeData()));
            ackIds.add(message.getAckId());
        }
        client.ack(newSubName, ackIds);
        if (actual.size() >= maxRecords) {
            break;
        }
    }
    client.deleteSubscription(newSubName);
    client.deleteTopic(newTopicName);
    assertThat(actual, containsInAnyOrder(expectedMessages.toArray()));
}
Also used : ConvertToIndexedRecord(org.talend.components.adapter.beam.transform.ConvertToIndexedRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayList(java.util.ArrayList) ReceivedMessage(com.google.api.services.pubsub.model.ReceivedMessage) PCollection(org.apache.beam.sdk.values.PCollection) PubSubOutputProperties(org.talend.components.pubsub.output.PubSubOutputProperties) Random(java.util.Random) PTransform(org.apache.beam.sdk.transforms.PTransform)

Aggregations

PubSubOutputProperties (org.talend.components.pubsub.output.PubSubOutputProperties)2 ReceivedMessage (com.google.api.services.pubsub.model.ReceivedMessage)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 PTransform (org.apache.beam.sdk.transforms.PTransform)1 PCollection (org.apache.beam.sdk.values.PCollection)1 ConvertToIndexedRecord (org.talend.components.adapter.beam.transform.ConvertToIndexedRecord)1