|
109 | 109 | let(:avro_schema) { Avro::Schema.parse avsc_definition } |
110 | 110 | let(:record) { { "name" => "Alaska", "post_abbr" => "AK" } } |
111 | 111 |
|
112 | | - it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with binary encoding" do |
| 112 | + before do |
113 | 113 | schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
114 | 114 | type: :AVRO, |
115 | 115 | definition: avsc_definition |
116 | 116 | @schema = schemas.create_schema parent: pubsub.project_path, |
117 | 117 | schema: schema, |
118 | 118 | schema_id: schema_id |
| 119 | + end |
119 | 120 |
|
120 | | - |
| 121 | + it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with binary encoding" do |
121 | 122 | # pubsub_create_topic_with_schema |
122 | 123 | assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do |
123 | 124 | create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :BINARY |
|
133 | 134 | end |
134 | 135 |
|
135 | 136 | it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with JSON encoding" do |
136 | | - schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
137 | | - type: :AVRO, |
138 | | - definition: avsc_definition |
139 | | - @schema = schemas.create_schema parent: pubsub.project_path, |
140 | | - schema: schema, |
141 | | - schema_id: schema_id |
142 | | - |
143 | 137 | # pubsub_create_topic_with_schema |
144 | 138 | assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do |
145 | 139 | create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :JSON |
|
155 | 149 | end |
156 | 150 |
|
157 | 151 | it "supports pubsub_subscribe_avro_records with binary encoding" do |
158 | | - schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
159 | | - type: :AVRO, |
160 | | - definition: avsc_definition |
161 | | - @schema = schemas.create_schema parent: pubsub.project_path, |
162 | | - schema: schema, |
163 | | - schema_id: schema_id |
164 | | - |
165 | 152 | schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id), |
166 | 153 | encoding: :BINARY |
167 | 154 |
|
|
170 | 157 | schema_settings: schema_settings |
171 | 158 |
|
172 | 159 | @subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id), |
173 | | - topic: @topic.name |
| 160 | + topic: @topic.name, |
| 161 | + ack_deadline_seconds: 60 |
174 | 162 |
|
175 | 163 | writer = Avro::IO::DatumWriter.new avro_schema |
176 | 164 | buffer = StringIO.new |
177 | 165 | writer.write record, Avro::IO::BinaryEncoder.new(buffer) |
178 | 166 | publisher = pubsub.publisher @topic.name |
179 | 167 | publisher.publish buffer |
180 | | - sleep 5 |
181 | 168 |
|
182 | 169 | # pubsub_subscribe_avro_records |
183 | 170 | expect_with_retry "pubsub_subscribe_avro_records" do |
184 | | - assert_output "Received a binary-encoded message:\n{\"name\"=>\"Alaska\", \"post_abbr\"=>\"AK\"}\n" do |
| 171 | + assert_output "Received a binary-encoded message:\n{\"name\" => \"Alaska\", \"post_abbr\" => \"AK\"}\n" do |
185 | 172 | subscribe_avro_records subscription_id: @subscription.name, avsc_file: avsc_file |
186 | 173 | end |
187 | 174 | end |
188 | 175 | end |
189 | 176 |
|
190 | 177 | it "supports pubsub_subscribe_avro_records with JSON encoding" do |
191 | | - schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
192 | | - type: :AVRO, |
193 | | - definition: avsc_definition |
194 | | - @schema = schemas.create_schema parent: pubsub.project_path, |
195 | | - schema: schema, |
196 | | - schema_id: schema_id |
197 | 178 | schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id), |
198 | 179 | encoding: :JSON |
199 | 180 |
|
|
202 | 183 | schema_settings: schema_settings |
203 | 184 |
|
204 | 185 | @subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id), |
205 | | - topic: @topic.name |
| 186 | + topic: @topic.name, |
| 187 | + ack_deadline_seconds: 60 |
206 | 188 |
|
207 | 189 | publisher = pubsub.publisher @topic.name |
208 | 190 | publisher.publish record.to_json |
209 | | - sleep 5 |
210 | 191 |
|
211 | 192 | # pubsub_subscribe_avro_records |
212 | 193 | expect_with_retry "pubsub_subscribe_avro_records" do |
213 | | - assert_output "Received a JSON-encoded message:\n{\"name\"=>\"Alaska\", \"post_abbr\"=>\"AK\"}\n" do |
| 194 | + assert_output "Received a JSON-encoded message:\n{\"name\" => \"Alaska\", \"post_abbr\" => \"AK\"}\n" do |
214 | 195 | subscribe_avro_records subscription_id: @subscription.name, avsc_file: nil |
215 | 196 | end |
216 | 197 | end |
217 | 198 | end |
218 | 199 |
|
219 | 200 | it "supports pubsub_commit_avro_schema & pubsub_commit_list_schema_revisions" do |
220 | | - schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
221 | | - type: :AVRO, |
222 | | - definition: avsc_definition |
223 | | - @schema = schemas.create_schema parent: pubsub.project_path, |
224 | | - schema: schema, |
225 | | - schema_id: schema_id |
226 | | - |
| 201 | + |
227 | 202 | rev_id = @schema.revision_id |
228 | 203 |
|
229 | 204 | schema1 = nil |
|
0 commit comments