net-tnsping 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGES +14 -0
  2. data/README +12 -22
  3. data/Rakefile +31 -24
  4. data/lib/net/tnsping.rb +236 -228
  5. data/net-tnsping.gemspec +21 -24
  6. data/test/test_net_tnsping.rb +199 -144
  7. metadata +45 -21
data/CHANGES CHANGED
@@ -1,3 +1,17 @@
1
+ == 1.3.2 - 1-Mar-2011
2
+ * Case is now ignored for the database name when searching through the
3
+ tnsnames.ora file.
4
+ * Removed explicit timeout accessor. It's already inherited.
5
+ * Fixed the driver accessor. It was not being set in the constructor.
6
+ * Removed a useless call to tns_admin in the constructor.
7
+ * Flip-flopped the db and database accessor and alias.
8
+ * Refactored tests to use declarative syntax, added some tests, and
9
+ did some general refactoring. Also, the default database name is
10
+ set to "XE" (Express Edition). Change as needed.
11
+ * Updated the Rakefile, removing the non-gem installation task, and
12
+ adding a clean task.
13
+ * Updated the gemspec. The gem build is now handled by a rake task.
14
+
1
15
  == 1.3.1 - 8-Aug-2009
2
16
  * Switched test-unit from a runtime dependency to a development dependency.
3
17
  * Minor documentation updates.
data/README CHANGED
@@ -1,27 +1,19 @@
1
1
  == Description
2
- This package emulates the Oracle tnsping utility.
2
+ The net-tnsping library emulates the Oracle tnsping utility. It pings
3
+ both the listener and the datasource.
3
4
 
4
5
  == Prerequisites
5
- Ruby 1.8.0 or later
6
- dbi
7
- net-ping 1.0.0 or later
8
- Any of the Oracle database drivers (oracle, oci8, ruby9i, etc)
6
+ * dbi
7
+ * net-ping
8
+ * Any of the Oracle database drivers (oracle, oci8, ruby9i, etc)
9
9
 
10
10
  == Installation
11
+ gem install net-tnsping
11
12
 
12
- === Manual Installation
13
- rake test (optional)
14
- rake install
15
-
16
- === Gem Installation
17
- rake test (optional)
18
- ruby net-tnsping.gemspec
19
- gem install net-tnsping-<version>.gem
20
-
21
13
  === Test Note
22
14
  You may want to manually tweak one instance variable (@@database) in the
23
15
  test suite in order to get a more robust set of test results. Set it to
24
- a known database name.
16
+ a known database name. By default it uses "XE" (Express Edition).
25
17
 
26
18
  == Synopsis
27
19
  require "net/tnsping"
@@ -30,14 +22,14 @@
30
22
  t = Ping::TNS.new("my_db")
31
23
 
32
24
  if t.ping?
33
- puts "Database appears to be up and running"
25
+ puts "Database appears to be up and running"
34
26
  else
35
- puts "There was a problem: " + t.exception
27
+ puts "There was a problem: " + t.exception
36
28
  end
37
29
 
38
30
  == Constants
39
31
  VERSION
40
- The version number of this package, returned as a String.
32
+ The version number of this library, returned as a String.
41
33
 
42
34
  == Class Methods
43
35
  Ping::TNS.new(db, driver="OCI8", host=nil, port=1521, timeout=5)
@@ -165,7 +157,7 @@ Ping::TNS#tns_file=(path)
165
157
  more reliable solution.
166
158
 
167
159
  == Known Bugs
168
- None that I'm aware of. Please log any bug reports on the project page
160
+ None that I'm aware of. Please log any bug reports on the project page
169
161
  at http://www.rubyforge.org/projects/shards
170
162
 
171
163
  == Acknowledgements
@@ -173,7 +165,7 @@ Ping::TNS#tns_file=(path)
173
165
  with some questions I had.
174
166
 
175
167
  == Copyright
176
- (C) 2003-2009 Daniel J. Berger
168
+ (C) 2003-2011 Daniel J. Berger
177
169
  All rights reserved.
178
170
 
179
171
  == Warranty
@@ -186,5 +178,3 @@ Ping::TNS#tns_file=(path)
186
178
 
187
179
  == Author
188
180
  Daniel J. Berger
