File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
container-registry/container-analysis/src/test/java/com/example/containeranalysis Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 23
23
import com .google .cloud .devtools .containeranalysis .v1 .ContainerAnalysisClient ;
24
24
import com .google .cloud .pubsub .v1 .Subscriber ;
25
25
import com .google .cloud .pubsub .v1 .SubscriptionAdminClient ;
26
+ import com .google .cloud .pubsub .v1 .TopicAdminClient ;
26
27
import com .google .pubsub .v1 .ProjectSubscriptionName ;
28
+ import com .google .pubsub .v1 .ProjectTopicName ;
27
29
import io .grafeas .v1 .DiscoveryNote ;
28
30
import io .grafeas .v1 .DiscoveryOccurrence ;
29
31
import io .grafeas .v1 .DiscoveryOccurrence .AnalysisStatus ;
@@ -202,6 +204,14 @@ public void testOccurrencesForNote() throws Exception {
202
204
public void testPubSub () throws Exception {
203
205
int newCount ;
204
206
int tries ;
207
+ // create new topic and subscription if needed
208
+ try (TopicAdminClient topicAdminClient = TopicAdminClient .create ()) {
209
+ String topicId = "container-analysis-occurrences-v1" ;
210
+ ProjectTopicName topicName = ProjectTopicName .of (PROJECT_ID , topicId );
211
+ topicAdminClient .createTopic (topicName );
212
+ } catch (StatusRuntimeException e ) {
213
+ System .out .println ("Topic already exists" );
214
+ }
205
215
ProjectSubscriptionName subName = ProjectSubscriptionName .of (PROJECT_ID , subId );
206
216
try {
207
217
Subscriptions .createOccurrenceSubscription (subId , PROJECT_ID );
You can’t perform that action at this time.
0 commit comments