Class: PigSpec::Test

Inherits:
Object
  • Object
show all
Includes:
Cleanroom
Defined in:
lib/pigspec.rb

Overview

TestCase of PigSpec

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.bridgeObject (readonly)

Returns the value of attribute bridge.



14
15
16
# File 'lib/pigspec.rb', line 14

def bridge
  @bridge
end

Class Method Details

.construct(pig_path, pigunit_path, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pigspec.rb', line 15

def construct(pig_path, pigunit_path, options)
  @pig_path ||= pig_path
  @pigunit_path ||= pigunit_path
  @options ||= options

  fail ArgumentError, 'This version pigspec only can same pig_path for all processes.' unless @pig_path == pig_path
  fail ArgumentError, 'This version pigspec only can same pigunit_path for all processes.' unless @pigunit_path == pigunit_path
  fail ArgumentError, 'This version pigspec only can same options for all processes.' unless @options == options

  @bridge ||= JavaBridge.new @pig_path, @pigunit_path, @options
end

Instance Method Details

#override(name, value, options = {}) ⇒ Object



61
62
63
# File 'lib/pigspec.rb', line 61

def override(name, value, options = {})
  @override.push name: name, value: value, schema: options[:as]
end

#pickup(name) ⇒ Object

to ‘expose’



67
68
69
# File 'lib/pigspec.rb', line 67

def pickup(name)  # rubocop:disable Style/TrivialAccessors
  @pickup = name
end

#runObject



72
73
74
75
76
77
78
79
80
# File 'lib/pigspec.rb', line 72

def run
  # If no output alias, must result nil
  return nil unless @pickup

  test = Test.bridge.create_test @script, *@args
  test.register_script
  apply_override test
  test.run_script @pickup
end

#script(text) ⇒ Object



46
47
48
# File 'lib/pigspec.rb', line 46

def script(text)
  @script = text.split("\n")
end

#script_file(path) ⇒ Object



51
52
53
# File 'lib/pigspec.rb', line 51

def script_file(path)
  @script = open(path, 'r') { |f| f.each_line.to_a }
end

#setup(pig_path, pigunit_path, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/pigspec.rb', line 28

def setup(pig_path, pigunit_path, options)
  fail ArgumentError, 'Must needs pig_path. It must point to your installation of Apache Pig/PigUnit jar files.' if pig_path.nil?
  fail ArgumentError, 'Must needs pigunit_path. It must point to your installation of Apache Pig/PigUnit jar files.' if pigunit_path.nil?

  Test.construct pig_path, pigunit_path, options
  @script = []
  @args = []
  @override = []
  @pickup = nil
end

#shutdownObject



39
40
41
42
43
44
# File 'lib/pigspec.rb', line 39

def shutdown
  # Rjb unload -> load is not work.(current restriction.)
  # s.a https://github.com/arton/rjb/issues/34
  # If the JNI bug fixed then we can uncomment follow line.
  # @bridge.unload
end

#with_args(*args) ⇒ Object



56
57
58
# File 'lib/pigspec.rb', line 56

def with_args(*args)
  @args = args
end