189
- djberg96 at nospam at gmail dot com
190
- imperator on IRC (irc.freenode.net)
data/Rakefile CHANGED
@@ -1,24 +1,31 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
-
4
- desc "Install the net-tnsping library (non-gem)"
5
- task :install do
6
- dest = File.join(Config::CONFIG['sitelibdir'], 'net')
7
- Dir.mkdir(dest) unless File.exists? dest
8
- cp 'lib/net/tnsping.rb', dest, :verbose => true
9
- end
10
-
11
- desc "Install the net-tnsping library as a gem"
12
- task :install_gem do
13
- ruby 'net-tnsping.gemspec'
14
- file = Dir["*.gem"].first
15
- sh "gem install #{file}"
16
- end
17
-
18
- desc "Run the example program"
19
- task :example do |dsn|
20
- ruby "-Ilib examples/example_tnsping.rb #{dsn}"
21
-
22
- Rake::TestTask.new do |t|
23
- t.warning = true
24
- end
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+
5
+ CLEAN.include("**/*.gem", "**/*.rbc", "**/*.log")
6
+
7
+ namespace :gem do
8
+ desc "Create the net-tnsping gem"
9
+ task :create => [:clean] do
10
+ spec = eval(IO.read('net-tnsping.gemspec'))
11
+ Gem::Builder.new(spec).build
12
+ end
13
+
14
+ desc "Install the net-tnsping gem"
15
+ task :install => [:create] do
16
+ file = Dir['*.gem'].first
17
+ sh "gem install #{file}"
18
+ end
19
+ end
20
+
21
+ desc "Run the example program"
22
+ task :example do |dsn|
23
+ ruby "-Ilib examples/example_tnsping.rb #{dsn}"
24
+ end
25
+
26
+ Rake::TestTask.new do |t|
27
+ t.warning = true
28
+ t.verbose = true
29
+ end
30
+
31
+ task :default => :test
@@ -4,243 +4,251 @@ require 'net/ping'
4
4
  # The Net module serves as a namespace only.
5
5
  module Net
6
6
 
7
- # The Ping::TNS class encapsulates the information and behavior of tns ping.
8
- class Ping::TNS < Ping::TCP
9
-
10
- # The error class typically raised if any of the Ping::TNS methods fail.
11
- class Error < StandardError; end
12
-
13
- # The version of the net-tnsping library.
14
- VERSION = '1.3.1'
15
-
16
- # Database name.
17
- attr_accessor :db
18
-
19
- # Database source name.
20
- attr_accessor :dsn
21
-
22
- # The full path to the tnsnames.ora file.
23
- attr_accessor :tns_file
24
-
25
- # The name of the host the database sits on.
26
- attr_accessor :host
27
-
28
- # The toplevel tns admin path.
29
- attr_accessor :tns_admin
30
-
31
- # The value of your ORACLE_HOME or ORA_HOME environment variable.
32
- attr_accessor :ora_home
33
-
34
- # The name of the oracle driver to use for connections. Defaults to OCI8.
35
- attr_accessor :driver
36
-
37
- # The timeout value for connection attempts. The default is 5 seconds.
38
- attr_accessor :timeout
39
-
40
- # A list of hosts for the given database name.
41
- attr_reader :hosts
42
-
43
- # A list of ports for the given database name
44
- attr_reader :ports
45
-
46
- # The port used when attempting a connection. The default is 1521.
47
- attr_reader :port
48
-
49
- # Creates and returns a new Ping::TNS object. If the db specified cannot
50
- # be found in the tnsnames.ora file, then a Ping::TNS::Error is raised.
51
- #
52
- def initialize(db, driver='OCI8', host=nil, port=1521, timeout=5)
53
- @db = db
54
- @dsn = "dbi:#{driver}:" << db
55
- @host = host
56
- @timeout = timeout
57
- @port = port
58
- @tns_admin = tns_admin
59
- @ports = [] # There can be more than one host/port
60
- @hosts = [] # for each dsn. Try them in order.
61
- @sid = nil
62
-
63
- @tns_admin = ENV['TNS_ADMIN']
64
- @ora_home = ENV['ORACLE_HOME'] || ENV['ORA_HOME']
65
-
66
- if @tns_admin
67
- @tns_file = File.join(@tns_admin, 'tnsnames.ora')
68
- elsif @ora_home
69
- @tns_file = File.join(@ora_home, 'network', 'admin', 'tnsnames.ora')
70
- else
71
- @tns_file = File.join((ENV['HOME'] || ENV['USERPROFILE']), 'tnsnames.ora')
72
- end
73
-
74
- yield self if block_given?
75
-
76
- # If the host is not specified, look for it in the tnsnames.ora file
77
- if host.nil?
78
- err_msg = "tnsnames.ora file could not be found"
79
- raise Error, err_msg unless File.exists?(@tns_file)
80
- parse_tns_file
81
- else
82
- @hosts.push(host)
83
- @ports.push(port)
84
- end
85
- end
7
+ # The Ping::TNS class encapsulates the information and behavior of tns ping.
8
+ class Ping::TNS < Ping::TCP
9
+
10
+ # The error class typically raised if any of the Ping::TNS methods fail.
11
+ class Error < StandardError; end
12
+
13
+ # The version of the net-tnsping library.
14
+ VERSION = '1.3.2'
15
+
16
+ # Database name.
17
+ attr_accessor :database
18
+
19
+ # Database source name.
20
+ attr_accessor :dsn
21
+
22
+ # The full path to the tnsnames.ora file.
23
+ attr_accessor :tns_file
24
+
25
+ # The name of the host the database sits on.
26
+ attr_accessor :host
27
+
28
+ # The toplevel tns admin path.
29
+ attr_accessor :tns_admin
30
+
31
+ # The value of your ORACLE_HOME or ORA_HOME environment variable.
32
+ attr_accessor :ora_home
86
33
 
