@@ -107,6 +107,11 @@ private static class State {
107
107
*/
108
108
@ Nullable
109
109
Map <String , Long > ackDeadline ;
110
+
111
+ /**
112
+ * Whether a subscription has been created.
113
+ */
114
+ boolean createdSubscription ;
110
115
}
111
116
112
117
private static final State STATE = new State ();
@@ -124,12 +129,40 @@ public static PubsubTestClientFactory createFactoryForPublish(
124
129
final TopicPath expectedTopic ,
125
130
final Iterable <OutgoingMessage > expectedOutgoingMessages ,
126
131
final Iterable <OutgoingMessage > failingOutgoingMessages ) {
132
+ return createFactoryForPublishInternal (
133
+ expectedTopic , expectedOutgoingMessages , failingOutgoingMessages , false );
134
+ }
135
+
136
+ /**
137
+ * Return a factory for testing publishers. Only one factory may be in-flight at a time.
138
+ * The factory must be closed when the test is complete, at which point final validation will
139
+ * occur. Additionally, verify that createSubscription was called.
140
+ */
141
+ public static PubsubTestClientFactory createFactoryForPublishVerifySubscription (
142
+ final TopicPath expectedTopic ,
143
+ final Iterable <OutgoingMessage > expectedOutgoingMessages ,
144
+ final Iterable <OutgoingMessage > failingOutgoingMessages ) {
145
+ return createFactoryForPublishInternal (
146
+ expectedTopic , expectedOutgoingMessages , failingOutgoingMessages , true );
147
+ }
148
+
149
+ /**
150
+ * Return a factory for testing publishers. Only one factory may be in-flight at a time.
151
+ * The factory must be closed when the test is complete, at which point final validation will
152
+ * occur.
153
+ */
154
+ public static PubsubTestClientFactory createFactoryForPublishInternal (
155
+ final TopicPath expectedTopic ,
156
+ final Iterable <OutgoingMessage > expectedOutgoingMessages ,
157
+ final Iterable <OutgoingMessage > failingOutgoingMessages ,
158
+ final boolean verifySubscriptionCreated ) {
127
159
synchronized (STATE ) {
128
160
checkState (!STATE .isActive , "Test still in flight" );
129
161
STATE .expectedTopic = expectedTopic ;
130
162
STATE .remainingExpectedOutgoingMessages = Sets .newHashSet (expectedOutgoingMessages );
131
163
STATE .remainingFailingOutgoingMessages = Sets .newHashSet (failingOutgoingMessages );
132
164
STATE .isActive = true ;
165
+ STATE .createdSubscription = false ;
133
166
}
134
167
return new PubsubTestClientFactory () {
135
168
@ Override
@@ -148,6 +181,9 @@ public String getKind() {
148
181
@ Override
149
182
public void close () {
150
183
synchronized (STATE ) {
184
+ if (verifySubscriptionCreated ) {
185
+ checkState (STATE .createdSubscription , "Did not call create subscription" );
186
+ }
151
187
checkState (STATE .isActive , "No test still in flight" );
152
188
checkState (STATE .remainingExpectedOutgoingMessages .isEmpty (),
153
189
"Still waiting for %s messages to be published" ,
@@ -372,7 +408,10 @@ public List<TopicPath> listTopics(ProjectPath project) throws IOException {
372
408
@ Override
373
409
public void createSubscription (
374
410
TopicPath topic , SubscriptionPath subscription , int ackDeadlineSeconds ) throws IOException {
375
- throw new UnsupportedOperationException ();
411
+ synchronized (STATE ) {
412
+ STATE .createdSubscription = true ;
413
+ }
414
+ return ;
376
415
}
377
416
378
417
@ Override
0 commit comments