t2-server 0.9.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2012 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2013 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -80,7 +80,8 @@ module T2Server
80
80
  end
81
81
 
82
82
  def xpath_attr(doc, expr, attribute)
83
- doc.find_first(expr, Namespaces::MAP).attributes[attribute]
83
+ node = xpath_first(doc, expr)
84
+ node.nil? ? nil : node.attributes[attribute]
84
85
  end
85
86
  end
86
87
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2012 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2013 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -50,7 +50,7 @@ module T2Server
50
50
  end
51
51
 
52
52
  def xml_children(doc, &block)
53
- doc.children.each &block
53
+ doc.children.each(&block)
54
54
  end
55
55
 
56
56
  def xml_node_name(node)
@@ -78,7 +78,8 @@ module T2Server
78
78
  end
79
79
 
80
80
  def xpath_attr(doc, expr, attribute)
81
- doc.at_xpath(expr, Namespaces::MAP)[attribute]
81
+ node = xpath_first(doc, expr)
82
+ node.nil? ? nil : node[attribute]
82
83
  end
83
84
  end
84
85
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2012 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2013 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -78,7 +78,8 @@ module T2Server
78
78
  end
79
79
 
80
80
  def xpath_attr(doc, expr, attribute)
81
- REXML::XPath.first(doc, expr, Namespaces::MAP).attributes[attribute]
81
+ node = xpath_first(doc, expr)
82
+ node.nil? ? nil : node.attributes[attribute]
82
83
  end
83
84
  end
84
85
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2012 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2013 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -39,6 +39,7 @@ rescue LoadError
39
39
  require 't2-server/xml/rexml'
40
40
  end
41
41
  end
42
+ require 't2-server/xml/xpath_cache'
42
43
 
43
44
  module T2Server
44
45
  module XML
@@ -58,54 +59,64 @@ module T2Server
58
59
  end
59
60
 
60
61
  module Fragments
61
- WORKFLOW = "<t2s:workflow xmlns:t2s=\"#{Namespaces::SERVER}\">\n" +
62
- " %s\n</t2s:workflow>"
63
- RUNINPUT = "<t2sr:runInput xmlns:t2sr=\"#{Namespaces::REST}\">\n" +
64
- " %s\n</t2sr:runInput>"
62
+ WORKFLOW = "<t2s:workflow xmlns:t2s=\"#{Namespaces::SERVER}\">\n"\
63
+ " %s\n</t2s:workflow>"
64
+ RUNINPUT = "<t2sr:runInput xmlns:t2sr=\"#{Namespaces::REST}\">\n"\
65
+ " %s\n</t2sr:runInput>"
65
66
  RUNINPUTVALUE = RUNINPUT % "<t2sr:value>%s</t2sr:value>"
66
67
  RUNINPUTFILE = RUNINPUT % "<t2sr:file>%s</t2sr:file>"
67
- UPLOAD = "<t2sr:upload xmlns:t2sr=\"#{Namespaces::REST}\" " +
68
+ UPLOAD = "<t2sr:upload xmlns:t2sr=\"#{Namespaces::REST}\" "\
68
69
  "t2sr:name=\"%s\">\n %s\n</t2sr:upload>"
69
- MKDIR = "<t2sr:mkdir xmlns:t2sr=\"#{Namespaces::REST}\" " +
70
+ MKDIR = "<t2sr:mkdir xmlns:t2sr=\"#{Namespaces::REST}\" "\
70
71
  "t2sr:name=\"%s\" />"
71
72
 
72
- PERMISSION = "<t2sr:userName>%s</t2sr:userName>" +
73
+ PERMISSION = "<t2sr:userName>%s</t2sr:userName>"\
73
74
  "<t2sr:permission>%s</t2sr:permission>"
74
- PERM_UPDATE = "<t2sr:permissionUpdate " +
75
- "xmlns:t2sr=\"#{Namespaces::REST}\">" +
76
- "#{PERMISSION}</t2sr:permissionUpdate>"
75
+ PERM_UPDATE = "<t2sr:permissionUpdate "\
76
+ "xmlns:t2sr=\"#{Namespaces::REST}\">"\
77
+ "#{PERMISSION}</t2sr:permissionUpdate>"
77
78
 