87
- # Sets the port that the Ping::TNS#ping_listener? method will use. If
88
- # this is set, then a ping will only be attempted on this port,
89
- # regardless of what is in the tnsnames.ora file.
90
- #
91
- def port=(num)
92
- @port = num
93
- @ports = [num]
34
+ # The name of the oracle driver to use for connections. Defaults to OCI8.
35
+ attr_accessor :driver
36
+
37
+ # A list of hosts for the given database name.
38
+ attr_reader :hosts
39
+
40
+ # A list of ports for the given database name
41
+ attr_reader :ports
42
+
43
+ # The port used when attempting a connection. The default is 1521.
44
+ attr_reader :port
45
+
46
+ # Creates and returns a new Ping::TNS object. If the db specified cannot
47
+ # be found in the tnsnames.ora file, then a Ping::TNS::Error is raised.
48
+ #
49
+ def initialize(database, driver='OCI8', host=nil, port=1521, timeout=5)
50
+ @database = database
51
+ @dsn = "dbi:#{driver}:" << database
52
+ @host = host
53
+ @timeout = timeout
54
+ @port = port
55
+ @driver = driver
56
+ @ports = [] # There can be more than one host/port
57
+ @hosts = [] # for each dsn. Try them in order.
58
+ @sid = nil
59
+
60
+ @tns_admin = ENV['TNS_ADMIN']
61
+ @ora_home = ENV['ORACLE_HOME'] || ENV['ORA_HOME']
62
+
63
+ if @tns_admin
64
+ @tns_file = File.join(@tns_admin, 'tnsnames.ora')
65
+ elsif @ora_home
66
+ @tns_file = File.join(@ora_home, 'network', 'admin', 'tnsnames.ora')
67
+ else
68
+ home = ENV['HOME'] || ENV['USERPROFILE']
69
+ @tns_file = File.join(home, 'tnsnames.ora')
94
70
  end
95
71
 
96
- # Performs a TCP ping on the listener. The host and port are determined from
97
- # your tnsnames.ora file. If more than one host and/or port are found in the
98
- # tnsnames.ora file, then each will be tried. So long as at least one of
99
- # them connects successfully, true is returned.
100
- #
101
- # If you specify a host and port in the constructor, then the attempt will
102
- # only be made against that host on the given port.
103
- #--
104
- # Try each host/port listed for a given entry. Return a true result if
105
- # any one of them succeeds and break out of the loop.
106
- #
107
- def ping?
108
- if @hosts.empty?
109
- raise Error, "No hosts found"
110
- end
111
-
112
- # Use 1521 if no ports were found in the tnsnames.ora file.
113
- if @ports.empty?
114
- @ports.push(@port)
115
- end
116
-
117
- # If the host is provided, only ping that host
118
- if @host
119
- 0.upto(@ports.length-1){ |n|
120
- @port = @ports[n]
121
- return super
122
- }
123
- else
124
- 0.upto(@ports.length-1){ |n|
125
- @port = @ports[n]
126
- @host = @hosts[n]
127
- return super
128
- }
129
- end
72
+ yield self if block_given?
73
+
74
+ # If the host is not specified, look for it in the tnsnames.ora file
75
+ if host.nil?
76
+ err_msg = "tnsnames.ora file could not be found"
77
+ raise Error, err_msg unless File.exists?(@tns_file)
78
+ parse_tns_file
79
+ else
80
+ @hosts.push(host)
81
+ @ports.push(port)
82
+ end
83
+ end
84
+
85
+ # Sets the port that the Ping::TNS#ping_listener? method will use. If
86
+ # this is set, then a ping will only be attempted on this port
87
+ # regardless of what is in the tnsnames.ora file.
88
+ #
89
+ def port=(num)
90
+ @port = num
91
+ @ports = [num]
92
+ end
93
+
94
+ # Performs a TCP ping on the listener. The host and port are determined from
95
+ # your tnsnames.ora file. If more than one host and/or port are found in the
96
+ # tnsnames.ora file, then each will be tried. So long as at least one of
97
+ # them connects successfully, true is returned.
98
+ #
99
+ # If you specify a host and port in the constructor, then the attempt will
100
+ # only be made against that host on the given port.
101
+ #
102
+ # Remember, this only pings the listener. If you want to ping the listener
103
+ # and the database, use the ping_all? method.
104
+ #--
105
+ # Try each host/port listed for a given entry. Return a true result if
106
+ # any one of them succeeds and break out of the loop.
107
+ #
108
+ def ping?
109
+ if @hosts.empty?
110
+ raise Error, "No hosts found"
130
111
  end
131
112
 
132
- # Attempts to make a connection using a bogus login and password via the
133
- # DBI class. If an ORA-01017 Oracle error is returned, that means the
134
- # database is up and running and true is returned.
135
- #
136
- # Note that each of the arguments for this method use the defaults
137
- # passed to the constructor (or have a default otherwise set). You
138
- # generally should not pass any arguments to this method.
139
- # In the event that this method fails, false is returned and the error
140
- # can be viewed via Ping::TNS#exception.
141
- #--
142
- # I have intentionally set the user and password to something random in
143
- # order to avoid the possibility of accidentally guessing them. In
144
- # case of cosmic coincidence, set them yourself.
145
- #
146
- def ping_database?(dsn=@dsn, timeout=@timeout, user=@sid, passwd=Time.now.to_s)
147
- re = /ORA-01017/
148
- dbh = nil
149
- user ||= Time.now.to_s
150
- rv = false
151
- begin
152
- Timeout.timeout(timeout){
153
- dbh = DBI.connect(dsn,user,passwd)
154
- }
155
- rescue DBI::DatabaseError => e
156
- if re.match(e.to_s)
157
- rv = true
158
- else
159
- @exception = e
160
- end
161
- rescue Timeout::Error, StandardError => e
162
- @exception = e
163
- ensure
164
- if dbh
165
- dbh.disconnect if dbh.connected?
166
- end
167
- end
168
- rv
113
+ # Use 1521 if no ports were found in the tnsnames.ora file.
114
+ if @ports.empty?
115
+ @ports.push(@port)
169
116
  end
