spqr 0.0.2 → 0.0.4

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.
data/CHANGES ADDED
@@ -0,0 +1,26 @@
1
+ version 0.0.4 (180897a77b55400b31d364a08cb9f81c423eb59f)
2
+
3
+ * Test suite is mainly stable (individual tests will sometimes hang
4
+ upon creating a QMF agent).
5
+ * This is probably the last version before I change the method call API.
6
+
7
+ version 0.0.3 (060c7b5bcaa2711b3e3ce511c9c3ecaa59bf0de8)
8
+
9
+ * Agent-ready callback and parent-process notification (app.rb)
10
+ * The beginnings of an SPQR test suite
11
+
12
+ version 0.0.2 (ecd94b141307c5f0f141833836ea686854cfda9c)
13
+
14
+ * First shaky pass at automated RPM packaging (see rpmspec and
15
+ srpm rake targets)
16
+ * Automatic find_all methods for Rhubarb persisting classes
17
+
18
+ version 0.0.1 (0714a87f30469772fc302515e95576e329f7deb9)
19
+
20
+ * Gem support
21
+ * Codegen fixes
22
+
23
+ version 0.0.0 (bbbc2e9d6983f773f6d093a821a0e635714ea869)
24
+
25
+ * Initial numbered release; corresponds roughly to the functionality
26
+ from the "Introducing SPQR" blog posts, but with an added Rakefile.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.4
data/lib/spqr/app.rb CHANGED
@@ -21,7 +21,7 @@ module SPQR
21
21
  class ClassMeta < Struct.new(:object_class, :schema_class) ; end
22
22
 
23
23
  def initialize(options=nil)
24
- defaults = {:logfile=>STDERR, :loglevel=>Logger::WARN}
24
+ defaults = {:logfile=>STDERR, :loglevel=>Logger::WARN, :notifier=>nil}
25
25
 
26
26
  # convenient shorthands for log levels
27
27
  loglevels = {:debug => Logger::DEBUG, :info => Logger::INFO, :warn => Logger::WARN, :error => Logger::ERROR, :fatal => Logger::FATAL}
@@ -43,6 +43,9 @@ module SPQR
43
43
 
44
44
  @classes_by_name = {}
45
45
  @classes_by_id = {}
46
+ @pipe = options[:notifier]
47
+ @app_name = (options[:appname] or "SPQR application")
48
+
46
49
  end
47
50
 
48
51
  def register(*ks)
@@ -100,7 +103,7 @@ module SPQR
100
103
  end
101
104
 
102
105
  def get_query(context, query, user_id)
103
- @log.debug "query: user=#{user_id} context=#{context} class=#{query.class_name} object_num=#{query.object_id.object_num_low if query.object_id} details=#{query}"
106
+ @log.debug "query: user=#{user_id} context=#{context} class=#{query.class_name} object_num=#{query.object_id.object_num_low if query.object_id} details=#{query} haveSelect=#{query.impl and query.impl.haveSelect} getSelect=#{query.impl and query.impl.getSelect} (#{query.impl and query.impl.getSelect and query.impl.getSelect.methods.inspect})"
104
107
 
105
108
  cmeta = @classes_by_name[query.class_name]
106
109
  objs = []
@@ -136,8 +139,9 @@ module SPQR
136
139
 
137
140
  @connection = Qmf::Connection.new(settings)
138
141
  @log.debug(" +-- @connection created: #{@connection}")
142
+ @log.debug(" +-- app name is '#{@app_name}'")
139
143
 
140
- @agent = Qmf::Agent.new(self)
144
+ @agent = Qmf::Agent.new(self, @app_name)
141
145
  @log.debug(" +-- @agent created: #{@agent}")
142
146
 
143
147
  @agent.set_connection(@connection)
@@ -150,6 +154,7 @@ module SPQR
150
154
  end
151
155
 
152
156
  @log.debug("entering orbit....")
157
+
153
158
  sleep
154
159
  end
155
160
 