78
79
  SERVICE_URI = "<t2s:serviceURI>%s</t2s:serviceURI>"
79
- CREDENTIAL = "<t2sr:credential xmlns:t2sr=\"#{Namespaces::REST}\"" +
80
- " xmlns:t2s=\"#{Namespaces::SERVER}\">\n" +
81
- "%s\n</t2sr:credential>"
82
- USERPASS_CRED = "<t2s:userpass>\n" +
83
- " #{SERVICE_URI}\n" +
84
- " <t2s:username>%s</t2s:username>\n" +
85
- " <t2s:password>%s</t2s:password>\n" +
86
- "</t2s:userpass>"
80
+ CREDENTIAL = "<t2sr:credential xmlns:t2sr=\"#{Namespaces::REST}\""\
81
+ " xmlns:t2s=\"#{Namespaces::SERVER}\">\n"\
82
+ "%s\n</t2sr:credential>"
83
+ USERPASS_CRED = "<t2s:userpass>\n"\
84
+ " #{SERVICE_URI}\n"\
85
+ " <t2s:username>%s</t2s:username>\n"\
86
+ " <t2s:password>%s</t2s:password>\n"\
87
+ "</t2s:userpass>"
87
88
 
88
- KEYPAIR_CRED = "<t2s:keypair>\n" +
89
- " #{SERVICE_URI}\n" +
90
- " <t2s:credentialName>%s</t2s:credentialName>\n" +
91
- " <t2s:credentialBytes>%s</t2s:credentialBytes>\n" +
92
- " <t2s:fileType>%s</t2s:fileType>\n" +
93
- " <t2s:unlockPassword>%s</t2s:unlockPassword>\n" +
94
- "</t2s:keypair>"
89
+ KEYPAIR_CRED = "<t2s:keypair>\n"\
90
+ " #{SERVICE_URI}\n"\
91
+ " <t2s:credentialName>%s</t2s:credentialName>\n"\
92
+ " <t2s:credentialBytes>%s</t2s:credentialBytes>\n"\
93
+ " <t2s:fileType>%s</t2s:fileType>\n"\
94
+ " <t2s:unlockPassword>%s</t2s:unlockPassword>\n"\
95
+ "</t2s:keypair>"
95
96
 
96
- TRUST = "<t2s:trustedIdentity " +
97
- "xmlns:t2s=\"#{Namespaces::SERVER}\">\n" +
98
- " <t2s:certificateBytes>%s</t2s:certificateBytes>\n" +
99
- " <t2s:fileType>%s</t2s:fileType>\n" +
100
- "</t2s:trustedIdentity>"
97
+ TRUST = "<t2s:trustedIdentity "\
98
+ "xmlns:t2s=\"#{Namespaces::SERVER}\">\n"\
99
+ " <t2s:certificateBytes>%s</t2s:certificateBytes>\n"\
100
+ " <t2s:fileType>%s</t2s:fileType>\n"\
101
+ "</t2s:trustedIdentity>"
101
102
  end
102
103
 
103
104
  module Methods
104
- # The methods in this namespace are provided by the particular XML
105
- # library selected above. The xpath_compile method needs to be declared
106
- # as a module method so it can be used as a class method when it is
107
- # mixed in.
108
- module_function :xpath_compile
105
+ # Most methods in this module are provided by the particular XML
106
+ # library selected above.
107
+
108
+ # Given a list of xpath keys, extract the href URIs from those elements.
109
+ def get_uris_from_doc(doc, keys)
110
+ cache = XPathCache.instance
111
+ uris = {}
112
+
113
+ keys.each do |key|
114
+ uri = xpath_attr(doc, cache[key], "href")
115
+ uris[key] = uri.nil? ? nil : URI.parse(uri)
116
+ end
117
+
118
+ uris
119
+ end
109
120
  end
110
121
  end
111
122
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010, 2011 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2013 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -30,9 +30,31 @@
30
30
  #
31
31
  # Author: Robert Haines
32
32
 
