Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions acceptance/data/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ def items_ddl_statement
ITEMS
end

# Not part of schema_ddl_statements: queues need an Enterprise edition
# instance, and the emulator doesn't support them yet.
def queue_ddl_statement
<<~QUEUE
CREATE QUEUE IF NOT EXISTS TestQueue (
Id INT64 NOT NULL,
Payload BYTES(MAX) NOT NULL
) PRIMARY KEY (Id)
QUEUE
end

def schema_pg_ddl_statements
[
stuff_pg_ddl_statement,
Expand Down
59 changes: 59 additions & 0 deletions google-cloud-spanner/acceptance/spanner/client/queues_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "spanner_helper"

# An ack without ignore_not_found fails with NOT_FOUND unless the message
# exists, so a successful ack also shows that the send landed.
describe "Spanner Client Queues", :queues, :spanner do
let(:db) { spanner_client }

before do
skip "Cloud Spanner Emulator does not yet support Queues (Send & Ack)" if emulator_enabled?

# Created once per run, in the per-run test database.
$spanner_test_queue_created ||= begin
db_job = db.database.update statements: [queue_ddl_statement]
db_job.wait_until_done!
raise GRPC::BadStatus.new(db_job.error.code, db_job.error.message) if db_job.error?
true
end
end

it "sends and acks messages with Client#commit" do
commit_time = db.commit do |c|
c.send_message "TestQueue", 1, StringIO.new("payload1")
c.send_message "TestQueue", 2, StringIO.new("payload2")
end
_(commit_time).must_be_kind_of Time

commit_time = db.commit do |c|
c.ack_message "TestQueue", 1
c.ack_message "TestQueue", 2
end
_(commit_time).must_be_kind_of Time
end

it "sends and acks a message with Client#transaction" do
commit_time = db.transaction do |tx|
tx.send_message "TestQueue", 3, StringIO.new("payload3")
end
_(commit_time).must_be_kind_of Time

commit_time = db.transaction do |tx|
tx.ack_message "TestQueue", 3
end
_(commit_time).must_be_kind_of Time
end
end
Loading