Skip to content

Commit 654d1b5

Browse files
authored
Merge branch 'master' into dpebot-repositorygardener
2 parents 5723331 + f673572 commit 654d1b5

7 files changed

Lines changed: 171 additions & 157 deletions

File tree

container-registry/container-analysis/src/main/java/com/example/containeranalysis/Samples.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static void deleteOccurrence(String occurrenceName) throws Exception {
161161

162162
// [START get_occurrence]
163163
/**
164-
* Retrieves an occurrence based on it's name
164+
* Retrieves an occurrence based on its name
165165
*
166166
* @param occurrenceName the name of the occurrence to delete
167167
* format: "projects/{projectId}/occurrences/{occurrence_id}"
@@ -177,7 +177,7 @@ public static Occurrence getOccurrence(String occurrenceName) throws Exception
177177

178178
// [START get_note]
179179
/**
180-
* Retrieves a note based on it's noteId and projectId
180+
* Retrieves a note based on its noteId and projectId
181181
*
182182
* @param noteId the note's unique identifier
183183
* @param projectId the project's unique identifier
@@ -280,22 +280,22 @@ public static int getOccurrencesForImage(String imageUrl, String projectId) thro
280280
// [START pubsub]
281281
/**
282282
* Handle incoming occurrences using a pubsub subscription
283-
* @param subscriptionId the user-specified identifier for the pubsub subscription
283+
* @param subId the user-specified identifier for the pubsub subscription
284284
* @param timeout the amount of time to listen for pubsub messages (in seconds)
285285
* @param projectId the project's unique identifier
286286
* @return number of occurrence pubsub messages received
287287
* @throws Exception on errors with the subscription client
288288
*/
289-
public static int pubSub(String subscriptionId, int timeout, String projectId) throws Exception {
289+
public static int pubSub(String subId, int timeout, String projectId) throws Exception {
290290
Subscriber subscriber = null;
291291
MessageReceiverExample receiver = new MessageReceiverExample();
292292

293293
try {
294294
// subscribe to the requested pubsub channel
295-
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
296-
subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
295+
ProjectSubscriptionName subName = ProjectSubscriptionName.of(projectId, subId);
296+
subscriber = Subscriber.newBuilder(subName, receiver).build();
297297
subscriber.startAsync().awaitRunning();
298-
// listen to messages for 'listenTimeout' seconds
298+
// listen to messages for 'timeout' seconds
299299
for (int i = 0; i < timeout; i++) {
300300
sleep(1000);
301301
}
@@ -330,20 +330,20 @@ public synchronized void receiveMessage(PubsubMessage message, AckReplyConsumer
330330

331331
/**
332332
* Creates and returns a pubsub subscription object listening to the occurrence topic
333-
* @param subscriptionId the identifier you want to associate with the subscription
333+
* @param subId the identifier you want to associate with the subscription
334334
* @param projectId the project's unique identifier
335335
* @throws Exception on errors with the subscription client
336336
*/
337-
public static Subscription createOccurrenceSubscription(String subscriptionId, String projectId)
337+
public static Subscription createOccurrenceSubscription(String subId, String projectId)
338338
throws Exception {
339339
String topicId = "resource-notes-occurrences-v1alpha1";
340340
try (SubscriptionAdminClient client = SubscriptionAdminClient.create()) {
341341
PushConfig config = PushConfig.getDefaultInstance();
342342
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
343-
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
344-
Subscription sub = client.createSubscription(subscriptionName, topicName, config, 0);
343+
ProjectSubscriptionName subName = ProjectSubscriptionName.of(projectId, subId);
344+
Subscription sub = client.createSubscription(subName, topicName, config, 0);
345345
return sub;
346346
}
347347
}
348348
// [END pubsub]
349-
}
349+
}

container-registry/container-analysis/src/test/java/com/example/containeranalysis/SamplesTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Date;
3030
import org.junit.After;
3131
import org.junit.Before;
32+
import org.junit.Ignore;
3233
import org.junit.Rule;
3334
import org.junit.Test;
3435
import org.junit.rules.TestName;
@@ -40,6 +41,7 @@
4041
*/
4142
@RunWith(JUnit4.class)
4243
@SuppressWarnings("checkstyle:abbreviationaswordinname")
44+
@Ignore
4345
public class SamplesTests {
4446

4547
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
@@ -164,6 +166,7 @@ public void testOccurrencesForImage() throws Exception {
164166
do {
165167
newCount = Samples.getOccurrencesForImage(imageUrl, PROJECT_ID);
166168
sleep(SLEEP_TIME);
169+
tries += 1;
167170
} while (newCount != 1 && tries < TRY_LIMIT);
168171
assertEquals(1, newCount);
169172
assertEquals(0, origCount);
@@ -181,6 +184,7 @@ public void testOccurrencesForNote() throws Exception {
181184
do {
182185
newCount = Samples.getOccurrencesForNote(noteId, PROJECT_ID);
183186
sleep(SLEEP_TIME);
187+
tries += 1;
184188
} while (newCount != 1 && tries < TRY_LIMIT);
185189
assertEquals(0, origCount);
186190
assertEquals(1, newCount);
@@ -193,14 +197,14 @@ public void testOccurrencesForNote() throws Exception {
193197
public void testPubSub() throws Exception {
194198
int newCount;
195199
int tries;
196-
String subscriptionId = "drydockOccurrences";
197-
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(PROJECT_ID, subscriptionId);
200+
String subId = "drydockOccurrences";
201+
ProjectSubscriptionName subName = ProjectSubscriptionName.of(PROJECT_ID, subId);
198202

199-
Samples.createOccurrenceSubscription(subscriptionId, PROJECT_ID);
203+
Samples.createOccurrenceSubscription(subId, PROJECT_ID);
200204
Subscriber subscriber = null;
201205
Samples.MessageReceiverExample receiver = new Samples.MessageReceiverExample();
202206
try {
203-
subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
207+
subscriber = Subscriber.newBuilder(subName, receiver).build();
204208
subscriber.startAsync().awaitRunning();
205209
// sleep so any messages in the queue can go through and be counted before we start the test
206210
sleep(SLEEP_TIME);
@@ -229,7 +233,7 @@ public void testPubSub() throws Exception {
229233
}
230234
//delete subscription now that we're done with it
231235
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
232-
subscriptionAdminClient.deleteSubscription(subscriptionName);
236+
subscriptionAdminClient.deleteSubscription(subName);
233237
}
234238
}
235239

datastore/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
</dependencies>
5858
<build>
5959
<plugins>
60-
<!-- // [START maven]-->
60+
<!-- // [START datastore_maven]-->
6161

62-
<!-- // [END maven]-->
63-
<!-- // [START exec] -->
62+
<!-- // [END datastore_maven]-->
63+
<!-- // [START datastore_exec] -->
6464
<plugin>
6565
<groupId>org.codehaus.mojo</groupId>
6666
<artifactId>exec-maven-plugin</artifactId>
@@ -69,7 +69,7 @@
6969
<mainClass>com.google.datastore.snippets.TaskList</mainClass>
7070
</configuration>
7171
</plugin>
72-
<!-- // [END exec] -->
72+
<!-- // [END datastore_exec] -->
7373
</plugins>
7474
</build>
7575
</project>

datastore/src/main/java/com/google/datastore/snippets/TaskList.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
*/
3737
public class TaskList {
3838

39-
// [START build_service]
39+
// [START datastore_build_service]
4040
// Create an authorized Datastore service using Application Default Credentials.
4141
private final Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
4242

4343
// Create a Key factory to construct keys associated with this project.
4444
private final KeyFactory keyFactory = datastore.newKeyFactory().setKind("Task");
45-
// [END build_service]
45+
// [END datastore_build_service]
4646

47-
// [START add_entity]
47+
// [START datastore_add_entity]
4848
/**
4949
* Adds a task entity to the Datastore.
5050
*
@@ -62,9 +62,9 @@ Key addTask(String description) {
6262
datastore.put(task);
6363
return key;
6464
}
65-
// [END add_entity]
65+
// [END datastore_add_entity]
6666

67-
// [START update_entity]
67+
// [START datastore_update_entity]
6868
/**
6969
* Marks a task entity as done.
7070
*
@@ -87,9 +87,9 @@ boolean markDone(long id) {
8787
}
8888
}
8989
}
90-
// [END update_entity]
90+
// [END datastore_update_entity]
9191

92-
// [START retrieve_entities]
92+
// [START datastore_retrieve_entities]
9393
/**
9494
* Returns a list of all task entities in ascending order of creation time.
9595
*
@@ -100,9 +100,9 @@ Iterator<Entity> listTasks() {
100100
Query.newEntityQueryBuilder().setKind("Task").setOrderBy(OrderBy.asc("created")).build();
101101
return datastore.run(query);
102102
}
103-
// [END retrieve_entities]
103+
// [END datastore_retrieve_entities]
104104

105-
// [START delete_entity]
105+
// [START datastore_delete_entity]
106106
/**
107107
* Deletes a task entity.
108108
*
@@ -112,9 +112,9 @@ Iterator<Entity> listTasks() {
112112
void deleteTask(long id) {
113113
datastore.delete(keyFactory.newKey(id));
114114
}
115-
// [END delete_entity]
115+
// [END datastore_delete_entity]
116116

117-
// [START format_results]
117+
// [START datastore_format_results]
118118
/**
119119
* Converts a list of task entities to a list of formatted task strings.
120120
*
@@ -135,7 +135,7 @@ static List<String> formatTasks(Iterator<Entity> tasks) {
135135
}
136136
return strings;
137137
}
138-
// [END format_results]
138+
// [END datastore_format_results]
139139

140140
/**
141141
* Handles a single command.

0 commit comments

Comments
 (0)