diff options
Diffstat (limited to 'src/arrow/c_glib/test/flight')
-rw-r--r-- | src/arrow/c_glib/test/flight/test-client.rb | 64 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-command-descriptor.rb | 52 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-criteria.rb | 29 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-endpoint.rb | 67 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-info.rb | 78 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-location.rb | 40 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-path-descriptor.rb | 52 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-server-options.rb | 28 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-stream-reader.rb | 69 | ||||
-rw-r--r-- | src/arrow/c_glib/test/flight/test-ticket.rb | 47 |
10 files changed, 526 insertions, 0 deletions
diff --git a/src/arrow/c_glib/test/flight/test-client.rb b/src/arrow/c_glib/test/flight/test-client.rb new file mode 100644 index 000000000..f6660a4ca --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-client.rb @@ -0,0 +1,64 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightClient < Test::Unit::TestCase + include Helper::Omittable + + def setup + @server = nil + omit("Arrow Flight is required") unless defined?(ArrowFlight) + omit("Unstable on Windows") if Gem.win_platform? + require_gi_bindings(3, 4, 7) + @server = Helper::FlightServer.new + host = "127.0.0.1" + location = ArrowFlight::Location.new("grpc://#{host}:0") + options = ArrowFlight::ServerOptions.new(location) + @server.listen(options) + @location = ArrowFlight::Location.new("grpc://#{host}:#{@server.port}") + end + + def teardown + return if @server.nil? + @server.shutdown + end + + def test_list_flights + client = ArrowFlight::Client.new(@location) + generator = Helper::FlightInfoGenerator.new + assert_equal([generator.page_view], + client.list_flights) + end + + sub_test_case("#do_get") do + def test_success + client = ArrowFlight::Client.new(@location) + info = client.list_flights.first + endpoint = info.endpoints.first + generator = Helper::FlightInfoGenerator.new + reader = client.do_get(endpoint.ticket) + assert_equal(generator.page_view_table, + reader.read_all) + end + + def test_error + client = ArrowFlight::Client.new(@location) + assert_raise(Arrow::Error::Invalid) do + client.do_get(ArrowFlight::Ticket.new("invalid")) + end + end + end +end diff --git a/src/arrow/c_glib/test/flight/test-command-descriptor.rb b/src/arrow/c_glib/test/flight/test-command-descriptor.rb new file mode 100644 index 000000000..316973287 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-command-descriptor.rb @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightCommandDescriptor < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_to_s + descriptor = ArrowFlight::CommandDescriptor.new("command") + assert_equal("FlightDescriptor<cmd = 'command'>", + descriptor.to_s) + end + + def test_command + command = "command" + descriptor = ArrowFlight::CommandDescriptor.new(command) + assert_equal(command, descriptor.command) + end + + sub_test_case("#==") do + def test_true + descriptor1 = ArrowFlight::CommandDescriptor.new("command") + descriptor2 = ArrowFlight::CommandDescriptor.new("command") + assert do + descriptor1 == descriptor2 + end + end + + def test_false + descriptor1 = ArrowFlight::CommandDescriptor.new("command1") + descriptor2 = ArrowFlight::CommandDescriptor.new("command2") + assert do + not (descriptor1 == descriptor2) + end + end + end +end diff --git a/src/arrow/c_glib/test/flight/test-criteria.rb b/src/arrow/c_glib/test/flight/test-criteria.rb new file mode 100644 index 000000000..d5f60a895 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-criteria.rb @@ -0,0 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightCriteria < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_expression + expression = "expression" + criteria = ArrowFlight::Criteria.new(expression) + assert_equal(expression, + criteria.expression.to_s) + end +end diff --git a/src/arrow/c_glib/test/flight/test-endpoint.rb b/src/arrow/c_glib/test/flight/test-endpoint.rb new file mode 100644 index 000000000..06cddf001 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-endpoint.rb @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightEndpoint < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_ticket + ticket = ArrowFlight::Ticket.new("data") + locations = [ + ArrowFlight::Location.new("grpc://127.0.0.1:2929"), + ArrowFlight::Location.new("grpc+tcp://127.0.0.1:12929"), + ] + endpoint = ArrowFlight::Endpoint.new(ticket, locations) + assert_equal(ticket, + endpoint.ticket) + end + + def test_locations + ticket = ArrowFlight::Ticket.new("data") + locations = [ + ArrowFlight::Location.new("grpc://127.0.0.1:2929"), + ArrowFlight::Location.new("grpc+tcp://127.0.0.1:12929"), + ] + endpoint = ArrowFlight::Endpoint.new(ticket, locations) + assert_equal(locations, + endpoint.locations) + end + + sub_test_case("#==") do + def test_true + ticket = ArrowFlight::Ticket.new("data") + location = ArrowFlight::Location.new("grpc://127.0.0.1:2929") + endpoint1 = ArrowFlight::Endpoint.new(ticket, [location]) + endpoint2 = ArrowFlight::Endpoint.new(ticket, [location]) + assert do + endpoint1 == endpoint2 + end + end + + def test_false + ticket = ArrowFlight::Ticket.new("data") + location1 = ArrowFlight::Location.new("grpc://127.0.0.1:2929") + location2 = ArrowFlight::Location.new("grpc://127.0.0.1:1129") + endpoint1 = ArrowFlight::Endpoint.new(ticket, [location1]) + endpoint2 = ArrowFlight::Endpoint.new(ticket, [location2]) + assert do + not (endpoint1 == endpoint2) + end + end + end +end diff --git a/src/arrow/c_glib/test/flight/test-info.rb b/src/arrow/c_glib/test/flight/test-info.rb new file mode 100644 index 000000000..5bf0fbfad --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-info.rb @@ -0,0 +1,78 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightInfo < Test::Unit::TestCase + include Helper::Writable + + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + @generator = Helper::FlightInfoGenerator.new + end + + sub_test_case("#get_schema") do + def test_with_options + info = @generator.page_view + table = @generator.page_view_table + options = Arrow::ReadOptions.new + assert_equal(table.schema, + info.get_schema(options)) + end + + def test_without_options + info = @generator.page_view + table = @generator.page_view_table + assert_equal(table.schema, + info.get_schema) + end + end + + def test_descriptor + info = @generator.page_view + assert_equal(@generator.page_view_descriptor, + info.descriptor) + end + + def test_endpoints + info = @generator.page_view + assert_equal(@generator.page_view_endpoints, + info.endpoints) + end + + def test_total_records + info = @generator.page_view + table = @generator.page_view_table + assert_equal(table.n_rows, + info.total_records) + end + + def test_total_bytes + info = @generator.page_view + table = @generator.page_view_table + output = Arrow::ResizableBuffer.new(0) + write_table(table, output, type: :stream) + assert_equal(output.size, + info.total_bytes) + end + + def test_equal + info1 = @generator.page_view + info2 = @generator.page_view + assert do + info1 == info2 + end + end +end diff --git a/src/arrow/c_glib/test/flight/test-location.rb b/src/arrow/c_glib/test/flight/test-location.rb new file mode 100644 index 000000000..5b1679322 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-location.rb @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightLocation < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_to_s + location = ArrowFlight::Location.new("grpc://127.0.0.1:2929") + assert_equal("grpc://127.0.0.1:2929", location.to_s) + end + + def test_scheme + location = ArrowFlight::Location.new("grpc://127.0.0.1:2929") + assert_equal("grpc", location.scheme) + end + + def test_equal + location1 = ArrowFlight::Location.new("grpc://127.0.0.1:2929") + location2 = ArrowFlight::Location.new("grpc://127.0.0.1:2929") + assert do + location1 == location2 + end + end +end diff --git a/src/arrow/c_glib/test/flight/test-path-descriptor.rb b/src/arrow/c_glib/test/flight/test-path-descriptor.rb new file mode 100644 index 000000000..441fc7bb0 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-path-descriptor.rb @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightPathDescriptor < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_to_s + descriptor = ArrowFlight::PathDescriptor.new(["a", "b", "c"]) + assert_equal("FlightDescriptor<path = 'a/b/c'>", + descriptor.to_s) + end + + def test_paths + paths = ["a", "b", "c"] + descriptor = ArrowFlight::PathDescriptor.new(paths) + assert_equal(paths, descriptor.paths) + end + + sub_test_case("#==") do + def test_true + descriptor1 = ArrowFlight::PathDescriptor.new(["a", "b", "c"]) + descriptor2 = ArrowFlight::PathDescriptor.new(["a", "b", "c"]) + assert do + descriptor1 == descriptor2 + end + end + + def test_false + descriptor1 = ArrowFlight::PathDescriptor.new(["a", "b", "c"]) + descriptor2 = ArrowFlight::PathDescriptor.new(["A", "B", "C"]) + assert do + not (descriptor1 == descriptor2) + end + end + end +end diff --git a/src/arrow/c_glib/test/flight/test-server-options.rb b/src/arrow/c_glib/test/flight/test-server-options.rb new file mode 100644 index 000000000..93a90297e --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-server-options.rb @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightServerOptions < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_location + location = ArrowFlight::Location.new("grpc://127.0.0.1:0") + options = ArrowFlight::ServerOptions.new(location) + assert_equal(location, options.location) + end +end diff --git a/src/arrow/c_glib/test/flight/test-stream-reader.rb b/src/arrow/c_glib/test/flight/test-stream-reader.rb new file mode 100644 index 000000000..f2e6229b0 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-stream-reader.rb @@ -0,0 +1,69 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightStreamReader < Test::Unit::TestCase + include Helper::Omittable + + def setup + @server = nil + omit("Arrow Flight is required") unless defined?(ArrowFlight) + omit("Unstable on Windows") if Gem.win_platform? + require_gi_bindings(3, 4, 5) + @server = Helper::FlightServer.new + host = "127.0.0.1" + location = ArrowFlight::Location.new("grpc://#{host}:0") + options = ArrowFlight::ServerOptions.new(location) + @server.listen(options) + location = ArrowFlight::Location.new("grpc://#{host}:#{@server.port}") + client = ArrowFlight::Client.new(location) + @generator = Helper::FlightInfoGenerator.new + @reader = client.do_get(@generator.page_view_ticket) + end + + def teardown + return if @server.nil? + @server.shutdown + end + + def test_read_next + chunks = [] + loop do + chunk = @reader.read_next + break if chunk.nil? + chunks << chunk + end + chunks_content = chunks.collect do |chunk| + [ + chunk.data, + chunk.metadata&.data&.to_s, + ] + end + table_batch_reader = Arrow::TableBatchReader.new(@generator.page_view_table) + assert_equal([ + [ + table_batch_reader.read_next, + nil, + ], + ], + chunks_content) + end + + def test_read_all + assert_equal(@generator.page_view_table, + @reader.read_all) + end +end diff --git a/src/arrow/c_glib/test/flight/test-ticket.rb b/src/arrow/c_glib/test/flight/test-ticket.rb new file mode 100644 index 000000000..976089762 --- /dev/null +++ b/src/arrow/c_glib/test/flight/test-ticket.rb @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +class TestFlightTicket < Test::Unit::TestCase + def setup + omit("Arrow Flight is required") unless defined?(ArrowFlight) + end + + def test_data + data = "data" + ticket = ArrowFlight::Ticket.new(data) + assert_equal(data, + ticket.data.to_s) + end + + sub_test_case("#==") do + def test_true + ticket1 = ArrowFlight::Ticket.new("data") + ticket2 = ArrowFlight::Ticket.new("data") + assert do + ticket1 == ticket2 + end + end + + def test_false + ticket1 = ArrowFlight::Ticket.new("data1") + ticket2 = ArrowFlight::Ticket.new("data2") + assert do + not (ticket1 == ticket2) + end + end + end +end |