33
- # This is simply here to provide backwards compatibility. Old versions had an
34
- # inconsistancy between the gem name and the file to require to use it.
35
- warn "[DEPRECATION] Code should no longer require 't2server'. Please use " +
36
- "require 't2-server' as this is consistent with the gem name. In version " +
37
- "1.0 require 't2server' will cease to work."
38
- require 't2-server'
33
+ require 'singleton'
34
+
35
+ module T2Server
36
+ module XML
37
+ class XPathCache
38
+ include Singleton
39
+ include XML::Methods
40
+
41
+ def initialize
42
+ @cache = {}
43
+ @xpaths = {}
44
+ end
45
+
46
+ def [](key)
47
+ return nil unless @xpaths.has_key? key
48
+ return @cache[key] if @cache.has_key? key
49
+
50
+ xpath = @xpaths[key]
51
+ @cache[key] = xpath_compile(xpath)
52
+ end
53
+
54
+ def register_xpaths(xpaths)
55
+ @xpaths.merge! xpaths
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "t2-server"
8
- s.version = "0.9.3"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Robert Haines"]
12
- s.date = "2013-05-20"
11
+ s.authors = ["Robert Haines", "Finn Bacall"]
12
+ s.date = "2013-11-05"
13
13
  s.description = "This gem provides access to the Taverna 2 Server REST interface from Ruby."
14
- s.email = ["rhaines@manchester.ac.uk"]
14
+ s.email = ["support@mygrid.org.uk"]
15
15
  s.executables = ["t2-delete-runs", "t2-run-workflow", "t2-server-info", "t2-get-output", "t2-server-admin"]
