factbase 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.0pdd.yml +2 -19
  3. data/.github/workflows/actionlint.yml +4 -20
  4. data/.github/workflows/benchmark.yml +10 -25
  5. data/.github/workflows/codecov.yml +6 -20
  6. data/.github/workflows/copyrights.yml +4 -19
  7. data/.github/workflows/markdown-lint.yml +4 -19
  8. data/.github/workflows/pdd.yml +4 -19
  9. data/.github/workflows/rake.yml +5 -21
  10. data/.github/workflows/reuse.yml +21 -0
  11. data/.github/workflows/xcop.yml +4 -19
  12. data/.github/workflows/yamllint.yml +4 -21
  13. data/.rubocop.yml +4 -21
  14. data/.rultor.yml +3 -19
  15. data/.simplecov +2 -19
  16. data/Gemfile +8 -24
  17. data/Gemfile.lock +40 -31
  18. data/LICENSES/MIT.txt +21 -0
  19. data/README.md +24 -0
  20. data/REUSE.toml +17 -0
  21. data/Rakefile +3 -28
  22. data/benchmarks/simple.rb +2 -19
  23. data/factbase.gemspec +2 -19
  24. data/lib/factbase/accum.rb +2 -19
  25. data/lib/factbase/churn.rb +36 -0
  26. data/lib/factbase/fact.rb +2 -19
  27. data/lib/factbase/flatten.rb +2 -19
  28. data/lib/factbase/inv.rb +6 -25
  29. data/lib/factbase/light.rb +32 -0
  30. data/lib/factbase/looged.rb +5 -26
  31. data/lib/factbase/pre.rb +6 -25
  32. data/lib/factbase/query.rb +4 -21
  33. data/lib/factbase/query_once.rb +2 -19
  34. data/lib/factbase/rules.rb +5 -26
  35. data/lib/factbase/syntax.rb +2 -19
  36. data/lib/factbase/tallied.rb +93 -0
  37. data/lib/factbase/taped.rb +88 -0
  38. data/lib/factbase/tee.rb +2 -19
  39. data/lib/factbase/term.rb +2 -19
  40. data/lib/factbase/term_once.rb +2 -19
  41. data/lib/factbase/terms/aggregates.rb +2 -19
  42. data/lib/factbase/terms/aliases.rb +2 -19
  43. data/lib/factbase/terms/casting.rb +2 -19
  44. data/lib/factbase/terms/debug.rb +2 -19
  45. data/lib/factbase/terms/defn.rb +2 -19
  46. data/lib/factbase/terms/logical.rb +2 -19
  47. data/lib/factbase/terms/math.rb +2 -19
  48. data/lib/factbase/terms/meta.rb +2 -19
  49. data/lib/factbase/terms/ordering.rb +2 -19
  50. data/lib/factbase/terms/strings.rb +2 -19
  51. data/lib/factbase/terms/system.rb +2 -19
  52. data/lib/factbase/to_json.rb +2 -19
  53. data/lib/factbase/to_xml.rb +2 -19
  54. data/lib/factbase/to_yaml.rb +2 -19
  55. data/lib/factbase.rb +38 -48
  56. data/test/factbase/terms/test_aggregates.rb +2 -19
  57. data/test/factbase/terms/test_aliases.rb +2 -19
  58. data/test/factbase/terms/test_casting.rb +2 -19
  59. data/test/factbase/terms/test_debug.rb +2 -19
  60. data/test/factbase/terms/test_defn.rb +2 -19
  61. data/test/factbase/terms/test_logical.rb +2 -19
  62. data/test/factbase/terms/test_math.rb +2 -19
  63. data/test/factbase/terms/test_meta.rb +2 -19
  64. data/test/factbase/terms/test_ordering.rb +2 -19
  65. data/test/factbase/terms/test_strings.rb +2 -19
  66. data/test/factbase/terms/test_system.rb +2 -19
  67. data/test/factbase/test_accum.rb +2 -19
  68. data/test/factbase/test_churn.rb +31 -0
  69. data/test/factbase/test_fact.rb +2 -19
  70. data/test/factbase/test_flatten.rb +2 -19
  71. data/test/factbase/test_inv.rb +2 -19
  72. data/test/factbase/test_looged.rb +2 -19
  73. data/test/factbase/test_pre.rb +2 -19
  74. data/test/factbase/test_query.rb +2 -19
  75. data/test/factbase/test_rules.rb +2 -19
  76. data/test/factbase/test_syntax.rb +2 -19
  77. data/test/factbase/test_tallied.rb +71 -0
  78. data/test/factbase/test_taped.rb +37 -0
  79. data/test/factbase/test_tee.rb +2 -19
  80. data/test/factbase/test_term.rb +2 -19
  81. data/test/factbase/test_to_json.rb +2 -19
  82. data/test/factbase/test_to_xml.rb +2 -19
  83. data/test/factbase/test_to_yaml.rb +2 -19
  84. data/test/test__helper.rb +3 -19
  85. data/test/test_factbase.rb +67 -45
  86. metadata +12 -3
  87. data/.yamllint.yml +0 -29