170
117
 
171
- # Simple wrapper for ping_listener? + ping_database?
172
- #
173
- def ping_all?
174
- return false unless self.ping_listener?
175
- return false unless self.ping_database?
176
- true
118
+ # If the host is provided, only ping that host
119
+ if @host
120
+ 0.upto(@ports.length-1){ |n|
121
+ @port = @ports[n]
122
+ return super
123
+ }
124
+ else
125
+ 0.upto(@ports.length-1){ |n|
126
+ @port = @ports[n]
127
+ @host = @hosts[n]
128
+ return super
129
+ }
130
+ end
131
+ end
132
+
133
+ # Attempts to make a connection using a bogus login and password via the
134
+ # DBI class. If an ORA-01017 Oracle error is returned, that means the
135
+ # database is up and running and true is returned.
136
+ #
137
+ # Note that each of the arguments for this method use the defaults
138
+ # passed to the constructor (or have a default otherwise set). You
139
+ # generally should not pass any arguments to this method.
140
+ # In the event that this method fails, false is returned and the error
141
+ # can be viewed via Ping::TNS#exception.
142
+ #--
143
+ # I have intentionally set the user and password to something random in
144
+ # order to avoid the possibility of accidentally guessing them. In
145
+ # case of cosmic coincidence, set them yourself.
146
+ #
147
+ def ping_database?(dsn=@dsn, timeout=@timeout, user=@sid, passwd=Time.now.to_s)
148
+ re = /ORA-01017/
149
+ dbh = nil
150
+ user ||= Time.now.to_s
151
+ rv = false
152
+
153
+ begin
154
+ Timeout.timeout(timeout){
155
+ dbh = DBI.connect(dsn,user,passwd)
156
+ }
157
+ rescue DBI::DatabaseError => e
158
+ if re.match(e.to_s)
159
+ rv = true
160
+ else
161
+ @exception = e
162
+ end
163
+ rescue Timeout::Error, StandardError => e
164
+ @exception = e
165
+ ensure
166
+ if dbh
167
+ dbh.disconnect if dbh.connected?
168
+ end
177
169
  end
178
170
 
179
- private
180
-
181
- # parse_tns_file
182
- #
183
- # Search for the dsn entry within the tnsnames.ora file and get the host
184
- # and port information. Private method.
185
- #
186
- def parse_tns_file(file=@tns_file, db=@db)
187
- re_blank = /^$/
188
- re_comment = /^#/
189
- re_tns_sentry = /^#{db}.*?=/ # specific entry
190
- re_tns_gentry = /^\w.*?=/ # generic entry
191
- re_tns_pair = /\w+\s*\=\s*[\w\.]+/ # used to parse key=val
192
- re_keys = /\bhost\b|\bport\b|\bsid\b/i
193
-
194
- data_string = ""
195
- found = false
196
-
197
- IO.foreach(file){ |line|
198
- next if re_blank.match(line)
199
- next if re_comment.match(line)
200
- line.chomp!
201
-
202
- # Skip over lines until an entry for the db is found.
203
- match = re_tns_sentry.match(line)
204
- if match
205
- found = true
206
- data_string << match.post_match # slurp the rest of the line
207
- next
208
- end
209
-
210
- # Once found, slurp the lines into a variable until the next
211
- # db entry is encountered.
212
- if found
213
- break if re_tns_gentry.match(line)
214
- line.strip!
215
- data_string << line
216
- end
217
- }
218
-
219
- unless found
220
- raise Error, "unable to find '#{db}' in #{file}"
221
- end
222
-
223
- # Break each 'key = value' line into its parts
224
- data_string.scan(re_tns_pair).each{ |pair|
225
- key, value = pair.split("=")
226
- key.strip!
227
- value.strip!
228
- next unless re_keys.match(key)
229
- case key.downcase
230
- when 'host'
231
- @hosts.push(value)
232
- when 'port'
233
- @ports.push(value.to_i)
234
- when 'sid'
235
- @sid = value
236
- end
237
- }
171
+ rv
172
+ end
173
+
174
+ # Simple wrapper for ping_listener? + ping_database?
175
+ #
176
+ def ping_all?
177
+ return false unless self.ping_listener?
178
+ return false unless self.ping_database?
179
+ true
180
+ end
181
+
182
+ private
183
+
184
+ # parse_tns_file
185
+ #
186
+ # Search for the dsn entry within the tnsnames.ora file and get the host
187
+ # and port information. Private method.
188
+ #
189
+ def parse_tns_file(file=@tns_file, db=@database)
190
+ re_blank = /^$/
191
+ re_comment = /^#/
192
+ re_tns_sentry = /^#{db}.*?=/i # specific entry
193
+ re_tns_gentry = /^\w.*?=/ # generic entry
194
+ re_tns_pair = /\w+\s*\=\s*[\w\.]+/ # used to parse key=val
195
+ re_keys = /\bhost\b|\bport\b|\bsid\b/i
196
+
197
+ data_string = ""
198
+ found = false
199
+
200
+ IO.foreach(file){ |line|
201
+ next if re_blank.match(line)
202
+ next if re_comment.match(line)
203
+ line.chomp!
204
+
205
+ # Skip over lines until an entry for the db is found.
206
+ match = re_tns_sentry.match(line)
207
+
208
+ if match
209
+ found = true
210
+ data_string << match.post_match # slurp the rest of the line
211
+ next
212
+ end
213
+
214
+ # Once found, slurp the lines into a variable until the next
215
+ # db entry is encountered.
216
+ if found
217
+ break if re_tns_gentry.match(line)
218
+ line.strip!
219
+ data_string << line
220
+ end
221
+ }
222
+
223
+ unless found
224
+ raise Error, "unable to find '#{db}' in #{file}"
238
225
  end