@@ -0,0 +1,126 @@
1
+ class QmfClicker
2
+ include ::SPQR::Manageable
3
+
4
+ def QmfClicker.find_by_id(oid)
5
+ @singleton ||= QmfClicker.new
6
+ @singleton
7
+ end
8
+
9
+ def QmfClicker.find_all
10
+ @singleton ||= QmfClicker.new
11
+ [@singleton]
12
+ end
13
+
14
+ def initialize
15
+ @clicks = 0
16
+ end
17
+
18
+ def click(args)
19
+ @clicks = @clicks.succ
20
+ end
21
+
22
+ spqr_expose :click do |args|
23
+ end
24
+
25
+ spqr_statistic :clicks, :int
26
+
27
+ spqr_package :example
28
+ spqr_class :QmfClicker
29
+ end
30
+
31
+ class QmfHello
32
+ include ::SPQR::Manageable
33
+
34
+ def QmfHello.find_by_id(oid)
35
+ @qmf_hellos ||= [QmfHello.new]
36
+ @qmf_hellos[0]
37
+ end
38
+
39
+ def QmfHello.find_all
40
+ @qmf_hellos ||= [QmfHello.new]
41
+ @qmf_hellos
42
+ end
43
+
44
+ def hello(args)
45
+ args["result"] = "Hello, #{args['name']}!"
46
+ end
47
+
48
+ spqr_expose :hello do |args|
49
+ args.declare :name, :lstr, :in
50
+ args.declare :result, :lstr, :out
51
+ end
52
+
53
+ spqr_package :example
54
+ spqr_class :QmfHello
55
+ end
56
+
57
+ class QmfDummyProp
58
+ include ::SPQR::Manageable
59
+
60
+ def QmfDummyProp.find_by_id(oid)
61
+ @qmf_dps ||= [QmfDummyProp.new]
62
+ @qmf_dps[0]
63
+ end
64
+
65
+ def QmfDummyProp.find_all
66
+ @qmf_dps ||= [QmfDummyProp.new]
67
+ @qmf_dps
68
+ end
69
+
70
+ def service_name
71
+ "DummyPropService"
72
+ end
73
+
74
+ spqr_property :service_name, :lstr
75
+
76
+ spqr_class :QmfDummyProp
77
+ spqr_package :example
78
+ end
79
+
80
+
81
+ class QmfIntegerProp
82
+ include ::SPQR::Manageable
83
+
84
+ SIZE = 12
85
+
86
+ def initialize(oid)
87
+ @int_id = oid
88
+ end
89
+
90
+ def spqr_object_id
91
+ @int_id
92
+ end
93
+
94
+ def QmfIntegerProp.gen_objects(ct)
95
+ objs = []
96
+ ct.times do |x|
97
+ objs << (new(x))
98
+ end
99
+ objs
100
+ end
101
+
102
+ def QmfIntegerProp.find_by_id(oid)
103
+ @qmf_ips ||= gen_objects(SIZE)
104
+ @qmf_ips[oid]
105
+ end
106
+
107
+ def QmfIntegerProp.find_all
108
+ @qmf_ips ||= gen_objects(SIZE)
109
+ @qmf_ips
110
+ end
111
+
112
+ def next(args)
113
+ args['result'] = QmfIntegerProp.find_by_id((@int_id + 1) % QmfIntegerProp::SIZE)
114
+ end
115
+
116
+ spqr_expose :next do |args|
117
+ args.declare :result, :objId, :out
118
+ end
119
+
120
+ spqr_property :int_id, :int, :index=>true
121
+
122
+ spqr_class :QmfIntegerProp
123
+ spqr_package :example
124
+ end
125
+
126
+
data/test/helper.rb CHANGED
@@ -1,11 +1,76 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require 'qmf'
4
+ require 'timeout'
5
+ require 'thread'
3
6
 
4
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+
6
10
  require 'spqr/spqr'
7
11
  require 'spqr/app'
8
12
  require 'rhubarb/rhubarb'
9
13
 