@@ -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_relative '../../lib/factbase'
@@ -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'
@@ -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'
@@ -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'
@@ -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 'time'
@@ -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_relative '../../lib/factbase'
@@ -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_relative '../../lib/factbase/syntax'
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'minitest/autorun'
7
+ require 'threads'
8
+ require_relative '../../lib/factbase'
9
+ require_relative '../../lib/factbase/tallied'
10
+
11
+ # Test.
12
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
13
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
14
+ # License:: MIT
15
+ class TestTallied < Minitest::Test
16
+ def test_counts_simple_changes
17
+ fb = Factbase::Tallied.new(Factbase.new)
18
+ fb.insert.bar = 3
19
+ fb.query('(exists bar)').each do |f|
20
+ f.foo = 42
21
+ end
22
+ assert_equal(1, fb.churn.inserted)
23
+ assert_equal(0, fb.churn.deleted)
24
+ assert_equal(2, fb.churn.added)
25
+ end
26
+
27
+ def test_counts_in_one
28
+ fb = Factbase::Tallied.new(Factbase.new)
29
+ fb.insert.bar = 3
30
+ assert_equal(1, fb.query('(agg (eq bar 3) (count))').one)
31
+ assert_equal(1, fb.churn.added)
32
+ end
33
+
34
+ def test_returns_all_props
35
+ fb = Factbase::Tallied.new(Factbase.new)
36
+ f = fb.insert
37
+ f.bar = 3
38
+ assert_includes(f.all_properties, 'bar')
39
+ end
40
+
41
+ def test_counts_in_txn
42
+ fb = Factbase::Tallied.new(Factbase.new)
43
+ fb.txn do |fbt|
44
+ fbt.insert.boom = 3
45
+ fbt.query('(exists boom)').each do |f|
46
+ f.foo = 88
47
+ end
48
+ end
49
+ assert_equal(1, fb.churn.inserted)
50
+ assert_equal(0, fb.churn.deleted)
51
+ assert_equal(2, fb.churn.added)
52
+ end
53
+
54
+ def test_counts_in_txn_in_threads
55
+ fb = Factbase::Tallied.new(Factbase.new)
56
+ t = 5
57
+ Threads.new(t).assert do |i|
58
+ fb.txn do |fbt|
59
+ fbt.insert.x = i
60
+ fbt.query("(eq x #{i})").each do |f|
61
+ f.send(:"a#{i}=", i)
62
+ end
63
+ fbt.query("(lt x #{t + 1})").delete!
64
+ end
65
+ end
66
+ assert_equal(0, fb.size)
67
+ assert_equal(t, fb.churn.inserted)
68
+ assert_equal(t, fb.churn.deleted)
69
+ assert_equal(t, fb.churn.added)
70
+ end
71
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'minitest/autorun'
7
+ require_relative '../../lib/factbase'
8
+ require_relative '../../lib/factbase/taped'
9
+
10
+ # Test.
11
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
12
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
13
+ # License:: MIT
14
+ class TestTaped < Minitest::Test
15
+ def test_tracks_insertion
16
+ t = Factbase::Taped.new([])
17
+ t << {}
18
+ assert_equal(1, t.inserted.size)
19
+ assert_predicate(t, :modified?)
20
+ end
21
+
22
+ def test_tracks_deletion
23
+ t = Factbase::Taped.new([{ x: 1 }, { x: 2 }])
24
+ t.delete_if { |m| m[:x] == 1 }
25
+ assert_equal(1, t.deleted.size)
26
+ end
27
+
28
+ def test_tracks_addition
29
+ h = { f: 5 }
30
+ t = Factbase::Taped.new([h])
31
+ t.each do |m|
32
+ m[:bar] = 66
33
+ end
34
+ assert_equal(1, t.added.size)
35
+ assert_equal(h.object_id, t.added.first)
36
+ end
37
+ end
@@ -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_relative '../../lib/factbase'
@@ -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_relative '../../lib/factbase/term'
@@ -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'
@@ -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'
@@ -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'
data/test/test__helper.rb CHANGED
@@ -1,28 +1,12 @@
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
  $stdout.sync = true
24
7
 
25
8
  require 'simplecov'
9
+ SimpleCov.external_at_exit = true
26
10
  SimpleCov.start
27
11
 
28
12
  require 'simplecov-cobertura'
@@ -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
- Threads.new(100).assert do
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(100, fb.size)
242
- assert_equal(100, fb.query('(eq foo 42)').each.to_a.size)
243
- assert_equal(100, fb.query('(eq bar 49)').each.to_a.size)
244
- assert_equal(100, fb.query("(eq value #{42 * 49})").each.to_a.size)
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
- Threads.new(100).assert do |i|
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(100, fb.size)
253
- Threads.new(100) do |i|
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
- total = 100
320
+ t = Concurrent.processor_count * 19
298
321
  fb = Factbase.new
299
- Threads.new(total).assert do |i|
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(total, fb.size)
306
- assert_equal(total, fb.query('(exists thread_id)').each.to_a.size)
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
- total = 100
324
- Threads.new(total).assert do |i|
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(total, facts.size)
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