16
16
  s.extra_rdoc_files = [
17
17
  "CHANGES.rdoc",
@@ -28,14 +28,17 @@ Gem::Specification.new do |s|
28
28
  "bin/t2-run-workflow",
29
29
  "bin/t2-server-admin",
30
30
  "bin/t2-server-info",
31
+ "extras/t2-server-stress",
31
32
  "lib/t2-server-cli.rb",
32
33
  "lib/t2-server.rb",
33
34
  "lib/t2-server/admin.rb",
34
35
  "lib/t2-server/exceptions.rb",
36
+ "lib/t2-server/interaction.rb",
35
37
  "lib/t2-server/net/connection.rb",
36
38
  "lib/t2-server/net/credentials.rb",
37
39
  "lib/t2-server/net/parameters.rb",
38
40
  "lib/t2-server/port.rb",
41
+ "lib/t2-server/run-cache.rb",
39
42
  "lib/t2-server/run.rb",
40
43
  "lib/t2-server/server.rb",
41
44
  "lib/t2-server/util.rb",
@@ -43,9 +46,10 @@ Gem::Specification.new do |s|
43
46
  "lib/t2-server/xml/nokogiri.rb",
44
47
  "lib/t2-server/xml/rexml.rb",
45
48
  "lib/t2-server/xml/xml.rb",
46
- "lib/t2server.rb",
49
+ "lib/t2-server/xml/xpath_cache.rb",
47
50
  "t2-server.gemspec",
48
51
  "test/tc_admin.rb",
52
+ "test/tc_misc.rb",
49
53
  "test/tc_params.rb",
50
54
  "test/tc_perms.rb",
51
55
  "test/tc_run.rb",
@@ -59,6 +63,7 @@ Gem::Specification.new do |s|
59
63
  "test/workflows/in.txt",
60
64
  "test/workflows/list_and_value.t2flow",
61
65
  "test/workflows/list_with_errors.t2flow",
66
+ "test/workflows/missing_outputs.t2flow",
62
67
  "test/workflows/no-ports.t2flow",
63
68
  "test/workflows/pass_through.t2flow",
64
69
  "test/workflows/secure/basic-http.t2flow",
@@ -90,8 +95,10 @@ Gem::Specification.new do |s|
90
95
  s.add_development_dependency(%q<nokogiri>, [">= 1.5.0"])
91
96
  s.add_development_dependency(%q<rdoc>, [">= 3.9.4"])
92
97
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
98
+ s.add_development_dependency(%q<launchy>, ["~> 2.2.0"])
93
99
  s.add_runtime_dependency(%q<net-http-persistent>, ["~> 2.6"])
94
100
  s.add_runtime_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
101
+ s.add_runtime_dependency(%q<ratom>, ["~> 0.8.2"])
95
102
  s.add_runtime_dependency(%q<hirb>, [">= 0.4.0"])
96
103
  else
97
104
  s.add_dependency(%q<rake>, ["~> 0.9.2"])
@@ -99,8 +106,10 @@ Gem::Specification.new do |s|
99
106
  s.add_dependency(%q<nokogiri>, [">= 1.5.0"])
100
107
  s.add_dependency(%q<rdoc>, [">= 3.9.4"])
101
108
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
109
+ s.add_dependency(%q<launchy>, ["~> 2.2.0"])
102
110
  s.add_dependency(%q<net-http-persistent>, ["~> 2.6"])
103
111
  s.add_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
112
+ s.add_dependency(%q<ratom>, ["~> 0.8.2"])
104
113
  s.add_dependency(%q<hirb>, [">= 0.4.0"])
105
114
  end
106
115
  else
@@ -109,8 +118,10 @@ Gem::Specification.new do |s|
109
118
  s.add_dependency(%q<nokogiri>, [">= 1.5.0"])
110
119
  s.add_dependency(%q<rdoc>, [">= 3.9.4"])
111
120
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
121
+ s.add_dependency(%q<launchy>, ["~> 2.2.0"])
112
122
  s.add_dependency(%q<net-http-persistent>, ["~> 2.6"])
113
123
  s.add_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
124
+ s.add_dependency(%q<ratom>, ["~> 0.8.2"])
114
125
  s.add_dependency(%q<hirb>, [">= 0.4.0"])
115
126
  end
116
127
  end
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2013 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ require 't2-server'
34
+
35
+ class TestMisc < Test::Unit::TestCase
36
+
37
+ # Test a run with the missing output data bug to check that the library can
38
+ # workaround it ok. Bug is: http://dev.mygrid.org.uk/issues/browse/T2-2100
39
+ def test_missing_ports
40
+ T2Server::Run.create($uri, $wkf_miss_o, $creds, $conn_params) do |run|
41
+ assert_nothing_raised { run.start }
42
+ assert(run.running?)
43
+ run.wait
44
+
45
+ run.output_ports.each do |_, port|
46
+ # Check that outputs are the correct depth
47
+ assert_equal(port.depth, 2)
48
+
49
+ # Check that output lists are the correct length
50
+ assert_equal(port.value.length, 3)
51
+ assert_equal(port[0].length, 10)
52
+
53
+ # Check that there are empty lists in the correct places
54
+ assert_equal(port.value[1], [])
55
+ end
56
+
57
+ assert(run.delete)
58
+ end
59
+ end
60
+
61
+ end
@@ -34,19 +34,27 @@ require 't2-server'
34
34
 
35
35
  class TestPermissions < Test::Unit::TestCase
36
36
 
37
- def test_ownership
37
+ def test_ownership_and_revokation
38
38
  server = T2Server::Server.new($uri, $conn_params)
39
39
 
40
40
  server.create_run($wkf_pass, $creds) do |run|
41
41
  assert(run.owner?)
42
42
  assert_equal(run.owner, $creds.username)
43
43
 
44
+ assert_equal(run.permission($creds1.username), :none)
44
45
  run.grant_permission($creds1.username, :read)
46
+ assert_equal(run.permission($creds1.username), :read)
45
47
  run_id = run.identifier
46
48
  run1 = server.run(run_id, $creds1)
47
49
 
48
50
  assert(!run1.owner?)
49
51
  assert_not_equal(run1.owner, $creds1.username)
52
+
53
+ assert(run.revoke_permission($creds1.username))
54
+ assert_equal(run.permission($creds1.username), :none)
55
+ assert(run.revoke_permission($creds1.username))
56
+
57
+ assert(run.delete)
50
58
  end
51
59
  end
52
60
 
@@ -81,6 +89,10 @@ class TestPermissions < Test::Unit::TestCase
81
89
  assert_raise(T2Server::AccessForbiddenError) do
82
90
  run1.delete
83
91
  end
92
+
93
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
94
+ run.delete
95
+ end
84
96
  end
85
97
  end
86
98
 
@@ -106,6 +118,10 @@ class TestPermissions < Test::Unit::TestCase
106
118
  assert_raise(T2Server::AccessForbiddenError) do
107
119
  run1.delete
108
120
  end
121
+
122
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
123
+ run.delete
124
+ end
109
125
  end
110
126
  end
111
127
 
@@ -32,12 +32,38 @@
32
32
 
33
33
  require 't2-server'
34
34
 
35
+ # A class to test data streaming.
36
+ class TestCache
37
+ attr_reader :data
38
+
39
+ def initialize
40
+ @data = ""
41
+ end
42
+
43
+ def write(data)
44
+ @data += data
45
+ data.size
46
+ end
47
+
48
+ def size
49
+ return @data.size
50
+ end
51
+ end
52
+
35
53
  class TestRun < Test::Unit::TestCase
36
54
 
37
55
  # Test run connection
38
- def test_run_misc
56
+ def test_run_create_and_delete
39
57
  assert_nothing_raised(T2Server::ConnectionError) do
40
- T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params)
58
+ run = T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params)
59
+ assert_equal(run.status, :initialized)
60
+ assert(run.delete)
61
+ assert(run.deleted?)
62
+ assert_equal(run.status, :deleted)
63
+ assert_nothing_raised(T2Server::AttributeNotFoundError) do
64
+ assert(run.delete) # Should still return true, not raise 404
65
+ end
66
+ assert(run.delete) # Should still return true
41
67
  end
