knjrbfw 0.0.110 → 0.0.114
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +0 -14
- data/lib/knj/autoload.rb +1 -2
- data/lib/knj/gtk2_window.rb +7 -7
- data/lib/knj/image.rb +60 -51
- data/lib/knj/scripts/php_to_rb_helper.rb +13 -20
- data/lib/knj/unix_proc.rb +35 -35
- data/lib/knj/web.rb +135 -136
- metadata +32 -85
- data/.document +0 -5
- data/.rspec +0 -1
- data/Gemfile +0 -22
- data/Gemfile.lock +0 -90
- data/VERSION +0 -1
- data/knjrbfw.gemspec +0 -318
- data/lib/knj/.gitignore +0 -1
- data/lib/knj/datarow.rb +0 -873
- data/lib/knj/datarow_custom.rb +0 -153
- data/lib/knj/db.rb +0 -1
- data/lib/knj/knjdb/dbtime.rb +0 -35
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +0 -604
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb +0 -155
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb +0 -69
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_sqlspecs.rb +0 -5
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +0 -443
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb +0 -184
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb +0 -177
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb +0 -29
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_sqlspecs.rb +0 -5
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +0 -449
- data/lib/knj/knjdb/dump.rb +0 -122
- data/lib/knj/knjdb/idquery.rb +0 -109
- data/lib/knj/knjdb/libknjdb.rb +0 -797
- data/lib/knj/knjdb/libknjdb_java_sqlite3.rb +0 -83
- data/lib/knj/knjdb/libknjdb_row.rb +0 -153
- data/lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb +0 -69
- data/lib/knj/knjdb/query_buffer.rb +0 -87
- data/lib/knj/knjdb/revision.rb +0 -342
- data/lib/knj/knjdb/sqlspecs.rb +0 -5
- data/lib/knj/objects.rb +0 -957
- data/lib/knj/process.rb +0 -480
- data/lib/knj/process_meta.rb +0 -569
- data/lib/knj/scripts/process_meta_exec.rb +0 -144
- data/lib/knj/sshrobot/sshrobot.rb +0 -135
- data/lib/knj/sshrobot.rb +0 -1
- data/lib/knj/translations.rb +0 -133
- data/spec/amixer_spec.rb +0 -32
- data/spec/arrayext_spec.rb +0 -42
- data/spec/autoload_spec.rb +0 -7
- data/spec/cmd_parser_spec.rb +0 -25
- data/spec/db_spec.rb +0 -282
- data/spec/db_spec_encoding_test_file.txt +0 -1
- data/spec/knjrbfw_spec.rb +0 -109
- data/spec/locales_spec.rb +0 -9
- data/spec/objects_spec.rb +0 -394
- data/spec/process_meta_spec.rb +0 -172
- data/spec/process_spec.rb +0 -115
- data/spec/spec_helper.rb +0 -12
- data/spec/strings_spec.rb +0 -65
- data/spec/web_spec.rb +0 -77
- data/testfiles/image.jpg +0 -0
data/spec/knjrbfw_spec.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Knjrbfw" do
|
4
|
-
it "should be able to join arrays with callbacks." do
|
5
|
-
res = Knj::ArrayExt.join(:arr => [1, 2, 3], :sep => ",", :callback => proc{|value| "'#{value}'"})
|
6
|
-
raise "Unexpected result from ArrayExt." if res != "'1','2','3'"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should be able to draw rounded transparent corners on images." do
|
10
|
-
require "rubygems"
|
11
|
-
require "RMagick"
|
12
|
-
|
13
|
-
pic = Magick::Image.read("#{File.dirname(__FILE__)}/../testfiles/image.jpg").first
|
14
|
-
pic.format = "png"
|
15
|
-
|
16
|
-
Knj::Image.rounded_corners(
|
17
|
-
:img => pic,
|
18
|
-
:radius => 10
|
19
|
-
)
|
20
|
-
|
21
|
-
blob_cont = pic.to_blob
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should be possible to use Strings.html_links-method." do
|
25
|
-
teststr = "This is a test. http://www.google.com This is a test."
|
26
|
-
|
27
|
-
#Test normal usage.
|
28
|
-
test1 = Knj::Strings.html_links(teststr)
|
29
|
-
raise "Unexpected string: '#{teststr}'" if test1 != "This is a test. <a href=\"http://www.google.com\">http://www.google.com</a> This is a test."
|
30
|
-
|
31
|
-
|
32
|
-
#Test with a block.
|
33
|
-
test2 = Knj::Strings.html_links(teststr) do |data|
|
34
|
-
data[:str].gsub(data[:match][0], "TEST")
|
35
|
-
end
|
36
|
-
|
37
|
-
raise "Unexpected string: '#{test2}'." if test2 != "This is a test. TEST This is a test."
|
38
|
-
end
|
39
|
-
|
40
|
-
=begin
|
41
|
-
it "should be able to use Knj::Mutexcl with advanced arguments." do
|
42
|
-
mutex = Knj::Mutexcl.new(
|
43
|
-
:modes => {
|
44
|
-
:reader => {
|
45
|
-
:blocks => [:writer]
|
46
|
-
},
|
47
|
-
:writer => {
|
48
|
-
:blocks => [:reader, :writer]
|
49
|
-
}
|
50
|
-
}
|
51
|
-
)
|
52
|
-
|
53
|
-
$count = 0
|
54
|
-
|
55
|
-
Knj::Thread.new do
|
56
|
-
mutex.sync(:reader) do
|
57
|
-
sleep 0.2
|
58
|
-
$count += 1
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
mutex.sync(:reader) do
|
63
|
-
$count += 1
|
64
|
-
end
|
65
|
-
|
66
|
-
raise "Count should be 1 by now but it wasnt: '#{$count}'." if $count != 1
|
67
|
-
sleep 0.3
|
68
|
-
raise "Count should be 2 by now but it wasnt: '#{$count}'." if $count != 2
|
69
|
-
|
70
|
-
|
71
|
-
$count = 0
|
72
|
-
Knj::Thread.new do
|
73
|
-
mutex.sync(:reader) do
|
74
|
-
sleep 2
|
75
|
-
$count += 1
|
76
|
-
end
|
77
|
-
end
|
78
|
-
sleep 0.1
|
79
|
-
|
80
|
-
Knj::Thread.new do
|
81
|
-
mutex.sync(:writer) do
|
82
|
-
$count += 1
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
sleep 1
|
87
|
-
raise "Count should be 0 but it wasnt: '#{$count}'." if $count != 0
|
88
|
-
sleep 1.1
|
89
|
-
raise "Count should be 2 but it wasnt: '#{$count}'." if $count != 2
|
90
|
-
|
91
|
-
Knj::Thread.new do
|
92
|
-
mutex.sync(:reader) do
|
93
|
-
sleep 0.2
|
94
|
-
$count += 1
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
Knj::Thread.new do
|
99
|
-
mutex.sync(:reader) do
|
100
|
-
sleep 0.2
|
101
|
-
$count += 1
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
sleep 0.35
|
106
|
-
raise "Count should be 4 but it wasnt: '#{$count}'." if $count != 4
|
107
|
-
end
|
108
|
-
=end
|
109
|
-
end
|
data/spec/locales_spec.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Locales" do
|
4
|
-
it "should do convertions of short formats" do
|
5
|
-
Thread.current[:locale] = "en"
|
6
|
-
res = Knj::Locales.lang
|
7
|
-
raise "Result wasnt as expected: '#{res}'." if res["first"] != "en" or res["second"] != "GB" or res["full"] != "en_GB"
|
8
|
-
end
|
9
|
-
end
|
data/spec/objects_spec.rb
DELETED
@@ -1,394 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Objects" do
|
4
|
-
it "should be able to cache rows" do
|
5
|
-
begin
|
6
|
-
require "#{File.dirname(__FILE__)}/../../array_enumerator/lib/array_enumerator"
|
7
|
-
rescue LoadError
|
8
|
-
require "array_enumerator"
|
9
|
-
end
|
10
|
-
|
11
|
-
require "sqlite3" if RUBY_ENGINE != "jruby"
|
12
|
-
|
13
|
-
$db_path = "#{Knj::Os.tmpdir}/knjrbfw_objects_cache_test.sqlite3"
|
14
|
-
File.unlink($db_path) if File.exists?($db_path)
|
15
|
-
$db = Knj::Db.new(:type => :sqlite3, :path => $db_path, :return_keys => "symbols", :debug => false)
|
16
|
-
|
17
|
-
schema = {
|
18
|
-
"tables" => {
|
19
|
-
"Group" => {
|
20
|
-
"columns" => [
|
21
|
-
{"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
|
22
|
-
{"name" => "groupname", "type" => "varchar"}
|
23
|
-
]
|
24
|
-
},
|
25
|
-
"User" => {
|
26
|
-
"columns" => [
|
27
|
-
{"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
|
28
|
-
{"name" => "username", "type" => "varchar"}
|
29
|
-
]
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
33
|
-
Knj::Db::Revision.new.init_db("schema" => schema, "db" => $db)
|
34
|
-
|
35
|
-
class User < Knj::Datarow; end
|
36
|
-
|
37
|
-
$ob = Knj::Objects.new(
|
38
|
-
:db => $db,
|
39
|
-
:datarow => true,
|
40
|
-
:require => false,
|
41
|
-
:array_enum => true,
|
42
|
-
:models => {
|
43
|
-
:User => {
|
44
|
-
:cache_ids => true
|
45
|
-
}
|
46
|
-
}
|
47
|
-
)
|
48
|
-
|
49
|
-
$ob.adds(:User, [
|
50
|
-
{:username => "User 1"},
|
51
|
-
{:username => "User 2"},
|
52
|
-
{:username => "User 3"},
|
53
|
-
{:username => "User 4"},
|
54
|
-
{:username => "User 5"}
|
55
|
-
])
|
56
|
-
|
57
|
-
raise "Expected user-ID-cache to be 5 but it wasnt: #{$ob.ids_cache[:User].length}" if $ob.ids_cache[:User].length != 5
|
58
|
-
|
59
|
-
user = $ob.get(:User, 4)
|
60
|
-
raise "No user returned." if !user
|
61
|
-
$ob.delete(user)
|
62
|
-
raise "Expected user-ID-cache to be 4 but it wasnt: #{$ob.ids_cache[:User].length} #{$ob.ids_cache}" if $ob.ids_cache[:User].length != 4
|
63
|
-
|
64
|
-
$ob.deletes([$ob.get(:User, 1), $ob.get(:User, 2)])
|
65
|
-
raise "Expected user-ID-cache to be 2 but it wasnt: #{$ob.ids_cache[:User].length} #{$ob.ids_cache}" if $ob.ids_cache[:User].length != 2
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should be able to do 'select_col_as_array'" do
|
69
|
-
res = $ob.list(:User, {"select_col_as_array" => "id"}).to_a
|
70
|
-
raise "Expected length of 2 but got: #{res.length}" if res.length != 2
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should work even though stressed by threads (thread-safe)." do
|
74
|
-
userd = []
|
75
|
-
10.upto(25) do |i|
|
76
|
-
userd << {:username => "User #{i}"}
|
77
|
-
end
|
78
|
-
|
79
|
-
$ob.adds(:User, userd)
|
80
|
-
users = $ob.list(:User).to_a
|
81
|
-
|
82
|
-
#Stress it to test threadsafety...
|
83
|
-
threads = []
|
84
|
-
0.upto(5) do |tc|
|
85
|
-
threads << Knj::Thread.new do
|
86
|
-
0.upto(5) do |ic|
|
87
|
-
user = $ob.add(:User, {:username => "User #{tc}-#{ic}"})
|
88
|
-
raise "No user returned." if !user
|
89
|
-
$ob.delete(user)
|
90
|
-
|
91
|
-
user1 = $ob.add(:User, {:username => "User #{tc}-#{ic}-1"})
|
92
|
-
user2 = $ob.add(:User, {:username => "User #{tc}-#{ic}-2"})
|
93
|
-
user3 = $ob.add(:User, {:username => "User #{tc}-#{ic}-3"})
|
94
|
-
|
95
|
-
raise "Missing user?" if !user1 or !user2 or !user3 or user1.deleted? or user2.deleted? or user3.deleted?
|
96
|
-
$ob.deletes([user1, user2, user3])
|
97
|
-
|
98
|
-
count = 0
|
99
|
-
users.each do |user|
|
100
|
-
count += 1
|
101
|
-
user[:username] = "#{user[:username]}." if !user.deleted?
|
102
|
-
end
|
103
|
-
|
104
|
-
raise "Expected at least 15 users but got #{count}." if count != 18
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
threads.each do |thread|
|
110
|
-
thread.join
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should be able to skip queries when adding" do
|
115
|
-
class Group < Knj::Datarow; end
|
116
|
-
|
117
|
-
$ob2 = Knj::Objects.new(
|
118
|
-
:db => $db,
|
119
|
-
:datarow => true,
|
120
|
-
:require => false
|
121
|
-
)
|
122
|
-
|
123
|
-
threads = []
|
124
|
-
0.upto(5) do
|
125
|
-
threads << Knj::Thread.new do
|
126
|
-
0.upto(5) do
|
127
|
-
ret = $ob2.add(:Group, {:groupname => "User 1"}, {:skip_ret => true})
|
128
|
-
raise "Expected empty return but got something: #{ret}" if ret
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
threads.each do |thread|
|
134
|
-
thread.join
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should delete the temporary database." do
|
139
|
-
File.unlink($db_path) if File.exists?($db_path)
|
140
|
-
end
|
141
|
-
|
142
|
-
#Moved from "knjrbfw_spec.rb"
|
143
|
-
it "should be able to generate a sample SQLite database and add a sample table, with sample columns and with a sample index to it" do
|
144
|
-
$db_path = "#{Knj::Os.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
|
145
|
-
$db = Knj::Db.new(
|
146
|
-
:type => "sqlite3",
|
147
|
-
:path => $db_path,
|
148
|
-
:return_keys => "symbols",
|
149
|
-
:index_append_table_name => true
|
150
|
-
)
|
151
|
-
|
152
|
-
$db.tables.create("Project", {
|
153
|
-
"columns" => [
|
154
|
-
{"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
|
155
|
-
{"name" => "category_id", "type" => "int"},
|
156
|
-
{"name" => "name", "type" => "varchar"}
|
157
|
-
],
|
158
|
-
"indexes" => [
|
159
|
-
{"name" => "category_id", "columns" => ["category_id"]}
|
160
|
-
]
|
161
|
-
})
|
162
|
-
|
163
|
-
$db.tables.create("Task", {
|
164
|
-
"columns" => [
|
165
|
-
{"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
|
166
|
-
{"name" => "project_id", "type" => "int"},
|
167
|
-
{"name" => "person_id", "type" => "int"},
|
168
|
-
{"name" => "name", "type" => "varchar"}
|
169
|
-
],
|
170
|
-
"indexes" => [
|
171
|
-
{"name" => "project_id", "columns" => ["project_id"]}
|
172
|
-
]
|
173
|
-
})
|
174
|
-
|
175
|
-
$db.tables.create("Person", {
|
176
|
-
"columns" => [
|
177
|
-
{"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
|
178
|
-
{"name" => "name", "type" => "varchar"}
|
179
|
-
]
|
180
|
-
})
|
181
|
-
|
182
|
-
$db.tables.create("Timelog", {
|
183
|
-
"columns" => [
|
184
|
-
{"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
|
185
|
-
{"name" => "person_id", "type" => "int"}
|
186
|
-
],
|
187
|
-
"indexes" => [
|
188
|
-
"person_id"
|
189
|
-
]
|
190
|
-
})
|
191
|
-
|
192
|
-
table = $db.tables["Project"]
|
193
|
-
|
194
|
-
indexes = table.indexes
|
195
|
-
raise "Could not find the sample-index 'category_id' that should have been created." if !indexes["Project__category_id"]
|
196
|
-
|
197
|
-
|
198
|
-
#If we insert a row the ID should increase and the name should be the same as inserted (or something is very very wrong)...
|
199
|
-
$db.insert("Project", {
|
200
|
-
"name" => "Test project"
|
201
|
-
})
|
202
|
-
|
203
|
-
count = 0
|
204
|
-
$db.q("SELECT * FROM Project") do |d|
|
205
|
-
raise "Somehow name was not 'Test project'" if d[:name] != "Test project"
|
206
|
-
raise "ID was not set?" if d[:id].to_i <= 0
|
207
|
-
count += 1
|
208
|
-
end
|
209
|
-
|
210
|
-
raise "Expected count of 1 but it wasnt: #{count}" if count != 1
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should be able to automatic generate methods on datarow-classes (has_many, has_one)." do
|
214
|
-
class Project < Knj::Datarow
|
215
|
-
has_many [
|
216
|
-
{:class => :Task, :col => :project_id, :depends => true}
|
217
|
-
]
|
218
|
-
end
|
219
|
-
|
220
|
-
class Task < Knj::Datarow
|
221
|
-
has_one [
|
222
|
-
{:class => :Person, :required => true},
|
223
|
-
:Project
|
224
|
-
]
|
225
|
-
end
|
226
|
-
|
227
|
-
class Person < Knj::Datarow
|
228
|
-
has_one [:Project]
|
229
|
-
|
230
|
-
has_many [
|
231
|
-
{:class => :Timelog, :autozero => true}
|
232
|
-
]
|
233
|
-
|
234
|
-
def html
|
235
|
-
return self[:name]
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
class Timelog < Knj::Datarow
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
$ob = Knj::Objects.new(:db => $db, :datarow => true, :require => false)
|
244
|
-
|
245
|
-
$ob.add(:Person, {
|
246
|
-
:name => "Kasper"
|
247
|
-
})
|
248
|
-
$ob.add(:Task, {
|
249
|
-
:name => "Test task",
|
250
|
-
:person_id => 1,
|
251
|
-
:project_id => 1
|
252
|
-
})
|
253
|
-
|
254
|
-
begin
|
255
|
-
$obb.add(:Task, {:name => "Test task"})
|
256
|
-
raise "Method should fail but didnt."
|
257
|
-
rescue
|
258
|
-
#ignore.
|
259
|
-
end
|
260
|
-
|
261
|
-
|
262
|
-
#Test 'list_invalid_required'.
|
263
|
-
$db.insert(:Task, :name => "Invalid require")
|
264
|
-
id = $db.last_id
|
265
|
-
found = false
|
266
|
-
|
267
|
-
$ob.list_invalid_required(:class => :Task) do |d|
|
268
|
-
raise "Expected object ID to be #{id} but it wasnt: #{d[:obj].id}" if d[:obj].id.to_i != id.to_i
|
269
|
-
$ob.delete(d[:obj])
|
270
|
-
found = true
|
271
|
-
end
|
272
|
-
|
273
|
-
raise "Expected to find a task but didnt." if !found
|
274
|
-
|
275
|
-
|
276
|
-
ret_proc = []
|
277
|
-
$ob.list(:Task) do |task|
|
278
|
-
ret_proc << task
|
279
|
-
end
|
280
|
-
|
281
|
-
raise "list with proc should return one task but didnt." if ret_proc.length != 1
|
282
|
-
|
283
|
-
|
284
|
-
project = $ob.get(:Project, 1)
|
285
|
-
|
286
|
-
tasks = project.tasks
|
287
|
-
raise "No tasks were found on project?" if tasks.empty?
|
288
|
-
|
289
|
-
|
290
|
-
ret_proc = []
|
291
|
-
ret_test = project.tasks do |task|
|
292
|
-
ret_proc << task
|
293
|
-
end
|
294
|
-
|
295
|
-
raise "When given a block the return should be nil so it doesnt hold weak-ref-objects in memory but it didnt return nil." if ret_test != nil
|
296
|
-
raise "list for project with proc should return one task but didnt (#{ret_proc.length})." if ret_proc.length != 1
|
297
|
-
|
298
|
-
person = tasks.first.person
|
299
|
-
project_second = tasks.first.project
|
300
|
-
|
301
|
-
raise "Returned object was not a person on task." if !person.is_a?(Person)
|
302
|
-
raise "Returned object was not a project on task." if !project_second.is_a?(Project)
|
303
|
-
|
304
|
-
|
305
|
-
#Check that has_many-depending is actually working.
|
306
|
-
begin
|
307
|
-
$ob.delete(project)
|
308
|
-
raise "It was possible to delete project 1 even though task 1 depended on it!"
|
309
|
-
rescue
|
310
|
-
#this should happen - it should not possible to delete project 1 because task 1 depends on it."
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
it "should be able to generate lists for inputs" do
|
315
|
-
Knj::Web.inputs([{
|
316
|
-
:title => "Test 3",
|
317
|
-
:name => :seltest3,
|
318
|
-
:type => :select,
|
319
|
-
:default => 1,
|
320
|
-
:opts => $ob.list_optshash(:Task)
|
321
|
-
}])
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should be able to connect to objects 'no-html' callback and test it." do
|
325
|
-
task = $ob.get(:Task, 1)
|
326
|
-
$ob.events.connect(:no_html) do |event, classname|
|
327
|
-
"[no #{classname.to_s.downcase}]"
|
328
|
-
end
|
329
|
-
|
330
|
-
raise "Unexpected person_html from task (should have been 'Kasper'): '#{task.person_html}'." if task.person_html != "Kasper"
|
331
|
-
task.update(:person_id => 0)
|
332
|
-
raise "Unexpected person_html from task (should have been '[no person]')." if task.person_html != "[no person]"
|
333
|
-
end
|
334
|
-
|
335
|
-
it "should be able to to multiple additions and delete objects through a buffer" do
|
336
|
-
objs = []
|
337
|
-
0.upto(500) do
|
338
|
-
objs << {:name => :Kasper}
|
339
|
-
end
|
340
|
-
|
341
|
-
$ob.adds(:Person, objs)
|
342
|
-
pers_length = $ob.list(:Person, "count" => true)
|
343
|
-
|
344
|
-
count = 0
|
345
|
-
$db.q_buffer do |buffer|
|
346
|
-
$ob.list(:Person) do |person|
|
347
|
-
count += 1
|
348
|
-
$ob.delete(person, :db_buffer => buffer)
|
349
|
-
end
|
350
|
-
|
351
|
-
buffer.flush
|
352
|
-
end
|
353
|
-
|
354
|
-
raise "Expected count to be #{pers_length} but it wasnt: #{count}" if count != pers_length
|
355
|
-
|
356
|
-
persons = $ob.list(:Person).to_a
|
357
|
-
raise "Expected persons count to be 0 but it wasnt: #{persons.map{|e| e.data} }" if persons.length > 0
|
358
|
-
end
|
359
|
-
|
360
|
-
it "should do autozero when deleting objects" do
|
361
|
-
person1 = $ob.add(:Person, {
|
362
|
-
:name => "Kasper"
|
363
|
-
})
|
364
|
-
person2 = $ob.add(:Person, {
|
365
|
-
:name => "Charlotte"
|
366
|
-
})
|
367
|
-
|
368
|
-
timelog1 = $ob.add(:Timelog, {
|
369
|
-
:person_id => person1.id
|
370
|
-
})
|
371
|
-
timelog2 = $ob.add(:Timelog, {
|
372
|
-
:person_id => person2.id
|
373
|
-
})
|
374
|
-
|
375
|
-
$ob.delete(person1)
|
376
|
-
|
377
|
-
raise "Expected timelog1's person-ID to be zero but it wasnt: '#{timelog1[:person_id]}'." if timelog1[:person_id].to_i != 0
|
378
|
-
raise "Expected timelog2's person-ID to be #{person2.id} but it wasnt: '#{timelog2[:person_id]}'." if timelog2[:person_id].to_i != person2.id.to_i
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should be able to do multiple deletes from ids" do
|
382
|
-
ids = []
|
383
|
-
1.upto(10) do |count|
|
384
|
-
ids << $ob.add(:Person).id
|
385
|
-
end
|
386
|
-
|
387
|
-
$ob.delete_ids(:class => :Person, :ids => ids)
|
388
|
-
end
|
389
|
-
|
390
|
-
it "should delete the temp database again." do
|
391
|
-
db_path = "#{Knj::Os.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
|
392
|
-
File.unlink(db_path) if File.exists?(db_path)
|
393
|
-
end
|
394
|
-
end
|
data/spec/process_meta_spec.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Process_meta" do
|
4
|
-
it "should be able to start a server and a client" do
|
5
|
-
require "knj/process_meta"
|
6
|
-
require "timeout"
|
7
|
-
|
8
|
-
#Start the activity.
|
9
|
-
$process_meta = Knj::Process_meta.new("debug" => true, "debug_err" => true, "id" => "process_meta_spec")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should be able to do simple blocks" do
|
13
|
-
block_ran = false
|
14
|
-
fpath = "#{Knj::Os.tmpdir}/process_meta_file_open"
|
15
|
-
|
16
|
-
Timeout.timeout(4) do
|
17
|
-
$process_meta.static(:File, :open, fpath, "w") do |fp|
|
18
|
-
block_ran = true
|
19
|
-
fp.write("Test!")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
raise "Block didnt run!" if !block_ran
|
24
|
-
raise "Unexpected file-content." if File.read(fpath) != "Test!"
|
25
|
-
File.unlink(fpath) if File.exists?(fpath)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should be able to do various operations" do
|
29
|
-
#Test that breaking a block wont continue to run in the process.
|
30
|
-
$process_meta.str_eval("
|
31
|
-
class Testclass
|
32
|
-
attr_reader :last_num
|
33
|
-
|
34
|
-
def initialize
|
35
|
-
@num = 0
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_block
|
39
|
-
@num.upto(10) do |i|
|
40
|
-
@last_num = i
|
41
|
-
yield(i)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
")
|
46
|
-
|
47
|
-
proxy_obj = $process_meta.new(:Testclass)
|
48
|
-
proxy_obj2 = $process_meta.new(:Testclass)
|
49
|
-
proxy_obj3 = $process_meta.new(:Testclass)
|
50
|
-
|
51
|
-
$ids = []
|
52
|
-
$ids << proxy_obj.__id__
|
53
|
-
$ids << proxy_obj2.__id__
|
54
|
-
$ids << proxy_obj3.__id__
|
55
|
-
|
56
|
-
proxy_obj.test_block do |i|
|
57
|
-
break if i == 5
|
58
|
-
end
|
59
|
-
|
60
|
-
last_num = proxy_obj.last_num
|
61
|
-
raise "Expected last num to be 5 but it wasnt: '#{last_num}'." if last_num != 5
|
62
|
-
|
63
|
-
#Somehow define_finalizer is always one behind, so we have to do another funny one here.
|
64
|
-
ObjectSpace.define_finalizer(self, $process_meta.method(:proxy_finalizer))
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should be able to do more" do
|
68
|
-
GC.start
|
69
|
-
|
70
|
-
#Its difficult to test this on JRuby.
|
71
|
-
if RUBY_ENGINE != "jruby"
|
72
|
-
count = 0
|
73
|
-
$ids.each do |id|
|
74
|
-
count += 1
|
75
|
-
raise "The object should no longer exist but it does: #{count}." if $process_meta.proxy_has?(id)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
#Spawn a test-object - a string - with a variable-name.
|
81
|
-
proxy_obj = $process_meta.spawn_object(:String, "my_test_var", "Kasper")
|
82
|
-
raise "to_s should return 'Kasper' but didnt: '#{proxy_obj.to_s}'." if proxy_obj.to_s != "Kasper"
|
83
|
-
|
84
|
-
#Stress it a little by doing 500 calls.
|
85
|
-
0.upto(500) do
|
86
|
-
res = proxy_obj.slice(0, 3)
|
87
|
-
raise "Expected output was: 'Kas' but wasnt: '#{res}'." if res != "Kas"
|
88
|
-
end
|
89
|
-
|
90
|
-
#Do a lot of calls at the same time to test thread-safety.
|
91
|
-
threads = []
|
92
|
-
0.upto(10) do |thread_i|
|
93
|
-
should_return = "Kasper".slice(0, thread_i)
|
94
|
-
thread = Knj::Thread.new do
|
95
|
-
0.upto(500) do |num_i|
|
96
|
-
res = proxy_obj.slice(0, thread_i)
|
97
|
-
raise "Should return: '#{should_return}' but didnt: '#{res}'." if res != should_return
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
threads << thread
|
102
|
-
end
|
103
|
-
|
104
|
-
threads.each do |thread|
|
105
|
-
thread.join
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#Try to define an integer and run upto with a block.
|
111
|
-
proxy_int = $process_meta.spawn_object(:Integer, nil, 5)
|
112
|
-
expect = 5
|
113
|
-
proxy_int.upto(1000) do |i|
|
114
|
-
raise "Expected '#{expect}' but got: '#{i}'." if i != expect
|
115
|
-
expect += 1
|
116
|
-
end
|
117
|
-
|
118
|
-
#Ensure the expected has actually been increased by running the block.
|
119
|
-
raise "Expected end-result of 1001 but got: '#{expect}'." if expect != 1001
|
120
|
-
|
121
|
-
|
122
|
-
proxy_int = $process_meta.spawn_object(:Integer, nil, 5)
|
123
|
-
proxy_int._process_meta_block_buffer_use = true
|
124
|
-
expect = 5
|
125
|
-
|
126
|
-
#If this takes more than 10 secs - something is wrong (JRuby can take a long time)...
|
127
|
-
Timeout.timeout(10) do
|
128
|
-
proxy_int.upto(10000) do |i|
|
129
|
-
raise "Expected '#{expect}' but got: '#{i}'." if i != expect
|
130
|
-
expect += 1
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
#Ensure the expected has actually been increased by running the block.
|
136
|
-
raise "Expected end-result of 10001 but got: '#{expect}'." if expect != 10001
|
137
|
-
|
138
|
-
#Try to unset an object.
|
139
|
-
proxy_obj._process_meta_unset
|
140
|
-
proxy_int._process_meta_unset
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should be able to do slow block-results in JRuby." do
|
144
|
-
$process_meta.str_eval("
|
145
|
-
class Kaspertest
|
146
|
-
def self.kaspertest
|
147
|
-
8.upto(12) do |i|
|
148
|
-
yield(i)
|
149
|
-
sleep 0.5
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
nil
|
155
|
-
")
|
156
|
-
|
157
|
-
Timeout.timeout(10) do
|
158
|
-
expect = 8
|
159
|
-
$process_meta.static("Kaspertest", "kaspertest") do |count|
|
160
|
-
raise "Expected '#{expect}' but got: '#{count}'." if expect != count
|
161
|
-
expect += 1
|
162
|
-
end
|
163
|
-
|
164
|
-
raise "Expected '13' but got: '#{expect}'." if expect != 13
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should be able to be destroyed." do
|
169
|
-
#Destroy the process-meta which should stop the process.
|
170
|
-
$process_meta.destroy
|
171
|
-
end
|
172
|
-
end
|