239
226
 
240
- alias database db
241
- alias database_source_name dsn
242
- alias ping_listener? ping?
243
- alias oracle_home ora_home
244
- alias oracle_home= ora_home=
245
- end
227
+ # Break each 'key = value' line into its parts
228
+ data_string.scan(re_tns_pair).each{ |pair|
229
+ key, value = pair.split("=")
230
+ key.strip!
231
+ value.strip!
232
+
233
+ next unless re_keys.match(key)
234
+
235
+ case key.downcase
236
+ when 'host'
237
+ @hosts.push(value)
238
+ when 'port'
239
+ @ports.push(value.to_i)
240
+ when 'sid'
241
+ @sid = value
242
+ end
243
+ }
244
+ end
245
+
246
+ # Aliases
247
+
248
+ alias db database
249
+ alias database_source_name dsn
250
+ alias ping_listener? ping?
251
+ alias oracle_home ora_home
252
+ alias oracle_home= ora_home=
253
+ end
246
254
  end
@@ -1,30 +1,27 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'net-tnsping'
5
- gem.version = '1.3.1'
6
- gem.license = 'Artistic 2.0'
7
- gem.author = 'Daniel J. Berger'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/shards'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'A library for pinging Oracle listeners and databases'
12
- gem.test_file = 'test/test_net_tnsping.rb'
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'net-tnsping'
5
+ spec.version = '1.3.2'
6
+ spec.license = 'Artistic 2.0'
7
+ spec.author = 'Daniel J. Berger'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/shards'
10
+ spec.summary = 'A library for pinging Oracle listeners and databases'
11
+ spec.test_file = 'test/test_net_tnsping.rb'
12
+ spec.has_rdoc = true
13
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
14
 
16
- gem.rubyforge_project = 'shards'
17
- gem.extra_rdoc_files = ['CHANGES', 'MANIFEST', 'README']
15
+ spec.rubyforge_project = 'shards'
16
+ spec.extra_rdoc_files = ['CHANGES', 'MANIFEST', 'README']
18
17
 
19
- gem.add_dependency('net-ping', '>= 1.0.0')
20
- gem.add_development_dependency('test-unit', '>= 2.0.3')
18
+ spec.add_dependency('net-ping', '>= 1.4.0')
19
+ spec.add_development_dependency('test-unit', '>= 2.1.2')
21
20
 
22
- gem.description = <<-EOF
23
- The net-tnsping library provides a way to ping Oracle databases and
24
- ensure that they're up and running. Unlike the tnsping command line
25
- program, which only pings the listener, the net-tnsping library
26
- pings both the listener and the database itself.
27
- EOF
21
+ spec.description = <<-EOF
22
+ The net-tnsping library provides a way to ping Oracle databases and
23
+ ensure that they're up and running. Unlike the tnsping command line
24
+ program, which only pings the listener, the net-tnsping library
25
+ pings both the listener and the database itself.
26
+ EOF
28
27
  end
29
-
30
- Gem::Builder.new(spec).build
@@ -9,150 +9,205 @@ gem 'test-unit'
9
9
 
10
10
  require 'test/unit'
11
11
  require 'net/tnsping'
12
- include Net
13
12
 
14
13
  class TC_TNS_Ping < Test::Unit::TestCase
