|
28 | 28 |
|
29 | 29 |
|
30 | 30 | describe "schemas" do |
31 | | - let(:pubsub) { Google::Cloud::Pubsub.new } |
| 31 | + let(:pubsub) { Google::Cloud::PubSub.new } |
32 | 32 | let(:schema_id) { random_schema_id } |
33 | 33 | let(:topic_id) { random_topic_id } |
34 | 34 | let(:subscription_id) { random_subscription_id } |
35 | 35 | let(:avsc_file) { File.expand_path "data/us-states.avsc", __dir__ } |
| 36 | + let(:topic_admin) { pubsub.topic_admin } |
| 37 | + let(:subscription_admin) { pubsub.subscription_admin } |
| 38 | + let(:schemas) { pubsub.schemas } |
36 | 39 |
|
37 | 40 | after do |
38 | | - @subscription.delete if @subscription |
39 | | - @topic.delete if @topic |
40 | | - @schema.delete if @schema |
| 41 | + subscription_admin.delete_subscription subscription: @subscription.name if @subscription |
| 42 | + topic_admin.delete_topic topic: @topic.name if @topic |
| 43 | + schemas.delete_schema name: @schema.name if @schema |
41 | 44 | end |
42 | 45 |
|
43 | 46 | it "supports pubsub_create_schema, pubsub_get_schema, pubsub_list_schemas, pubsub_delete_schema" do |
44 | 47 | # create_avro_schema |
45 | 48 | assert_output "Schema projects/#{pubsub.project}/schemas/#{schema_id} created.\n" do |
46 | 49 | create_avro_schema schema_id: schema_id, avsc_file: avsc_file |
47 | 50 | end |
48 | | - @schema = pubsub.schema schema_id |
| 51 | + @schema = schemas.get_schema name: pubsub.schema_path(schema_id) |
49 | 52 | assert @schema |
50 | 53 | assert_equal "projects/#{pubsub.project}/schemas/#{schema_id}", @schema.name |
51 | 54 |
|
|
75 | 78 | let(:record) { { "name" => "Alaska", "post_abbr" => "AK" } } |
76 | 79 |
|
77 | 80 | it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with binary encoding" do |
78 | | - @schema = pubsub.create_schema schema_id, :avro, avsc_definition |
| 81 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 82 | + type: :AVRO, |
| 83 | + definition: avsc_definition |
| 84 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 85 | + schema: schema, |
| 86 | + schema_id: schema_id |
| 87 | + |
79 | 88 |
|
80 | 89 | # pubsub_create_topic_with_schema |
81 | 90 | assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do |
82 | | - create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :binary |
| 91 | + create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :BINARY |
83 | 92 | end |
84 | | - @topic = pubsub.topic topic_id |
| 93 | + @topic = topic_admin.get_topic topic: pubsub.topic_path(topic_id) |
85 | 94 | assert @topic |
86 | 95 | assert_equal "projects/#{pubsub.project}/topics/#{topic_id}", @topic.name |
87 | 96 |
|
|
92 | 101 | end |
93 | 102 |
|
94 | 103 | it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with JSON encoding" do |
95 | | - @schema = pubsub.create_schema schema_id, :avro, avsc_definition |
| 104 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 105 | + type: :AVRO, |
| 106 | + definition: avsc_definition |
| 107 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 108 | + schema: schema, |
| 109 | + schema_id: schema_id |
96 | 110 |
|
97 | 111 | # pubsub_create_topic_with_schema |
98 | 112 | assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do |
99 | | - create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :json |
| 113 | + create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :JSON |
100 | 114 | end |
101 | | - @topic = pubsub.topic topic_id |
| 115 | + @topic = topic_admin.get_topic topic: pubsub.topic_path(topic_id) |
102 | 116 | assert @topic |
103 | 117 | assert_equal "projects/#{pubsub.project}/topics/#{topic_id}", @topic.name |
104 | 118 |
|
|
109 | 123 | end |
110 | 124 |
|
111 | 125 | it "supports pubsub_subscribe_avro_records with binary encoding" do |
112 | | - @schema = pubsub.create_schema schema_id, :avro, avsc_definition |
113 | | - @topic = pubsub.create_topic random_topic_id, schema_name: schema_id, message_encoding: :binary |
| 126 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 127 | + type: :AVRO, |
| 128 | + definition: avsc_definition |
| 129 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 130 | + schema: schema, |
| 131 | + schema_id: schema_id |
| 132 | + |
| 133 | + schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id), |
| 134 | + encoding: :BINARY |
| 135 | + |
| 136 | + |
| 137 | + @topic = topic_admin.create_topic name: pubsub.topic_path(random_topic_id), |
| 138 | + schema_settings: schema_settings |
114 | 139 |
|
115 | | - @subscription = @topic.subscribe random_subscription_id |
| 140 | + @subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id), |
| 141 | + topic: @topic.name |
116 | 142 |
|
117 | 143 | writer = Avro::IO::DatumWriter.new avro_schema |
118 | 144 | buffer = StringIO.new |
119 | 145 | writer.write record, Avro::IO::BinaryEncoder.new(buffer) |
120 | | - @topic.publish buffer |
| 146 | + publisher = pubsub.publisher @topic.name |
| 147 | + publisher.publish buffer |
121 | 148 | sleep 5 |
122 | 149 |
|
123 | 150 | # pubsub_subscribe_avro_records |
|
129 | 156 | end |
130 | 157 |
|
131 | 158 | it "supports pubsub_subscribe_avro_records with JSON encoding" do |
132 | | - @schema = pubsub.create_schema schema_id, :avro, avsc_definition |
133 | | - @topic = pubsub.create_topic random_topic_id, schema_name: schema_id, message_encoding: :json |
| 159 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 160 | + type: :AVRO, |
| 161 | + definition: avsc_definition |
| 162 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 163 | + schema: schema, |
| 164 | + schema_id: schema_id |
| 165 | + schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id), |
| 166 | + encoding: :JSON |
134 | 167 |
|
135 | | - @subscription = @topic.subscribe random_subscription_id |
136 | 168 |
|
137 | | - @topic.publish record.to_json |
| 169 | + @topic = topic_admin.create_topic name: pubsub.topic_path(random_topic_id), |
| 170 | + schema_settings: schema_settings |
| 171 | + |
| 172 | + @subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id), |
| 173 | + topic: @topic.name |
| 174 | + |
| 175 | + publisher = pubsub.publisher @topic.name |
| 176 | + publisher.publish record.to_json |
138 | 177 | sleep 5 |
139 | 178 |
|
140 | 179 | # pubsub_subscribe_avro_records |
|
153 | 192 | let(:revision_file) { File.expand_path "data/us-states-revision.proto", __dir__ } |
154 | 193 |
|
155 | 194 | it "supports pubsub_create_topic_with_schema, pubsub_publish_proto_messages with binary encoding" do |
156 | | - @schema = pubsub.create_schema schema_id, :protocol_buffer, proto_definition |
| 195 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 196 | + type: :PROTOCOL_BUFFER, |
| 197 | + definition: proto_definition |
| 198 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 199 | + schema: schema, |
| 200 | + schema_id: schema_id |
157 | 201 |
|
158 | 202 | # pubsub_create_topic_with_schema |
159 | 203 | assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do |
160 | | - create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :binary |
| 204 | + create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :BINARY |
161 | 205 | end |
162 | | - @topic = pubsub.topic topic_id |
| 206 | + |
| 207 | + @topic = topic_admin.get_topic topic: pubsub.topic_path(topic_id) |
163 | 208 | assert @topic |
164 | 209 | assert_equal "projects/#{pubsub.project}/topics/#{topic_id}", @topic.name |
165 | 210 |
|
|
170 | 215 | end |
171 | 216 |
|
172 | 217 | it "supports pubsub_create_topic_with_schema, pubsub_publish_proto_messages with JSON encoding" do |
173 | | - @schema = pubsub.create_schema schema_id, :protocol_buffer, proto_definition |
| 218 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 219 | + type: :PROTOCOL_BUFFER, |
| 220 | + definition: proto_definition |
| 221 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 222 | + schema: schema, |
| 223 | + schema_id: schema_id |
174 | 224 |
|
175 | 225 | # pubsub_create_topic_with_schema |
176 | 226 | assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do |
177 | | - create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :json |
| 227 | + create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :JSON |
178 | 228 | end |
179 | | - @topic = pubsub.topic topic_id |
| 229 | + |
| 230 | + @topic = topic_admin.get_topic topic: pubsub.topic_path(topic_id) |
180 | 231 | assert @topic |
181 | 232 | assert_equal "projects/#{pubsub.project}/topics/#{topic_id}", @topic.name |
182 | 233 |
|
|
187 | 238 | end |
188 | 239 |
|
189 | 240 | it "supports pubsub_subscribe_proto_messages with binary encoding" do |
190 | | - @schema = pubsub.create_schema schema_id, :protocol_buffer, proto_definition |
191 | | - @topic = pubsub.create_topic random_topic_id, schema_name: schema_id, message_encoding: :binary |
| 241 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 242 | + type: :PROTOCOL_BUFFER, |
| 243 | + definition: proto_definition |
| 244 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 245 | + schema: schema, |
| 246 | + schema_id: schema_id |
| 247 | + |
| 248 | + schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id), |
| 249 | + encoding: :BINARY |
| 250 | + |
| 251 | + @topic = topic_admin.create_topic name: pubsub.topic_path(random_topic_id), |
| 252 | + schema_settings: schema_settings |
192 | 253 |
|
193 | | - @subscription = @topic.subscribe random_subscription_id |
| 254 | + @subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id), |
| 255 | + topic: @topic.name |
194 | 256 |
|
195 | 257 | state = Utilities::StateProto.new name: "Alaska", post_abbr: "AK" |
196 | | - @topic.publish Utilities::StateProto.encode(state) |
| 258 | + publisher = pubsub.publisher @topic.name |
| 259 | + publisher.publish Utilities::StateProto.encode(state) |
197 | 260 | sleep 5 |
198 | 261 |
|
199 | 262 | # pubsub_subscribe_proto_messages |
|
205 | 268 | end |
206 | 269 |
|
207 | 270 | it "supports pubsub_subscribe_proto_messages with JSON encoding" do |
208 | | - @schema = pubsub.create_schema schema_id, :protocol_buffer, proto_definition |
209 | | - @topic = pubsub.create_topic random_topic_id, schema_name: schema_id, message_encoding: :json |
| 271 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 272 | + type: :PROTOCOL_BUFFER, |
| 273 | + definition: proto_definition |
| 274 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 275 | + schema: schema, |
| 276 | + schema_id: schema_id |
210 | 277 |
|
211 | | - @subscription = @topic.subscribe random_subscription_id |
| 278 | + schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id), |
| 279 | + encoding: :JSON |
| 280 | + |
| 281 | + @topic = topic_admin.create_topic name: pubsub.topic_path(random_topic_id), |
| 282 | + schema_settings: schema_settings |
| 283 | + |
| 284 | + @subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id), |
| 285 | + topic: @topic.name |
212 | 286 |
|
213 | 287 | state = Utilities::StateProto.new name: "Alaska", post_abbr: "AK" |
214 | | - @topic.publish Utilities::StateProto.encode_json(state) |
| 288 | + publisher = pubsub.publisher @topic.name |
| 289 | + publisher.publish Utilities::StateProto.encode_json(state) |
215 | 290 | sleep 5 |
216 | 291 |
|
217 | 292 | # pubsub_subscribe_proto_messages |
|
223 | 298 | end |
224 | 299 |
|
225 | 300 | it "supports pubsub_commit_proto_schema & pubsub_commit_list_schema_revisions" do |
226 | | - @schema = pubsub.create_schema schema_id, :protocol_buffer, proto_definition |
| 301 | + schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id, |
| 302 | + type: :PROTOCOL_BUFFER, |
| 303 | + definition: proto_definition |
| 304 | + @schema = schemas.create_schema parent: pubsub.project_path, |
| 305 | + schema: schema, |
| 306 | + schema_id: schema_id |
| 307 | + |
227 | 308 | rev_id = @schema.revision_id |
228 | 309 |
|
229 | 310 | # pubsub_commit_proto_schema |
|
0 commit comments