Skip to content

Upgrading pubsub to 0.9.2-alpha, quick start update #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pubsub/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ Install [Maven](http://maven.apache.org/).
Build your project with:

mvn clean package -DskipTests

You can then run a given `ClassName` via:

mvn exec:java -Dexec.mainClass=com.example.pubsub.ClassName \
-DpropertyName=propertyValue \
-Dexec.args="any arguments to the app"
## Testing

To run the tests for this sample, first set the `GOOGLE_CLOUD_PROJECT`
environment variable. The project should have a dataset named `test_dataset`
with a table named `test_table`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right README change? Isn't pubsub organized by topic, rather than dataset/table?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to name changes
If you are going to require something, show them how to create it.

gcloud ...

LGTM otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, copy-paste error


export GOOGLE_CLOUD_PROJECT=my-project
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newlines are your friend between 22-23

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)


Then run the tests with Maven.

mvn clean verify

### Creating a new topic (using the quickstart sample)

Expand Down
2 changes: 1 addition & 1 deletion pubsub/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.8.0</version>
<version>0.9.2-alpha</version>
</dependency>

<!-- Test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016, Google, Inc.
Copyright 2017, Google, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that the copyright year should actually be the date of first publish, and establishes how far back the copyright extends; so it's generally more advantageous for it to be lower.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,23 +18,44 @@

// [START pubsub_quickstart]
// Imports the Google Cloud client library
import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSubOptions;
import com.google.cloud.pubsub.Topic;
import com.google.cloud.pubsub.TopicInfo;

public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
PubSub pubsub = PubSubOptions.getDefaultInstance().getService();
import com.google.api.gax.core.RpcFuture;
import com.google.cloud.pubsub.spi.v1.Publisher;
import com.google.cloud.pubsub.spi.v1.PublisherClient;
import com.google.protobuf.ByteString;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.TopicName;

// The name for the new topic
String topicName = "my-new-topic";
public class QuickstartSample {

// Creates the new topic
Topic topic = pubsub.create(TopicInfo.of(topicName));
public static void main(String... args) throws Exception {

System.out.printf("Topic %s created.%n", topic.getName());
// Create a new topic
String projectId = args[0];
TopicName topic = TopicName.create(projectId, "my-new-topic");
try (PublisherClient publisherClient = PublisherClient.create()) {
publisherClient.createTopic(topic);
}
System.out.printf("Topic %s:%s created.\n", topic.getProject(), topic.getTopic());

// Creates a publisher
Publisher publisher = null;
try {
publisher = Publisher.newBuilder(topic).build();

//Publish a message asynchronously
String message = "my-message";
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
RpcFuture<String> messageIdFuture = publisher.publish(pubsubMessage);

//Print message id of published message
System.out.println("published with message ID: " + messageIdFuture.get());
} finally {
if (publisher != null) {
publisher.shutdown();
}
}
}
}
// [END pubsub_quickstart]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016, Google, Inc.
Copyright 2017, Google, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roll back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,15 +18,17 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.pubsub.PubSub;
import com.google.cloud.pubsub.PubSubOptions;
import com.google.cloud.pubsub.spi.v1.PublisherClient;
import com.google.pubsub.v1.TopicName;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

/**
Expand All @@ -35,34 +37,44 @@
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class QuickstartSampleIT {

private ByteArrayOutputStream bout;
private PrintStream out;
private String projectId;

private static final void deleteTestTopic() {
PubSub pubsub = PubSubOptions.getDefaultInstance().getService();
String topicName = "my-new-topic";
pubsub.deleteTopic(topicName);
private void deleteTestTopic(String projectId) throws Exception {
try (PublisherClient publisherClient = PublisherClient.create()) {
publisherClient.deleteTopic(TopicName.create(projectId, "my-new-topic"));
} catch (IOException e) {
System.err.println("Error deleting topic " + e.getMessage());
}
}

@Before
public void setUp() {
deleteTestTopic();

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
assertThat(projectId).isNotNull();
try {
deleteTestTopic(projectId);
} catch (Exception e) {
//empty catch block
}
}

@After
public void tearDown() {
public void tearDown() throws Exception {
System.setOut(null);
deleteTestTopic();
deleteTestTopic(projectId);
}

@Test
public void testQuickstart() throws Exception {
QuickstartSample.main();
QuickstartSample.main(projectId);
String got = bout.toString();
assertThat(got).contains("Topic my-new-topic created.");
assertThat(got).contains("my-new-topic created.");
assertThat(got).contains("published with message ID");
}
}