marquise 0.1.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.
@@ -0,0 +1,153 @@
1
+ require_relative './spec_helper'
2
+ require 'marquise'
3
+
4
+ describe Marquise do
5
+ describe "#tell" do
6
+ let(:marquise) do
7
+ Marquise::FFI.
8
+ should_receive(:marquise_consumer_new).
9
+ with('tcp://localhost:4567', 5).
10
+ and_return('#tell')
11
+ Marquise::FFI.
12
+ should_receive(:marquise_connect).
13
+ with('#tell').
14
+ and_return('#tellconn')
15
+
16
+ x = Marquise.new('tcp://localhost:4567')
17
+ # Neuter the Marquise
18
+ ObjectSpace.undefine_finalizer(x)
19
+
20
+ x
21
+ end
22
+
23
+ describe "(counter)" do
24
+ it "calls marquise_send_counter" do
25
+ Marquise::FFI.
26
+ should_receive(:marquise_send_counter).
27
+ and_return(0)
28
+
29
+ marquise.tell
30
+ end
31
+
32
+ it "passes sensible arguments to marquise_send_counter" do
33
+ Marquise::FFI.stub(:marquise_send_counter) do |*args|
34
+ expect(args).to be_an(Array)
35
+ expect(args.length).to eq(5)
36
+
37
+ conn, src_f, src_v, src_c, tstamp = args
38
+
39
+ expect(conn).to eq('#tellconn')
40
+
41
+ expect(tstamp).
42
+ to be_within(1_000_000_000).
43
+ of(Time.now.to_f * 1_000_000_000)
44
+
45
+ expect(src_c).to eq(0)
46
+ expect(src_f).to be(nil)
47
+ expect(src_v).to be(nil)
48
+
49
+ 0
50
+ end
51
+
52
+ marquise.tell
53
+ end
54
+
55
+ it "bombs out if marquise_send_counter fails" do
56
+ Marquise::FFI.
57
+ should_receive(:marquise_send_counter).
58
+ and_return(-1)
59
+ FFI.
60
+ should_receive(:errno).
61
+ with().
62
+ and_return(Errno::ENOEXEC::Errno)
63
+
64
+ expect { marquise.tell }.to raise_error(Errno::ENOEXEC)
65
+ end
66
+
67
+ it "passes a custom timestamp" do
68
+ t = Time.now - 86400
69
+
70
+ Marquise::FFI.stub(:marquise_send_counter) do |*args|
71
+ expect(args).to be_an(Array)
72
+ expect(args.length).to eq(5)
73
+
74
+ conn, src_f, src_v, src_c, tstamp = args
75
+
76
+ expect(tstamp).
77
+ to eq(t.to_f * 1_000_000_000)
78
+
79
+ 0
80
+ end
81
+
82
+ marquise.tell(t)
83
+ end
84
+
85
+ it "passes tags to marquise_send_counter" do
86
+ Marquise::FFI.stub(:marquise_send_counter) do |*args|
87
+ expect(args).to be_an(Array)
88
+ expect(args.length).to eq(5)
89
+
90
+ conn, src_f, src_v, src_c, tstamp = args
91
+
92
+ expect(conn).to eq('#tellconn')
93
+
94
+ expect(tstamp).
95
+ to be_within(1_000_000_000).
96
+ of(Time.now.to_f * 1_000_000_000)
97
+
98
+ expect(src_c).to eq(2)
99
+
100
+ expect(src_f).to be_a(FFI::MemoryPointer)
101
+ expect(src_f.size).to eq(3*src_f.type_size)
102
+ expect(src_f[0].read_pointer.read_string).to eq('foo')
103
+ expect(src_f[1].read_pointer.read_string).to eq('answer')
104
+ expect(src_f[2].read_pointer.address).to eq(0)
105
+
106
+ expect(src_v).to be_a(FFI::MemoryPointer)
107
+ expect(src_v.size).to eq(3*src_f.type_size)
108
+ expect(src_v[0].read_pointer.read_string).to eq('bar')
109
+ expect(src_v[1].read_pointer.read_string).to eq('42')
110
+ expect(src_v[2].read_pointer.address).to eq(0)
111
+
112
+ 0
113
+ end
114
+
115
+ marquise.tell(:foo => 'bar', 'answer' => 42)
116
+ end
117
+
118
+ it "passes timestamp *and* tags to marquise_send_counter" do
119
+ t = Time.now + 86400
120
+
121
+ Marquise::FFI.stub(:marquise_send_counter) do |*args|
122
+ expect(args).to be_an(Array)
123
+ expect(args.length).to eq(5)
124
+
125
+ conn, src_f, src_v, src_c, tstamp = args
126
+
127
+ expect(conn).to eq('#tellconn')
128
+
129
+ expect(tstamp).
130
+ to eq(t.to_f * 1_000_000_000)
131
+
132
+ expect(src_c).to eq(2)
133
+
134
+ expect(src_f).to be_a(FFI::MemoryPointer)
135
+ expect(src_f.size).to eq(3*src_f.type_size)
136
+ expect(src_f[0].read_pointer.read_string).to eq('foo')
137
+ expect(src_f[1].read_pointer.read_string).to eq('answer')
138
+ expect(src_f[2].read_pointer.address).to eq(0)
139
+
140
+ expect(src_v).to be_a(FFI::MemoryPointer)
141
+ expect(src_v.size).to eq(3*src_f.type_size)
142
+ expect(src_v[0].read_pointer.read_string).to eq('bar')
143
+ expect(src_v[1].read_pointer.read_string).to eq('42')
144
+ expect(src_v[2].read_pointer.address).to eq(0)
145
+
146
+ 0
147
+ end
148
+
149
+ marquise.tell(t, :foo => 'bar', 'answer' => 42)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,172 @@
1
+ require_relative './spec_helper'
2
+ require 'marquise'
3
+
4
+ describe Marquise do
5
+ describe "#tell" do
6
+ let(:marquise) do
7
+ Marquise::FFI.
8
+ should_receive(:marquise_consumer_new).
9
+ with('tcp://localhost:4567', 5).
10
+ and_return('#tell')
11
+ Marquise::FFI.
12
+ should_receive(:marquise_connect).
13
+ with('#tell').
14
+ and_return('#tellconn')
15
+
16
+ x = Marquise.new('tcp://localhost:4567')
17
+ # Neuter the Marquise
18
+ ObjectSpace.undefine_finalizer(x)
19
+
20
+ x
21
+ end
22
+
23
+ describe "(int)" do
24
+ it "calls marquise_send_int" do
25
+ Marquise::FFI.
26
+ should_receive(:marquise_send_int).
27
+ and_return(0)
28
+
29
+ marquise.tell 1
30
+ end
31
+
32
+ it "passes sensible arguments to marquise_send_int" do
33
+ Marquise::FFI.stub(:marquise_send_int) do |*args|
34
+ expect(args).to be_an(Array)
35
+ expect(args.length).to eq(6)
36
+
37
+ conn, src_f, src_v, src_c, i, tstamp = args
38
+
39
+ expect(conn).to eq('#tellconn')
40
+
41
+ expect(tstamp).
42
+ to be_within(1_000_000_000).
43
+ of(Time.now.to_f * 1_000_000_000)
44
+
45
+ expect(src_c).to eq(0)
46
+ expect(src_f).to be(nil)
47
+ expect(src_v).to be(nil)
48
+
49
+ expect(i).to eq(1)
50
+
51
+ 0
52
+ end
53
+
54
+ marquise.tell 1
55
+ end
56
+
57
+ it "bombs out if marquise_send_int fails" do
58
+ Marquise::FFI.
59
+ should_receive(:marquise_send_int).
60
+ and_return(-1)
61
+ FFI.
62
+ should_receive(:errno).
63
+ with().
64
+ and_return(Errno::ENOEXEC::Errno)
65
+
66
+ expect { marquise.tell 1 }.to raise_error(Errno::ENOEXEC)
67
+ end
68
+
69
+ it "bombs out if you send a bignum" do
70
+ # Do this just to keep the marquise happy
71
+ marquise.connect
72
+
73
+ expect { marquise.tell 2**65 }.
74
+ to raise_error(
75
+ ArgumentError,
76
+ "Integer out of range for Marquise#tell"
77
+ )
78
+ end
79
+
80
+ it "passes a custom timestamp" do
81
+ t = Time.now - 86400
82
+
83
+ Marquise::FFI.stub(:marquise_send_int) do |*args|
84
+ expect(args).to be_an(Array)
85
+ expect(args.length).to eq(6)
86
+
87
+ conn, src_f, src_v, src_c, i, tstamp = args
88
+
89
+ expect(tstamp).
90
+ to eq(t.to_f * 1_000_000_000)
91
+
92
+ expect(i).to eq(1)
93
+
94
+ 0
95
+ end
96
+
97
+ marquise.tell(1, t)
98
+ end
99
+
100
+ it "passes tags to marquise_send_int" do
101
+ Marquise::FFI.stub(:marquise_send_int) do |*args|
102
+ expect(args).to be_an(Array)
103
+ expect(args.length).to eq(6)
104
+
105
+ conn, src_f, src_v, src_c, i, tstamp = args
106
+
107
+ expect(conn).to eq('#tellconn')
108
+
109
+ expect(tstamp).
110
+ to be_within(1_000_000_000).
111
+ of(Time.now.to_f * 1_000_000_000)
112
+
113
+ expect(src_c).to eq(2)
114
+
115
+ expect(src_f).to be_a(FFI::MemoryPointer)
116
+ expect(src_f.size).to eq(3*src_f.type_size)
117
+ expect(src_f[0].read_pointer.read_string).to eq('foo')
118
+ expect(src_f[1].read_pointer.read_string).to eq('answer')
119
+ expect(src_f[2].read_pointer.address).to eq(0)
120
+
121
+ expect(src_v).to be_a(FFI::MemoryPointer)
122
+ expect(src_v.size).to eq(3*src_f.type_size)
123
+ expect(src_v[0].read_pointer.read_string).to eq('bar')
124
+ expect(src_v[1].read_pointer.read_string).to eq('42')
125
+ expect(src_v[2].read_pointer.address).to eq(0)
126
+
127
+ expect(i).to eq(1)
128
+
129
+ 0
130
+ end
131
+
132
+ marquise.tell(1, :foo => 'bar', 'answer' => 42)
133
+ end
134
+
135
+ it "passes timestamp *and* tags to marquise_send_int" do
136
+ t = Time.now + 86400
137
+
138
+ Marquise::FFI.stub(:marquise_send_int) do |*args|
139
+ expect(args).to be_an(Array)
140
+ expect(args.length).to eq(6)
141
+
142
+ conn, src_f, src_v, src_c, i, tstamp = args
143
+
144
+ expect(conn).to eq('#tellconn')
145
+
146
+ expect(tstamp).
147
+ to eq(t.to_f * 1_000_000_000)
148
+
149
+ expect(src_c).to eq(2)
150
+
151
+ expect(src_f).to be_a(FFI::MemoryPointer)
152
+ expect(src_f.size).to eq(3*src_f.type_size)
153
+ expect(src_f[0].read_pointer.read_string).to eq('foo')
154
+ expect(src_f[1].read_pointer.read_string).to eq('answer')
155
+ expect(src_f[2].read_pointer.address).to eq(0)
156
+
157
+ expect(src_v).to be_a(FFI::MemoryPointer)
158
+ expect(src_v.size).to eq(3*src_f.type_size)
159
+ expect(src_v[0].read_pointer.read_string).to eq('bar')
160
+ expect(src_v[1].read_pointer.read_string).to eq('42')
161
+ expect(src_v[2].read_pointer.address).to eq(0)
162
+
163
+ expect(i).to eq(1)
164
+
165
+ 0
166
+ end
167
+
168
+ marquise.tell(1, t, :foo => 'bar', 'answer' => 42)
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,161 @@
1
+ require_relative './spec_helper'
2
+ require 'marquise'
3
+
4
+ describe Marquise do
5
+ describe "#tell" do
6
+ let(:marquise) do
7
+ Marquise::FFI.
8
+ should_receive(:marquise_consumer_new).
9
+ with('tcp://localhost:4567', 5).
10
+ and_return('#tell')
11
+ Marquise::FFI.
12
+ should_receive(:marquise_connect).
13
+ with('#tell').
14
+ and_return('#tellconn')
15
+
16
+ x = Marquise.new('tcp://localhost:4567')
17
+ # Neuter the Marquise
18
+ ObjectSpace.undefine_finalizer(x)
19
+
20
+ x
21
+ end
22
+
23
+ describe "(real)" do
24
+ it "calls marquise_send_real" do
25
+ Marquise::FFI.
26
+ should_receive(:marquise_send_real).
27
+ and_return(0)
28
+
29
+ marquise.tell Math::PI
30
+ end
31
+
32
+ it "passes sensible arguments to marquise_send_real" do
33
+ Marquise::FFI.stub(:marquise_send_real) do |*args|
34
+ expect(args).to be_an(Array)
35
+ expect(args.length).to eq(6)
36
+
37
+ conn, src_f, src_v, src_c, f, tstamp = args
38
+
39
+ expect(conn).to eq('#tellconn')
40
+
41
+ expect(tstamp).
42
+ to be_within(1_000_000_000).
43
+ of(Time.now.to_f * 1_000_000_000)
44
+
45
+ expect(src_c).to eq(0)
46
+ expect(src_f).to be(nil)
47
+ expect(src_v).to be(nil)
48
+
49
+ expect(f).to eq(Math::PI)
50
+
51
+ 0
52
+ end
53
+
54
+ marquise.tell Math::PI
55
+ end
56
+
57
+ it "bombs out if marquise_send_real fails" do
58
+ Marquise::FFI.
59
+ should_receive(:marquise_send_real).
60
+ and_return(-1)
61
+ FFI.
62
+ should_receive(:errno).
63
+ with().
64
+ and_return(Errno::ENOEXEC::Errno)
65
+
66
+ expect { marquise.tell Math::PI }.to raise_error(Errno::ENOEXEC)
67
+ end
68
+
69
+ it "passes a custom timestamp" do
70
+ t = Time.now - 86400
71
+
72
+ Marquise::FFI.stub(:marquise_send_real) do |*args|
73
+ expect(args).to be_an(Array)
74
+ expect(args.length).to eq(6)
75
+
76
+ conn, src_f, src_v, src_c, f, tstamp = args
77
+
78
+ expect(tstamp).
79
+ to eq(t.to_f * 1_000_000_000)
80
+
81
+ expect(f).to eq(Math::PI)
82
+
83
+ 0
84
+ end
85
+
86
+ marquise.tell(Math::PI, t)
87
+ end
88
+
89
+ it "passes tags to marquise_send_real" do
90
+ Marquise::FFI.stub(:marquise_send_real) do |*args|
91
+ expect(args).to be_an(Array)
92
+ expect(args.length).to eq(6)
93
+
94
+ conn, src_f, src_v, src_c, f, tstamp = args
95
+
96
+ expect(conn).to eq('#tellconn')
97
+
98
+ expect(tstamp).
99
+ to be_within(1_000_000_000).
100
+ of(Time.now.to_f * 1_000_000_000)
101
+
102
+ expect(src_c).to eq(2)
103
+
104
+ expect(src_f).to be_a(FFI::MemoryPointer)
105
+ expect(src_f.size).to eq(3*src_f.type_size)
106
+ expect(src_f[0].read_pointer.read_string).to eq('foo')
107
+ expect(src_f[1].read_pointer.read_string).to eq('answer')
108
+ expect(src_f[2].read_pointer.address).to eq(0)
109
+
110
+ expect(src_v).to be_a(FFI::MemoryPointer)
111
+ expect(src_v.size).to eq(3*src_f.type_size)
112
+ expect(src_v[0].read_pointer.read_string).to eq('bar')
113
+ expect(src_v[1].read_pointer.read_string).to eq('42')
114
+ expect(src_v[2].read_pointer.address).to eq(0)
115
+
116
+ expect(f).to eq(Math::PI)
117
+
118
+ 0
119
+ end
120
+
121
+ marquise.tell(Math::PI, :foo => 'bar', 'answer' => 42)
122
+ end
123
+
124
+ it "passes timestamp *and* tags to marquise_send_real" do
125
+ t = Time.now + 86400
126
+
127
+ Marquise::FFI.stub(:marquise_send_real) do |*args|
128
+ expect(args).to be_an(Array)
129
+ expect(args.length).to eq(6)
130
+
131
+ conn, src_f, src_v, src_c, f, tstamp = args
132
+
133
+ expect(conn).to eq('#tellconn')
134
+
135
+ expect(tstamp).
136
+ to eq(t.to_f * 1_000_000_000)
137
+
138
+ expect(src_c).to eq(2)
139
+
140
+ expect(src_f).to be_a(FFI::MemoryPointer)
141
+ expect(src_f.size).to eq(3*src_f.type_size)
142
+ expect(src_f[0].read_pointer.read_string).to eq('foo')
143
+ expect(src_f[1].read_pointer.read_string).to eq('answer')
144
+ expect(src_f[2].read_pointer.address).to eq(0)
145
+
146
+ expect(src_v).to be_a(FFI::MemoryPointer)
147
+ expect(src_v.size).to eq(3*src_f.type_size)
148
+ expect(src_v[0].read_pointer.read_string).to eq('bar')
149
+ expect(src_v[1].read_pointer.read_string).to eq('42')
150
+ expect(src_v[2].read_pointer.address).to eq(0)
151
+
152
+ expect(f).to eq(Math::PI)
153
+
154
+ 0
155
+ end
156
+
157
+ marquise.tell(Math::PI, t, :foo => 'bar', 'answer' => 42)
158
+ end
159
+ end
160
+ end
161
+ end