File tree Expand file tree Collapse file tree 2 files changed +13
-12
lines changed
src/test/java/com/example/pubsub Expand file tree Collapse file tree 2 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,10 @@ For more samples, see the samples in
1515
1616#### Setup
1717- Install [ Maven] ( http://maven.apache.org/ )
18- - Install the [ Google Cloud SDK] ( https://cloud.google.com/sdk/ ) and run :
18+ - Install the [ Google Cloud SDK] ( https://cloud.google.com/sdk/ ) and authenticate :
1919```
2020 gcloud config set project [YOUR PROJECT ID]
21+ gcloud auth application-default login
2122```
2223- [ Enable] ( https://console.cloud.google.com/apis/api/pubsub.googleapis.com/overview ) Pub/Sub API
2324- Build your project with:
@@ -30,16 +31,16 @@ For more samples, see the samples in
3031 mvn exec:java -Dexec.mainClass=com.example.pubsub.CreateTopicExample -Dexec.args=my-topic-id
3132```
3233
33- #### Publish messages
34+ #### Create a subscription
3435```
35- mvn exec:java -Dexec.mainClass=com.example.pubsub.PublisherExample -Dexec.args=my-topic-id
36+ mvn exec:java -Dexec.mainClass=com.example.pubsub.CreatePullSubscriptionExample -Dexec.args=" my-topic-id my-subscription-id"
3637```
37- Publishes 10 messages to the topic ` my-topic-id ` .
3838
39- #### Create a subscription
39+ #### Publish messages
4040```
41- mvn exec:java -Dexec.mainClass=com.example.pubsub.CreatePullSubscriptionExample -Dexec.args=" my-topic-id my-subscription-id"
41+ mvn exec:java -Dexec.mainClass=com.example.pubsub.PublisherExample -Dexec.args=my-topic-id
4242```
43+ Publishes 5 messages to the topic ` my-topic-id ` .
4344
4445#### Receive messages
4546```
Original file line number Diff line number Diff line change @@ -72,20 +72,20 @@ public void tearDown() throws Exception {
7272
7373 @ Test
7474 public void testQuickstart () throws Exception {
75- //create a topic
75+ // create a topic
7676 CreateTopicExample .main (topicId );
7777 String got = bout .toString ();
7878 assertThat (got ).contains (topicId + " created." );
7979
80- // publish messages
81- List <String > published = PublisherExample .publishMessages (topicId );
82- assertThat (published ).hasSize (5 );
83-
8480 // create a subscriber
8581 CreatePullSubscriptionExample .main (topicId , subscriptionId );
8682 got = bout .toString ();
8783 assertThat (got ).contains (subscriptionId + " created." );
8884
85+ // publish messages
86+ List <String > published = PublisherExample .publishMessages (topicId );
87+ assertThat (published ).hasSize (5 );
88+
8989 SubscriberExample subscriberExample = new SubscriberExample (subscriptionId );
9090 // receive messages
9191 Thread subscriberThread = new Thread (subscriberExample );
@@ -95,9 +95,9 @@ public void testQuickstart() throws Exception {
9595 while ((received = subscriberExample .getReceivedMessages ()).size () < 5 ) {
9696 Thread .sleep (1000 );
9797 }
98+
9899 assertThat (received ).containsAllIn (published );
99100 subscriberExample .stopSubscriber ();
100- subscriberThread .join ();
101101 }
102102
103103 private String formatForTest (String name ) {
You can’t perform that action at this time.
0 commit comments