42
68
  end
43
69
 
@@ -71,7 +97,23 @@ class TestRun < Test::Unit::TestCase
71
97
 
72
98
  # get zip file
73
99
  assert_nothing_raised(T2Server::T2ServerError) do
74
- assert_not_equal(run.zip_output, "")
100
+ zip_out = run.zip_output
101
+ assert_not_equal(zip_out, "")
102
+ end
103
+
104
+ # test streaming zip data
105
+ assert_nothing_raised(T2Server::T2ServerError) do
106
+ zip_cache = TestCache.new
107
+ run.zip_output(zip_cache)
108
+ end
109
+
110
+ # show getting a zip file of a singleton port does nothing
111
+ assert_nothing_raised(T2Server::T2ServerError) do
112
+ assert_nil(run.output_port("OUT").zip)
113
+
114
+ zip_cache = TestCache.new
115
+ run.output_port("OUT").zip(zip_cache)
116
+ assert_equal(zip_cache.data, "")
75
117
  end
76
118
 
77
119
  # deletion
@@ -79,14 +121,53 @@ class TestRun < Test::Unit::TestCase
79
121
  end
80
122
  end
81
123
 
82
- # Test run with no input or output
124
+ # Test run naming. This is different for different versions of server.
125
+ def test_run_naming
126
+ T2Server::Server.new($uri, $conn_params) do |server|
127
+ vc = server.version_components
128
+ v250plus = vc[0] > 2 || (vc[0] == 2 && vc[1] >= 5)
129
+ server.create_run($wkf_no_io, $creds) do |run|
130
+ if v250plus
131
+ # Read initial name.
132
+ assert(run.name.length > 0)
133
+ assert_equal("Workflow1", run.name[0...9])
134
+
135
+ # Set a new name and test.
136
+ name = "No input or output"
137
+ assert(run.name = name)
138
+ assert(run.name.length == 18)
139
+ assert_equal(name, run.name)
140
+
141
+ # Set a name that is too long
142
+ long_name = "0123456789012345678901234567890123456789ABCDEFGHIJ"
143
+ assert(run.name = long_name)
144
+ assert(run.name.length == 48)
145
+ assert_equal(long_name[0...48], run.name)
146
+ else
147
+ # Read initial name.
148
+ assert(run.name.length == 0)
149
+ assert_equal("", run.name)
150
+
151
+ # "Set" a new name and test.
152
+ assert(run.name = "test")
153
+ assert(run.name.length == 0)
154
+ assert_equal("", run.name)
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ # Test run with no input or output. Also, pre-load workflow into a String.
83
161
  def test_run_no_ports
84
- T2Server::Run.create($uri, $wkf_no_io, $creds, $conn_params) do |run|
162
+ workflow = File.read($wkf_no_io)
163
+
164
+ T2Server::Run.create($uri, workflow, $creds, $conn_params) do |run|
85
165
  assert_nothing_raised { run.input_ports }