14
+ module QmfTestHelpers
15
+ DEBUG = false
16
+
17
+ class AgentNotifyHandler < Qmf::ConsoleHandler
18
+ def initialize
19
+ @q = Queue.new
20
+ end
21
+
22
+ def queue
23
+ @q
24
+ end
25
+
26
+ def agent_added(agent)
27
+ puts "GOT AN AGENT: #{agent}" if DEBUG
28
+ @q << agent
29
+ end
30
+ end
31
+
32
+ def app_setup(*classes)
33
+ unless $broker
34
+ $notify_handler = AgentNotifyHandler.new
35
+ $connection = Qmf::Connection.new(Qmf::ConnectionSettings.new)
36
+ $console = Qmf::Console.new($notify_handler)
37
+ $broker = $console.add_connection($connection)
38
+ end
39
+
40
+ @app = SPQR::App.new(:loglevel => (DEBUG ? :debug : :fatal))
41
+ @app.register *classes
42
+ @child_pid = fork do
43
+ unless DEBUG
44
+ # replace stdin/stdout/stderr
45
+ $stdin.reopen("/dev/null", "r")
46
+ $stdout.reopen("/dev/null", "w")
47
+ $stderr.reopen("/dev/null", "w")
48
+ end
49
+
50
+ @app.main
51
+ end
52
+
53
+ $broker.wait_for_stable
54
+
55
+ Timeout.timeout(5) do
56
+ k = ""
57
+ begin
58
+ @ag = $notify_handler.queue.pop
59
+ k = @ag.key
60
+ puts "GOT A KEY: #{k}" if DEBUG
61
+ end until k != "1.0"
62
+
63
+ # XXX
64
+ sleep 0.45
65
+ puts "ESCAPING FROM TIMEOUT" if DEBUG
66
+ end
67
+
68
+ end
69
+
70
+ def teardown
71
+ Process.kill(9, @child_pid) if @child_pid
72
+ end
73
+ end
74
+
10
75
  class Test::Unit::TestCase
11
76
  end
@@ -0,0 +1,58 @@
1
+ require 'helper'
2
+ require 'set'
3
+ require 'example-apps'
4
+
5
+ class TestSpqrClicker < Test::Unit::TestCase
6
+ include QmfTestHelpers
7
+
8
+ def setup
9
+ @child_pid = nil
10
+ end
11
+
12
+ def test_no_param_method
13
+ app_setup QmfClicker
14
+
15
+ assert_nothing_raised do
16
+ obj = $console.objects(:class=>"QmfClicker", :agent=>@ag)[0]
17
+
18
+ obj.click({})
19
+ end
20
+ end
21
+
22
+ def test_statistics_empty
23
+ app_setup QmfClicker
24
+
25
+ obj = $console.objects(:class=>"QmfClicker", :agent=>@ag)[0]
26
+ assert_equal "clicks", obj.statistics[0][0].name
27
+ assert_equal 0, obj[:clicks]
28
+ end
29
+
30
+ def test_statistics_postquery
31
+ app_setup QmfClicker
32
+
33
+ x = 0
34
+
35
+ 9.times do
36
+ obj = $console.objects(:class=>"QmfClicker", :agent=>@ag)[0]
37
+ assert_equal x, obj[:clicks]
38
+
39
+ obj.click({})
40
+ x = x.succ
41
+ end
42
+ end
43
+
44
+ def test_statistics_postupdate
45
+ app_setup QmfClicker
46
+
47
+ x = 0
48
+ obj = $console.objects(:class=>"QmfClicker", :agent=>@ag)[0]
49
+
50
+ 9.times do
51
+ obj.update
52
+ assert_equal x, obj[:clicks]
53
+
54
+ obj.click({})
55
+ x = x.succ
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+ require 'set'
3
+ require 'example-apps'
4
+
5
+ class TestSpqrDummyProp < Test::Unit::TestCase
6
+ include QmfTestHelpers
7
+
8
+ def setup
9
+ @child_pid = nil
10
+ end
11
+
12
+ def test_property_basic
13
+ app_setup QmfDummyProp
14
+
15
+ obj = $console.objects(:class=>"QmfDummyProp", :agent=>@ag)[0]
16
+ assert_equal "DummyPropService", obj[:service_name]
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+ require 'set'
3
+ require 'example-apps'
4
+
5
+ class TestSpqrHello < Test::Unit::TestCase
6
+ include QmfTestHelpers
7
+
8
+ def setup
9
+ @child_pid = nil
10
+ end
11
+
12
+ def test_hello_objects
13
+ app_setup QmfHello
14
+ objs = $console.objects(:class=>"QmfHello", :agent=>@ag)
15
+ assert objs.size > 0
16
+ end
17
+
18
+ def test_hello_call
19
+ app_setup QmfHello
20
+ obj = $console.objects(:class=>"QmfHello", :agent=>@ag)[0]
21
+
22
+ val = obj.hello("ruby").result
23
+ args = { 'name' => 'ruby' }
24
+ QmfHello.find_by_id(0).hello(args)
25
+
26
+ expected = args['result']
27
+
28
+ assert_equal expected, val
29
+ end
30
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+ require 'set'
3
+ require 'example-apps'
4
+
5
+ class TestSpqrIntegerProp < Test::Unit::TestCase
6
+ include QmfTestHelpers
7
+
8
+ def setup
9
+ @child_pid = nil
10
+ end
11
+
12
+ def test_reference_returning_method
13
+ app_setup QmfIntegerProp
14
+
15
+ objs = $console.objects(:class=>"QmfIntegerProp", :agent=>@ag)
16
+
17
+ objs.size.times do |x|
18
+ expected = objs[(x + 1) % QmfIntegerProp::SIZE]
19
+ actual = $console.object(:object_id=>objs[x].next.result)
20
+ assert_equal expected.int_id, actual.int_id
21
+ end
22
+ end
23
+
24
+ def test_property_identities
25
+ app_setup QmfIntegerProp
26
+
27
+ objs = $console.objects(:class=>"QmfIntegerProp", :agent=>@ag)
28
+ ids = Set.new
29
+
30
+ objs.each do |obj|
31
+ ids << obj[:int_id]
32
+ end
33
+
34
+ assert_equal objs.size, ids.size
35
+
36
+ objs.size.times do |x|
37
+ assert ids.include?(x), "ids should include #{x}, which is less than #{objs.size}"
38
+ end
39
+ end
40
+
41
+ def test_find_objs_by_props
42
+ app_setup QmfIntegerProp
43
+
44
+ sz = QmfIntegerProp::SIZE
45
+
46
+ sz.times do |x|
47
+ obj = $console.objects(:class=>"QmfIntegerProp", 'int_id'=>x, :agent=>@ag)[0]
48
+ assert_equal x, obj[:int_id]
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spqr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Benton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-30 00:00:00 -06:00
12
+ date: 2009-12-08 00:00:00 -06:00
13
13
  default_executable: spqr-gen.rb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,6 +35,7 @@ extra_rdoc_files:
35
35
  files:
36
36
  - .document
37
37
  - .gitignore
38
+ - CHANGES
38
39
  - LICENSE
39
40
  - README.rdoc
40
41
  - Rakefile
@@ -55,9 +56,13 @@ files:
55
56
  - spec/spec_helper.rb
56
57
  - spec/spqr_spec.rb
57
58
  - spqr.spec.in
59
+ - test/example-apps.rb
58
60
  - test/helper.rb
59
61
  - test/test_rhubarb.rb
60
- - test/test_spqr.rb
62
+ - test/test_spqr_clicker.rb
63
+ - test/test_spqr_dummyprop.rb
64
+ - test/test_spqr_hello.rb
65
+ - test/test_spqr_integerprop.rb
61
66
  has_rdoc: true
62
67
  homepage: http://git.fedorahosted.org/git/grid/spqr.git
63
68
  licenses: []
@@ -89,9 +94,12 @@ summary: "SPQR: {Schema Processor|Straightforward Publishing} for QMF agents in
89
94
  test_files:
90
95
  - spec/spqr_spec.rb
91
96
  - spec/spec_helper.rb
97
+ - test/example-apps.rb
98
+ - test/test_spqr_dummyprop.rb
92
99
  - test/helper.rb
100
+ - test/test_spqr_clicker.rb
101
+ - test/test_spqr_integerprop.rb
93
102
  - test/test_rhubarb.rb
94
- - test/test_spqr.rb
103
+ - test/test_spqr_hello.rb
95
104
  - examples/hello.rb
96
- - examples/codegen/EchoAgent.rb
97
105
  - examples/logservice.rb
@@ -1,33 +0,0 @@
1
- module Examples
2
- module Codegen
3
- class EchoAgent
4
- include SPQR::Manageable
5
-
6
- spqr_package 'examples.codegen'
7
- spqr_class 'EchoAgent'
8
- # Find method (NB: you must implement this)
9
- def EchoAgent.find_by_id(objid)
10
- EchoAgent.new
11
- end
12
- # Find-all method (NB: you must implement this)
13
- def EchoAgent.find_all
14
- [EchoAgent.new]
15
- end
16
- ### Schema method declarations
17
-
18
- # echo returns its argument
19
- # * arg (lstr/IO)
20
- #
21
- def echo(args)
22
- # Print values of in/out parameters
23
- log.debug "arg => #{args["arg"]}" #
24
- # Assign values to in/out parameters
25
- args["arg"] = args["arg"]
26
- end
27
-
28
- spqr_expose :echo do |args|
29
- args.declare :arg, :lstr, :inout, {}
30
- end
31
- end
32
- end
33
- end
data/test/test_spqr.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSpqr < Test::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end