15
- def self.startup
16
- @@database = 'change_me' # Change to a valid host name
17
- @@hostname = Socket.gethostname
18
- end
19
-
20
- def setup
21
- if @@database == 'change_me'
22
- @tnsp = Ping::TNS.new(@@database, 'OCI8', @@hostname)
23
- else
24
- @tnsp = Ping::TNS.new(@@database)
25
- end
26
- end
27
-
28
- def test_version
29
- assert_equal('1.3.1', Ping::TNS::VERSION)
30
- end
31
-
32
- def test_db_get
33
- assert_respond_to(@tnsp, :db)
34
- assert_nothing_raised{ @tnsp.db }
35
- assert_equal(@@database, @tnsp.db)
36
- end
37
-
38
- def test_db_set
39
- assert_respond_to(@tnsp, :db=)
40
- assert_nothing_raised{ @tnsp.db = 'fubar' }
41
- assert_equal('fubar', @tnsp.db)
42
- end
43
-
44
- def test_dsn_get
45
- assert_respond_to(@tnsp, :dsn)
46
- assert_nothing_raised{ @tnsp.dsn }
47
- assert_equal("dbi:OCI8:#{@@database}", @tnsp.dsn)
48
- end
49
-
50
- def test_dsn_set
51
- assert_respond_to(@tnsp, :dsn=)
52
- assert_nothing_raised{ @tnsp.dsn = 'dbi:OCI8:fubar' }
53
- assert_equal('dbi:OCI8:fubar', @tnsp.dsn)
54
- end
55
-
56
- def test_port_get
57
- assert_respond_to(@tnsp, :port)
58
- assert_equal(1521, @tnsp.port)
59
- end
60
-
61
- def test_port_set
62
- assert_respond_to(@tnsp, :port=)
63
- assert_nothing_raised{ @tnsp.port = 1555 }
64
- assert_equal(1555, @tnsp.port)
65
- end
66
-
67
- def test_ports
68
- assert_respond_to(@tnsp, :ports)
69
- assert_kind_of(Array, @tnsp.ports)
70
- assert(@tnsp.ports.length > 0)
71
- end
72
-
73
- def test_host_get
74
- assert_respond_to(@tnsp, :host)
75
- assert_equal(@@hostname, @tnsp.host)
76
- end
77
-
78
- def test_host_set
79
- assert_respond_to(@tnsp, :host=)
80
- assert_nothing_raised{ @tnsp.host = 'fubar' }
81
- assert_equal('fubar', @tnsp.host)
82
- end
83
-
84
- def tests_hosts
85
- assert_respond_to(@tnsp, :hosts)
86
- assert_kind_of(Array, @tnsp.hosts)
87
- assert(@tnsp.hosts.length > 0)
88
- end
89
-
90
- def test_tns_file_get
91
- assert_respond_to(@tnsp, :tns_file)
92
- omit_if(@@database == 'change_me', 'tns_file test skipped without real database')
93
- assert_true(File.exist?(@tnsp.tns_file))
94
- end
95
-
96
- def test_tns_file_set
97
- assert_respond_to(@tnsp, :tns_file=)
98
- assert_nothing_raised{ @tnsp.tns_file = 'fu_tnsnames.ora' }
99
- assert_equal('fu_tnsnames.ora', @tnsp.tns_file)
100
- end
101
-
102
- def test_oracle_home_get
103
- assert_respond_to(@tnsp, :oracle_home)
104
- assert_kind_of([String, NilClass], @tnsp.oracle_home)
105
- end
106
-
107
- def test_oracle_home_set
108
- assert_respond_to(@tnsp, :oracle_home=)
109
- assert_nothing_raised{ @tnsp.oracle_home = ENV['HOME'] }
110
- assert_equal(ENV['HOME'], @tnsp.oracle_home)
111
- end
112
-
113
- def test_tns_admin_get
114
- assert_respond_to(@tnsp, :tns_admin)
115
- assert_kind_of([String, NilClass], @tnsp.tns_admin)
116
- end
117
-
118
- def test_tns_admin_set
119
- assert_respond_to(@tnsp, :tns_admin=)
120
- assert_nothing_raised{ @tnsp.tns_admin = ENV['HOME'] }
121
- assert_equal(ENV['HOME'], @tnsp.tns_admin)
122
- end
123
-
124
- def test_ping_listener
125
- assert_respond_to(@tnsp, :ping?)
126
- assert_nothing_raised{ @tnsp.ping? }
127
- omit_if(@@database == 'change_me', 'ping listener test skipped without real database')
128
- assert_equal(true, @tnsp.ping?)
129
- end
130
-
131
- def test_ping_database
132
- assert_respond_to(@tnsp, :ping_database?)
133
- assert_nothing_raised{ @tnsp.ping_database? }
134
- omit_if(@@database == 'change_me', 'ping database test skipped without real database')
135
- assert_equal(true, @tnsp.ping_database?)
136
- end
137
-
138
- def test_ping_all
139
- assert_respond_to(@tnsp, :ping_all?)
140
- assert_nothing_raised{ @tnsp.ping_all? }
141
- omit_if(@@database == 'change_me', 'ping all test skipped without real database')
142
- assert_equal(true, @tnsp.ping_all?)
143
- end
144
-
145
- def test_bad_db
146
- assert_raises(Ping::TNS::Error){ Ping::TNS.new('bogus_db') }
147
- @tnsp.port = 9999
148
- assert_equal(false, @tnsp.ping_listener?)
149
- end
150
-
151
- def teardown
152
- @tnsp = nil
153
- end
154
-
155
- def self.shutdown
156
- @@database = nil
157
- end
14
+ def self.startup
15
+ @@database = 'xe'
16
+ @@username = 'hr'
17
+ @@password = 'hr'
18
+ @@hostname = Socket.gethostname
19
+ end
20
+
21
+ def setup
22
+ @tnsp = Net::Ping::TNS.new(@@database)
23
+ end
24
+
25
+ test "version number is expected value" do
26
+ assert_equal('1.3.2', Net::Ping::TNS::VERSION)
27
+ end
28
+
29
+ test "database reader basic functionality" do
30
+ assert_respond_to(@tnsp, :database)
31
+ assert_nothing_raised{ @tnsp.database }
32
+ assert_equal(@@database, @tnsp.database)
33
+ end
34
+
35
+ test "db is an alias for database" do
36
+ assert_respond_to(@tnsp, :db)
37
+ assert_alias_method(@tnsp, :db, :database)
38
+ end
39
+
40
+ test "database writer basic functionality" do
41
+ assert_respond_to(@tnsp, :database=)
42
+ assert_nothing_raised{ @tnsp.database = 'fubar' }
43
+ assert_equal('fubar', @tnsp.database)
44
+ end
45
+
46
+ test "dsn reader basic functionality" do
47
+ assert_respond_to(@tnsp, :dsn)
48
+ assert_nothing_raised{ @tnsp.dsn }
49
+ assert_equal("dbi:OCI8:#{@@database}", @tnsp.dsn)
50
+ end
51
+
52
+ test "database_source_name is an alias for dsn" do
53
+ assert_respond_to(@tnsp, :database_source_name)
54
+ assert_alias_method(@tnsp, :database_source_name, :dsn)
55
+ end
56
+
57
+ test "dsn writer basic functionality" do
58
+ assert_respond_to(@tnsp, :dsn=)
59
+ assert_nothing_raised{ @tnsp.dsn = 'dbi:OCI8:fubar' }
60
+ assert_equal('dbi:OCI8:fubar', @tnsp.dsn)
61
+ end
62
+
63
+ test "port reader basic functionality" do
64
+ assert_respond_to(@tnsp, :port)
65
+ assert_equal(1521, @tnsp.port)
66
+ end
67
+
68
+ test "port writer basic functionality" do
69
+ assert_respond_to(@tnsp, :port=)
70
+ assert_nothing_raised{ @tnsp.port = 1555 }
71
+ assert_equal(1555, @tnsp.port)
72
+ end
73
+
74
+ test "ports reader basic functionality" do
75
+ assert_respond_to(@tnsp, :ports)
76
+ assert_kind_of(Array, @tnsp.ports)
77
+ assert(@tnsp.ports.length > 0)
78
+ end
79
+
80
+ test "host reader basic functionality" do
81
+ assert_respond_to(@tnsp, :host)
82
+ assert_nil(@tnsp.host)
83
+ end
84
+
85
+ test "host writer basic functionality" do
86
+ assert_respond_to(@tnsp, :host=)
87
+ assert_nothing_raised{ @tnsp.host = 'fubar' }
88
+ assert_equal('fubar', @tnsp.host)
89
+ end
90
+
91
+ test "hosts reader basic functionality" do
92
+ assert_respond_to(@tnsp, :hosts)
93
+ assert_kind_of(Array, @tnsp.hosts)
94
+ assert(@tnsp.hosts.length > 0)
95
+ end
96
+
97
+ test "there is no hosts writer method" do
98
+ assert_raise(NoMethodError){ @tnsp.hosts = %w[foo bar] }
99
+ end
100
+
101
+ test "tns_file reader basic functionality" do
102
+ assert_respond_to(@tnsp, :tns_file)
103
+ assert_kind_of(String, @tnsp.tns_file)
104
+ assert_true(File.exist?(@tnsp.tns_file))
105
+ end
106
+
107
+ test "tns_file writer basic functionality" do
108
+ assert_respond_to(@tnsp, :tns_file=)
109
+ assert_nothing_raised{ @tnsp.tns_file = 'fu_tnsnames.ora' }
110
+ assert_equal('fu_tnsnames.ora', @tnsp.tns_file)
111
+ end
112
+
113
+ test "oracle_home reader basic functionality" do
114
+ assert_respond_to(@tnsp, :oracle_home)
115
+ assert_kind_of([String, NilClass], @tnsp.oracle_home)
116
+ end
117
+
118
+ test "ora_home is an alias for oracle_home" do
119
+ assert_respond_to(@tnsp, :ora_home)
120
+ assert_alias_method(@tnsp, :ora_home, :oracle_home)
121
+ end
122
+
123
+ test "oracle_home writer basic functionality" do
124
+ assert_respond_to(@tnsp, :oracle_home=)
125
+ assert_nothing_raised{ @tnsp.oracle_home = ENV['HOME'] }
126
+ assert_equal(ENV['HOME'], @tnsp.oracle_home)
127
+ end
128
+
129
+ test "ora_home= is an alias for oracle_home=" do
130
+ assert_respond_to(@tnsp, :ora_home=)
131
+ assert_alias_method(@tnsp, :ora_home=, :oracle_home=)
132
+ end
133
+
134
+ test "tns_admin reader basic functionality" do
135
+ assert_respond_to(@tnsp, :tns_admin)
136
+ assert_kind_of([String, NilClass], @tnsp.tns_admin)
137
+ end
138
+
139
+ test "tns_admin writer basic functionality" do
140
+ assert_respond_to(@tnsp, :tns_admin=)
141
+ assert_nothing_raised{ @tnsp.tns_admin = ENV['HOME'] }
142
+ assert_equal(ENV['HOME'], @tnsp.tns_admin)
143
+ end
144
+
145
+ test "timeout reader basic functionality" do
146
+ assert_respond_to(@tnsp, :timeout)
147
+ assert_kind_of(Fixnum, @tnsp.timeout)
148
+ end
149
+
150
+ test "timeout writer basic functionality" do
151
+ assert_respond_to(@tnsp, :timeout=)
152
+ assert_nothing_raised{ @tnsp.timeout = 10 }
153
+ assert_equal(10, @tnsp.timeout)
154
+ end
155
+
156
+ test "driver reader basic functionality" do
157
+ assert_respond_to(@tnsp, :driver)
158
+ assert_kind_of(String, @tnsp.driver)
159
+ end
160
+
161
+ test "driver writer basic functionality" do
162
+ assert_respond_to(@tnsp, :driver=)
163
+ assert_nothing_raised{ @tnsp.driver = "oracle" }
164
+ assert_equal("oracle", @tnsp.driver)
165
+ end
166
+
167
+ test "ping_listener? basic functionality" do
168
+ assert_respond_to(@tnsp, :ping_listener?)
169
+ assert_nothing_raised{ @tnsp.ping_listener? }
170
+ end
171
+
172
+ test "ping_listener? returns a boolean value" do
173
+ assert_boolean(@tnsp.ping_listener?)
174
+ end
175
+
176
+ test "ping? is an alias for ping_listener?" do
177
+ end
178
+
179
+ test "ping_database? basic functionality" do
180
+ assert_respond_to(@tnsp, :ping_database?)
181
+ assert_nothing_raised{ @tnsp.ping_database? }
182
+ end
183
+
184
+ test "ping_database? returns a boolean value" do
185
+ assert_boolean(@tnsp.ping_database?)
186
+ end
187
+
188
+ test "ping_all? basic functionality" do
189
+ assert_respond_to(@tnsp, :ping_all?)
190
+ assert_nothing_raised{ @tnsp.ping_all? }
191
+ end
192
+
193
+ test "ping_all? returns a boolean value" do
194
+ assert_boolean(@tnsp.ping_all?)
195
+ end
196
+
197
+ test "ping fails against a bogus database" do
198
+ assert_raises(Net::Ping::TNS::Error){ Net::Ping::TNS.new('bogus_db') }
199
+ @tnsp.port = 9999
200
+ assert_false(@tnsp.ping_listener?)
201
+ end
202
+
203
+ def teardown
204
+ @tnsp = nil
205
+ end
206
+
207
+ def self.shutdown
208
+ @@username = nil
209
+ @@password = nil
210
+ @@database = nil
211
+ @@hostname = nil
212
+ end
158
213
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-tnsping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 2
10
+ version: 1.3.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Daniel J. Berger
@@ -9,30 +15,42 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-08-08 00:00:00 -06:00
18
+ date: 2011-03-01 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: net-ping
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: 1.0.0
24
- version:
29
+ hash: 7
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 0
34
+ version: 1.4.0
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: test-unit
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
33
- version: 2.0.3
34
- version:
35
- description: " The net-tnsping library provides a way to ping Oracle databases and\n ensure that they're up and running. Unlike the tnsping command line\n program, which only pings the listener, the net-tnsping library\n pings both the listener and the database itself.\n"
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 1
49
+ - 2
50
+ version: 2.1.2
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: " The net-tnsping library provides a way to ping Oracle databases and\n ensure that they're up and running. Unlike the tnsping command line\n program, which only pings the listener, the net-tnsping library\n pings both the listener and the database itself.\n"
36
54
  email: djberg96@gmail.com