86
166
  assert_nothing_raised { run.start }
87
167
  assert(run.running?)
88
168
  run.wait
89
169
  assert_nothing_raised { run.output_ports }
170
+ assert(run.delete)
90
171
  end
91
172
  end
92
173
 
@@ -105,6 +186,19 @@ class TestRun < Test::Unit::TestCase
105
186
 
106
187
  assert_equal(run.output_port("MANY").value, many)
107
188
  assert_equal(run.output_port("SINGLE").value, single_out)
189
+
190
+ # get zip file of a single port and test streaming
191
+ assert_nothing_raised(T2Server::T2ServerError) do
192
+ zip_out = run.output_port("MANY").zip
193
+ assert_not_equal(zip_out, "")
194
+ end
195
+
196
+ assert_nothing_raised(T2Server::T2ServerError) do
197
+ zip_cache = TestCache.new
198
+ run.output_port("MANY").zip(zip_cache)
199
+ end
200
+
201
+ assert(run.delete)
108
202
  end
109
203
  end
110
204
 
@@ -122,6 +216,19 @@ class TestRun < Test::Unit::TestCase
122
216
 
123
217
  assert_equal(run.output_port("list_out").value, list_out)
124
218
  assert_equal(run.output_port("singleton_out").value, "Hello, World!")
219
+
220
+ # Get the log file
221
+ assert_nothing_raised(T2Server::T2ServerError) do
222
+ assert_not_equal(run.log, "")
223
+ end
224
+
225
+ assert_nothing_raised(T2Server::T2ServerError) do
226
+ log_cache = TestCache.new
227
+ run.log(log_cache)
228
+ assert_not_equal(log_cache.size, 0)
229
+ end
230
+
231
+ assert(run.delete)
125
232
  end
126
233
  end
127
234
 
@@ -134,11 +241,14 @@ class TestRun < Test::Unit::TestCase
134
241
  run.start
135
242
  run.wait
136
243
  assert_equal(run.output_port("nodes").value, ["hello", "world"])
244
+ assert(run.delete)
137
245
  end
138
246
  end
139
247
 
248
+ # Test run with file input. Also pass workflow as File object.
140
249
  def test_run_file_input
141
- # run with file input
250
+ workflow = File.open($wkf_pass, "r")
251
+
142
252
  T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params) do |run|
143
253
 
144
254
  assert_nothing_raised(T2Server::AttributeNotFoundError) do
@@ -149,7 +259,10 @@ class TestRun < Test::Unit::TestCase
149
259
  assert(run.running?)
150
260
  assert_nothing_raised(T2Server::RunStateError) { run.wait }
151
261
  assert_equal(run.output_port("OUT").value, "Hello, World!")
262
+ assert(run.delete)
152
263
  end
264
+
265
+ workflow.close
153
266
  end
154
267
 
155
268
  # Test run that returns list of lists, some empty, using baclava for input
@@ -171,11 +284,14 @@ class TestRun < Test::Unit::TestCase
171
284
  assert_nothing_raised(T2Server::RunStateError) { run.wait }
172
285
  assert_equal(run.output_ports.keys.sort, ["MANY", "SINGLE"])
173
286
  assert_equal(run.output_port("SINGLE").value, [])
287
+ assert(!run.output_port("SINGLE").empty?)
174
288
  assert_equal(run.output_port("MANY").value,
175
289
  [[["boo"]], [["", "Hello"]], [], [[], ["test"], []]])
176
290
  assert_equal(run.output_port("MANY").total_size, 12)
291
+ assert(run.output_port("MANY")[1][0][0].empty?)
177
292
  assert_equal(run.output_port("MANY")[1][0][1].value(1..3), "ell")
178
293
  assert_raise(NoMethodError) { run.output_port("SINGLE")[0].value }
294
+ assert(run.delete)
179
295
  end
180
296
  end
181
297
 
@@ -192,9 +308,18 @@ class TestRun < Test::Unit::TestCase
192
308
  assert(run.running?)
193
309
  assert_nothing_raised(T2Server::RunStateError) { run.wait }
194
310
 
311
+ # Test normal and streamed output
195
312
  assert_nothing_raised(T2Server::AccessForbiddenError) do
