factbase 0.5.1 → 0.6.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.
- checksums.yaml +4 -4
- data/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +4 -20
- data/.github/workflows/benchmark.yml +10 -25
- data/.github/workflows/codecov.yml +6 -20
- data/.github/workflows/copyrights.yml +4 -19
- data/.github/workflows/markdown-lint.yml +4 -19
- data/.github/workflows/pdd.yml +4 -19
- data/.github/workflows/rake.yml +5 -21
- data/.github/workflows/reuse.yml +21 -0
- data/.github/workflows/xcop.yml +4 -19
- data/.github/workflows/yamllint.yml +4 -21
- data/.rubocop.yml +4 -21
- data/.rultor.yml +3 -19
- data/.simplecov +2 -19
- data/Gemfile +8 -24
- data/Gemfile.lock +53 -43
- data/LICENSES/MIT.txt +21 -0
- data/README.md +24 -0
- data/REUSE.toml +17 -0
- data/Rakefile +3 -28
- data/benchmarks/simple.rb +2 -19
- data/factbase.gemspec +2 -19
- data/lib/factbase/accum.rb +2 -19
- data/lib/factbase/churn.rb +36 -0
- data/lib/factbase/fact.rb +2 -19
- data/lib/factbase/flatten.rb +2 -19
- data/lib/factbase/inv.rb +6 -25
- data/lib/factbase/light.rb +32 -0
- data/lib/factbase/looged.rb +5 -26
- data/lib/factbase/pre.rb +6 -25
- data/lib/factbase/query.rb +4 -21
- data/lib/factbase/query_once.rb +2 -19
- data/lib/factbase/rules.rb +5 -26
- data/lib/factbase/syntax.rb +13 -25
- data/lib/factbase/tallied.rb +93 -0
- data/lib/factbase/taped.rb +88 -0
- data/lib/factbase/tee.rb +2 -19
- data/lib/factbase/term.rb +2 -19
- data/lib/factbase/term_once.rb +2 -19
- data/lib/factbase/terms/aggregates.rb +2 -19
- data/lib/factbase/terms/aliases.rb +2 -19
- data/lib/factbase/terms/casting.rb +2 -19
- data/lib/factbase/terms/debug.rb +2 -19
- data/lib/factbase/terms/defn.rb +2 -19
- data/lib/factbase/terms/logical.rb +2 -19
- data/lib/factbase/terms/math.rb +2 -19
- data/lib/factbase/terms/meta.rb +2 -19
- data/lib/factbase/terms/ordering.rb +2 -19
- data/lib/factbase/terms/strings.rb +2 -19
- data/lib/factbase/terms/system.rb +2 -19
- data/lib/factbase/to_json.rb +2 -19
- data/lib/factbase/to_xml.rb +2 -19
- data/lib/factbase/to_yaml.rb +2 -19
- data/lib/factbase.rb +38 -48
- data/test/factbase/terms/test_aggregates.rb +2 -19
- data/test/factbase/terms/test_aliases.rb +2 -19
- data/test/factbase/terms/test_casting.rb +2 -19
- data/test/factbase/terms/test_debug.rb +2 -19
- data/test/factbase/terms/test_defn.rb +2 -19
- data/test/factbase/terms/test_logical.rb +2 -19
- data/test/factbase/terms/test_math.rb +2 -19
- data/test/factbase/terms/test_meta.rb +2 -19
- data/test/factbase/terms/test_ordering.rb +2 -19
- data/test/factbase/terms/test_strings.rb +2 -19
- data/test/factbase/terms/test_system.rb +2 -19
- data/test/factbase/test_accum.rb +2 -19
- data/test/factbase/test_churn.rb +31 -0
- data/test/factbase/test_fact.rb +2 -19
- data/test/factbase/test_flatten.rb +2 -19
- data/test/factbase/test_inv.rb +2 -19
- data/test/factbase/test_looged.rb +2 -19
- data/test/factbase/test_pre.rb +2 -19
- data/test/factbase/test_query.rb +2 -19
- data/test/factbase/test_rules.rb +2 -19
- data/test/factbase/test_syntax.rb +24 -19
- data/test/factbase/test_tallied.rb +71 -0
- data/test/factbase/test_taped.rb +37 -0
- data/test/factbase/test_tee.rb +2 -19
- data/test/factbase/test_term.rb +2 -19
- data/test/factbase/test_to_json.rb +2 -19
- data/test/factbase/test_to_xml.rb +2 -19
- data/test/factbase/test_to_yaml.rb +2 -19
- data/test/test__helper.rb +3 -19
- data/test/test_factbase.rb +67 -45
- metadata +12 -3
- data/.yamllint.yml +0 -29
data/test/test_factbase.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'minitest/autorun'
|
24
7
|
require 'loog'
|
@@ -119,16 +102,6 @@ class TestFactbase < Minitest::Test
|
|
119
102
|
assert_equal(1, fb.size)
|
120
103
|
end
|
121
104
|
|
122
|
-
def test_makes_duplicate
|
123
|
-
fb1 = Factbase.new
|
124
|
-
fb1.insert
|
125
|
-
assert_equal(1, fb1.size)
|
126
|
-
fb2 = fb1.dup
|
127
|
-
fb2.insert
|
128
|
-
assert_equal(1, fb1.size)
|
129
|
-
assert_equal(2, fb2.size)
|
130
|
-
end
|
131
|
-
|
132
105
|
def test_txn_returns_boolean
|
133
106
|
fb = Factbase.new
|
134
107
|
assert_kind_of(FalseClass, fb.txn { true })
|
@@ -139,6 +112,12 @@ class TestFactbase < Minitest::Test
|
|
139
112
|
assert(fb.txn { |fbt| fbt.query('(always)').each.to_a[0].zzz = 33 })
|
140
113
|
end
|
141
114
|
|
115
|
+
def test_appends_in_txn
|
116
|
+
fb = Factbase.new
|
117
|
+
fb.insert.foo = 443
|
118
|
+
assert(fb.txn { |fbt| fbt.query('(always)').each { |f| f.hello = 33 } })
|
119
|
+
end
|
120
|
+
|
142
121
|
def test_run_txn
|
143
122
|
fb = Factbase.new
|
144
123
|
fb.txn do |fbt|
|
@@ -230,27 +209,71 @@ class TestFactbase < Minitest::Test
|
|
230
209
|
assert_equal(0, fb.query('(always)').each.to_a.size)
|
231
210
|
end
|
232
211
|
|
212
|
+
def test_simple_concurrent_inserts
|
213
|
+
fb = Factbase.new
|
214
|
+
t = Concurrent.processor_count * 20
|
215
|
+
Threads.new(t).assert do
|
216
|
+
fb.insert
|
217
|
+
end
|
218
|
+
assert_equal(t, fb.size)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_simple_concurrent_inserts_in_txns
|
222
|
+
fb = Factbase.new
|
223
|
+
t = Concurrent.processor_count * 7
|
224
|
+
mul = 23
|
225
|
+
Threads.new(t).assert do
|
226
|
+
assert(
|
227
|
+
fb.txn do |fbt|
|
228
|
+
mul.times do |m|
|
229
|
+
fbt.insert.foo = m
|
230
|
+
end
|
231
|
+
end
|
232
|
+
)
|
233
|
+
end
|
234
|
+
assert_equal(t * mul, fb.size)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_simple_concurrent_inserts_in_txns_with_sleep
|
238
|
+
fb = Factbase.new
|
239
|
+
t = Concurrent.processor_count * 13
|
240
|
+
mul = 53
|
241
|
+
Threads.new(t).assert do
|
242
|
+
assert(
|
243
|
+
fb.txn do |fbt|
|
244
|
+
sleep(0.01)
|
245
|
+
mul.times do |m|
|
246
|
+
fbt.insert.foo = m
|
247
|
+
end
|
248
|
+
end
|
249
|
+
)
|
250
|
+
end
|
251
|
+
assert_equal(t * mul, fb.size)
|
252
|
+
end
|
253
|
+
|
233
254
|
def test_concurrent_inserts
|
234
255
|
fb = Factbase.new
|
235
|
-
|
256
|
+
t = Concurrent.processor_count * 20
|
257
|
+
Threads.new(t).assert do
|
236
258
|
fact = fb.insert
|
237
259
|
fact.foo = 42
|
238
260
|
fact.bar = 49
|
239
261
|
fact.value = fact.foo * fact.bar
|
240
262
|
end
|
241
|
-
assert_equal(
|
242
|
-
assert_equal(
|
243
|
-
assert_equal(
|
244
|
-
assert_equal(
|
263
|
+
assert_equal(t, fb.size)
|
264
|
+
assert_equal(t, fb.query('(eq foo 42)').each.to_a.size)
|
265
|
+
assert_equal(t, fb.query('(eq bar 49)').each.to_a.size)
|
266
|
+
assert_equal(t, fb.query("(eq value #{42 * 49})").each.to_a.size)
|
245
267
|
end
|
246
268
|
|
247
269
|
def test_different_values_when_concurrent_inserts
|
248
270
|
fb = Factbase.new
|
249
|
-
|
271
|
+
t = Concurrent.processor_count * 16
|
272
|
+
Threads.new(t).assert do |i|
|
250
273
|
fb.insert.foo = i
|
251
274
|
end
|
252
|
-
assert_equal(
|
253
|
-
Threads.new(
|
275
|
+
assert_equal(t, fb.size)
|
276
|
+
Threads.new(t) do |i|
|
254
277
|
f = fb.query("(eq foo #{i})").each.to_a
|
255
278
|
assert_equal(1, f.count)
|
256
279
|
assert_equal(i, f.first.foo)
|
@@ -294,16 +317,16 @@ class TestFactbase < Minitest::Test
|
|
294
317
|
# See details here https://github.com/yegor256/factbase/actions/runs/10492255419/job/29068637032
|
295
318
|
def test_concurrent_transactions_inserts
|
296
319
|
skip('Does not work')
|
297
|
-
|
320
|
+
t = Concurrent.processor_count * 19
|
298
321
|
fb = Factbase.new
|
299
|
-
Threads.new(
|
322
|
+
Threads.new(t).assert do |i|
|
300
323
|
fb.txn do |fbt|
|
301
324
|
fact = fbt.insert
|
302
325
|
fact.thread_id = i
|
303
326
|
end
|
304
327
|
end
|
305
|
-
assert_equal(
|
306
|
-
assert_equal(
|
328
|
+
assert_equal(t, fb.size)
|
329
|
+
assert_equal(t, fb.query('(exists thread_id)').each.to_a.size)
|
307
330
|
end
|
308
331
|
|
309
332
|
def test_concurrent_transactions_with_rollbacks
|
@@ -320,8 +343,8 @@ class TestFactbase < Minitest::Test
|
|
320
343
|
|
321
344
|
def test_concurrent_transactions_successful
|
322
345
|
fb = Factbase.new
|
323
|
-
|
324
|
-
Threads.new(
|
346
|
+
t = Concurrent.processor_count * 17
|
347
|
+
Threads.new(t).assert do |i|
|
325
348
|
fb.txn do |fbt|
|
326
349
|
fact = fbt.insert
|
327
350
|
fact.thread_id = i
|
@@ -329,7 +352,7 @@ class TestFactbase < Minitest::Test
|
|
329
352
|
end
|
330
353
|
end
|
331
354
|
facts = fb.query('(exists thread_id)').each.to_a
|
332
|
-
assert_equal(
|
355
|
+
assert_equal(t, facts.size)
|
333
356
|
facts.each do |fact|
|
334
357
|
assert_equal(fact.value, fact.thread_id * 10)
|
335
358
|
end
|
@@ -358,7 +381,6 @@ class TestFactbase < Minitest::Test
|
|
358
381
|
Threads.new(2).assert do
|
359
382
|
results = fb.query('(exists thread_id)').each.to_a
|
360
383
|
assert_equal(2, results.size)
|
361
|
-
|
362
384
|
thread_ids = results.map(&:thread_id)
|
363
385
|
assert_equal((0..1).to_a, thread_ids.sort)
|
364
386
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- ".github/workflows/markdown-lint.yml"
|
144
144
|
- ".github/workflows/pdd.yml"
|
145
145
|
- ".github/workflows/rake.yml"
|
146
|
+
- ".github/workflows/reuse.yml"
|
146
147
|
- ".github/workflows/xcop.yml"
|
147
148
|
- ".github/workflows/yamllint.yml"
|
148
149
|
- ".gitignore"
|
@@ -150,25 +151,30 @@ files:
|
|
150
151
|
- ".rubocop.yml"
|
151
152
|
- ".rultor.yml"
|
152
153
|
- ".simplecov"
|
153
|
-
- ".yamllint.yml"
|
154
154
|
- Gemfile
|
155
155
|
- Gemfile.lock
|
156
156
|
- LICENSE.txt
|
157
|
+
- LICENSES/MIT.txt
|
157
158
|
- README.md
|
159
|
+
- REUSE.toml
|
158
160
|
- Rakefile
|
159
161
|
- benchmarks/simple.rb
|
160
162
|
- factbase.gemspec
|
161
163
|
- lib/factbase.rb
|
162
164
|
- lib/factbase/accum.rb
|
165
|
+
- lib/factbase/churn.rb
|
163
166
|
- lib/factbase/fact.rb
|
164
167
|
- lib/factbase/flatten.rb
|
165
168
|
- lib/factbase/inv.rb
|
169
|
+
- lib/factbase/light.rb
|
166
170
|
- lib/factbase/looged.rb
|
167
171
|
- lib/factbase/pre.rb
|
168
172
|
- lib/factbase/query.rb
|
169
173
|
- lib/factbase/query_once.rb
|
170
174
|
- lib/factbase/rules.rb
|
171
175
|
- lib/factbase/syntax.rb
|
176
|
+
- lib/factbase/tallied.rb
|
177
|
+
- lib/factbase/taped.rb
|
172
178
|
- lib/factbase/tee.rb
|
173
179
|
- lib/factbase/term.rb
|
174
180
|
- lib/factbase/term_once.rb
|
@@ -199,6 +205,7 @@ files:
|
|
199
205
|
- test/factbase/terms/test_strings.rb
|
200
206
|
- test/factbase/terms/test_system.rb
|
201
207
|
- test/factbase/test_accum.rb
|
208
|
+
- test/factbase/test_churn.rb
|
202
209
|
- test/factbase/test_fact.rb
|
203
210
|
- test/factbase/test_flatten.rb
|
204
211
|
- test/factbase/test_inv.rb
|
@@ -207,6 +214,8 @@ files:
|
|
207
214
|
- test/factbase/test_query.rb
|
208
215
|
- test/factbase/test_rules.rb
|
209
216
|
- test/factbase/test_syntax.rb
|
217
|
+
- test/factbase/test_tallied.rb
|
218
|
+
- test/factbase/test_taped.rb
|
210
219
|
- test/factbase/test_tee.rb
|
211
220
|
- test/factbase/test_term.rb
|
212
221
|
- test/factbase/test_to_json.rb
|
data/.yamllint.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Copyright (c) 2024-2025 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
extends: default
|
22
|
-
rules:
|
23
|
-
line-length: disable
|
24
|
-
brackets:
|
25
|
-
min-spaces-inside: 0
|
26
|
-
max-spaces-inside: 2
|
27
|
-
truthy:
|
28
|
-
level: warning
|
29
|
-
allowed-values: [ 'on', 'true', 'false', 'yes', 'no' ]
|