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;
}
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()));
}
Aggregations