summaryrefslogtreecommitdiffstats
path: root/src/arrow/ruby/red-plasma/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/arrow/ruby/red-plasma/test')
-rw-r--r--src/arrow/ruby/red-plasma/test/helper.rb25
-rw-r--r--src/arrow/ruby/red-plasma/test/helper/omittable.rb36
-rw-r--r--src/arrow/ruby/red-plasma/test/helper/plasma-store.rb57
-rwxr-xr-xsrc/arrow/ruby/red-plasma/test/run-test.rb50
-rw-r--r--src/arrow/ruby/red-plasma/test/test-plasma-client.rb53
5 files changed, 221 insertions, 0 deletions
diff --git a/src/arrow/ruby/red-plasma/test/helper.rb b/src/arrow/ruby/red-plasma/test/helper.rb
new file mode 100644
index 000000000..02c545f53
--- /dev/null
+++ b/src/arrow/ruby/red-plasma/test/helper.rb
@@ -0,0 +1,25 @@
+# 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.
+
+require "plasma"
+
+require "tempfile"
+
+require "test-unit"
+
+require_relative "helper/omittable"
+require_relative "helper/plasma-store"
diff --git a/src/arrow/ruby/red-plasma/test/helper/omittable.rb b/src/arrow/ruby/red-plasma/test/helper/omittable.rb
new file mode 100644
index 000000000..a1c0334b6
--- /dev/null
+++ b/src/arrow/ruby/red-plasma/test/helper/omittable.rb
@@ -0,0 +1,36 @@
+# 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.
+
+module Helper
+ module Omittable
+ def require_gi_bindings(major, minor, micro)
+ return if GLib.check_binding_version?(major, minor, micro)
+ message =
+ "Require gobject-introspection #{major}.#{minor}.#{micro} or later: " +
+ GLib::BINDING_VERSION.join(".")
+ omit(message)
+ end
+
+ def require_gi(major, minor, micro)
+ return if GObjectIntrospection::Version.or_later?(major, minor, micro)
+ message =
+ "Require GObject Introspection #{major}.#{minor}.#{micro} or later: " +
+ GObjectIntrospection::Version::STRING
+ omit(message)
+ end
+ end
+end
diff --git a/src/arrow/ruby/red-plasma/test/helper/plasma-store.rb b/src/arrow/ruby/red-plasma/test/helper/plasma-store.rb
new file mode 100644
index 000000000..dcf1f47ae
--- /dev/null
+++ b/src/arrow/ruby/red-plasma/test/helper/plasma-store.rb
@@ -0,0 +1,57 @@
+# 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.
+
+module Helper
+ class PlasmaStore
+ def initialize(options={})
+ @path = `pkg-config --variable=plasma_store_server plasma`.chomp
+ @memory_size = options[:memory_size] || 1024 * 1024
+ @socket_file = Tempfile.new(["plasma-store", ".sock"])
+ @socket_file.close
+ @pid = nil
+ FileUtils.rm_f(socket_path)
+ end
+
+ def socket_path
+ @socket_file.path
+ end
+
+ def start
+ @pid = spawn(@path,
+ "-m", @memory_size.to_s,
+ "-s", socket_path)
+ until File.exist?(socket_path)
+ if Process.waitpid(@pid, Process::WNOHANG)
+ raise "Failed to run plasma-store-server: #{@path}"
+ end
+ end
+ end
+
+ def stop
+ return if @pid.nil?
+ Process.kill(:TERM, @pid)
+ timeout = 1
+ limit = Time.now + timeout
+ while Time.now < limit
+ return if Process.waitpid(@pid, Process::WNOHANG)
+ sleep(0.1)
+ end
+ Process.kill(:KILL, @pid)
+ Process.waitpid(@pid)
+ end
+ end
+end
diff --git a/src/arrow/ruby/red-plasma/test/run-test.rb b/src/arrow/ruby/red-plasma/test/run-test.rb
new file mode 100755
index 000000000..48d2c49e1
--- /dev/null
+++ b/src/arrow/ruby/red-plasma/test/run-test.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+#
+# 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.
+
+$VERBOSE = true
+
+require "pathname"
+
+(ENV["ARROW_DLL_PATH"] || "").split(File::PATH_SEPARATOR).each do |path|
+ RubyInstaller::Runtime.add_dll_directory(path)
+end
+
+base_dir = Pathname.new(__dir__).parent.expand_path
+arrow_base_dir = base_dir.parent + "red-arrow"
+
+lib_dir = base_dir + "lib"
+test_dir = base_dir + "test"
+
+arrow_lib_dir = arrow_base_dir + "lib"
+arrow_ext_dir = arrow_base_dir + "ext" + "arrow"
+
+build_dir = ENV["BUILD_DIR"]
+if build_dir
+ arrow_build_dir = Pathname.new(build_dir) + "red-arrow"
+else
+ arrow_build_dir = arrow_ext_dir
+end
+
+$LOAD_PATH.unshift(arrow_build_dir.to_s)
+$LOAD_PATH.unshift(arrow_lib_dir.to_s)
+$LOAD_PATH.unshift(lib_dir.to_s)
+
+require_relative "helper"
+
+exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))
diff --git a/src/arrow/ruby/red-plasma/test/test-plasma-client.rb b/src/arrow/ruby/red-plasma/test/test-plasma-client.rb
new file mode 100644
index 000000000..d6182976c
--- /dev/null
+++ b/src/arrow/ruby/red-plasma/test/test-plasma-client.rb
@@ -0,0 +1,53 @@
+# 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 TestPlasmaClient < Test::Unit::TestCase
+ include Helper::Omittable
+
+ def setup
+ @store = nil
+ require_gi_bindings(3, 3, 9)
+ @store = Helper::PlasmaStore.new
+ @store.start
+ @id = Plasma::ObjectID.new("Hello")
+ @data = "World"
+ end
+
+ def teardown
+ @store.stop if @store
+ end
+
+ def test_new_pathname
+ client = Plasma::Client.new(Pathname(@store.socket_path))
+ object = client.create(@id, @data.bytesize, nil)
+ object.data.set_data(0, @data)
+ object.seal
+
+ object = client.refer_object(@id, -1)
+ assert_equal(@data, object.data.data.to_s)
+ end
+
+ def test_new_options
+ client = Plasma::Client.new(@store.socket_path, n_retries: 1)
+ object = client.create(@id, @data.bytesize, nil)
+ object.data.set_data(0, @data)
+ object.seal
+
+ object = client.refer_object(@id, -1)
+ assert_equal(@data, object.data.data.to_s)
+ end
+end