196
313
  output = run.baclava_output
314
+
315
+ out_stream = ""
316
+ run.baclava_output do |chunk|
317
+ out_stream += chunk
318
+ end
319
+ assert_equal(output, out_stream)
197
320
  end
321
+
322
+ assert(run.delete)
198
323
  end
199
324
  end
200
325
 
@@ -209,44 +334,44 @@ class TestRun < Test::Unit::TestCase
209
334
  run.start
210
335
  run.wait
211
336
 
212
- # get total data size (without downloading the data)
337
+ # Get total data size (without downloading the data).
213
338
  assert_equal(run.output_port("OUT").total_size, 100)
214
339
  assert_equal(run.output_port("OUT").size, 100)
215
340
 
216
- # no data downloaded yet
217
- assert(run.output_port("OUT").value(:debug).nil?)
341
+ # Stream just the first 10 bytes.
342
+ stream = ""
343
+ run.output_port("OUT").value(0...10) do |chunk|
344
+ stream += chunk
345
+ end
346
+ assert_equal(stream, "123456789\n")
218
347
 
219
- # get just the first 10 bytes
220
- assert_equal(run.output_port("OUT").value(0...10),
221
- "123456789\n")
348
+ # Get just the second 10 bytes.
349
+ assert_equal(run.output_port("OUT").value(10...20),
350
+ "223456789\n")
222
351
 
223
- # get a bad range - should return the first 10 bytes
224
- assert_equal(run.output_port("OUT").value(-10...10),
225
- "123456789\n")
352
+ # Stream the first 20 bytes.
353
+ stream = ""
354
+ run.output_port("OUT").value(0...20) do |chunk|
355
+ stream += chunk
356
+ end
357
+ assert_equal(stream, "123456789\n223456789\n")
226
358
 
227
- # confirm only the first 10 bytes have been downloaded
228
- assert_equal(run.output_port("OUT").value(:debug),
359
+ # Get a bad range - should return the first 10 bytes.
360
+ assert_equal(run.output_port("OUT").value(-10...10),
229
361
  "123456789\n")
230
362
 
231
- # ask for a separate 10 byte range
232
- assert_equal(run.output_port("OUT").value(20...30),
233
- "323456789\n")
234
-
235
- # confirm that enough was downloaded to connect the two ranges
236
- assert_equal(run.output_port("OUT").value(:debug),
237
- "123456789\n223456789\n323456789\n")
238
-
239
- # ask for a range that we already have
240
- assert_equal(run.output_port("OUT").value(5..25),
241
- "6789\n223456789\n323456")
242
-
243
- # confirm that no more has actually been downloaded
244
- assert_equal(run.output_port("OUT").value(:debug),
245
- "123456789\n223456789\n323456789\n")
363
+ # Stream the lot and check total length. There should be two chunks.
364
+ stream = ""
365
+ run.output_port("OUT").value do |chunk|
366
+ stream += chunk
367
+ end
368
+ assert_equal(stream.length, 100)
246
369
 
247
- # now get the lot and check its size
370
+ # Now get the lot and check its size.
248
371
  out = run.output_port("OUT").value
249
372
  assert_equal(out.length, 100)
373
+
374
+ assert(run.delete)
250
375
  end
251
376
  end
252
377
 
@@ -255,16 +380,21 @@ class TestRun < Test::Unit::TestCase
255
380
  T2Server::Run.create($uri, $wkf_fail, $creds, $conn_params) do |run|
256
381
  run.start
257
382
  run.wait
258
- assert(run.output_port("OUT").value.nil?)
383
+ assert_not_nil(run.output_port("OUT").value)
259
384
  assert(run.output_port("OUT").error?)
385
+ assert(run.delete)
260
386
  end
261
387
  end
262
388
 
263
389
  def test_errors
264
390
  T2Server::Run.create($uri, $wkf_errors, $creds, $conn_params) do |run|
265
391
  run.start
392
+ assert(!run.error?)
266
393
  run.wait
394
+ assert_not_nil(run.output_port("OUT").value)
267
395
  assert(run.output_port("OUT").error?)
396
+ assert(run.error?)
397
+ assert(run.delete)
268
398
  end
269
399
  end
270
400
  end