37
55
  executables: []
38
56
 
@@ -43,14 +61,14 @@ extra_rdoc_files:
43
61
  - MANIFEST
44
62
  - README
45
63
  files:
46
- - CHANGES
47
- - examples/example_tnsping.rb
48
- - lib/net/tnsping.rb
49
- - MANIFEST
50
- - net-tnsping.gemspec
51
64
  - Rakefile
52
65
  - README
66
+ - net-tnsping.gemspec
67
+ - lib/net/tnsping.rb
68
+ - CHANGES
69
+ - examples/example_tnsping.rb
53
70
  - test/test_net_tnsping.rb
71
+ - MANIFEST
54
72
  has_rdoc: true
55
73
  homepage: http://www.rubyforge.org/projects/shards
56
74
  licenses:
@@ -61,21 +79,27 @@ rdoc_options: []
61
79
  require_paths:
62
80
  - lib
63
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
64
83
  requirements:
65
84
  - - ">="
66
85
  - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
67
89
  version: "0"
68
- version:
69
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
70
92
  requirements:
71
93
  - - ">="
72
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
73
98
  version: "0"
74
- version:
75
99
  requirements: []
76
100
 
77
101
  rubyforge_project: shards
78
- rubygems_version: 1.3.5
102
+ rubygems_version: 1.3.7
79
103
  signing_key:
80
104
  specification_version: 3
81
105
  summary: A library for pinging Oracle listeners and databases