xamplr 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGES.txt +13 -0
  2. data/LICENSE +3 -0
  3. data/README.rdoc +26 -0
  4. data/README.rdoc.orig +118 -0
  5. data/Rakefile +85 -0
  6. data/VERSION.yml +4 -0
  7. data/examples/random-people-shared-addresses/Makefile +16 -0
  8. data/examples/random-people-shared-addresses/batch-load-users.rb +83 -0
  9. data/examples/random-people-shared-addresses/find-mentions.rb +47 -0
  10. data/examples/random-people-shared-addresses/find-people-by-address.rb +104 -0
  11. data/examples/random-people-shared-addresses/optimise.rb +16 -0
  12. data/examples/random-people-shared-addresses/people.rb +35 -0
  13. data/examples/random-people-shared-addresses/query.rb +75 -0
  14. data/examples/random-people-shared-addresses/query2.rb +73 -0
  15. data/examples/random-people-shared-addresses/random-names.csv +10000 -0
  16. data/examples/random-people-shared-addresses/settings.rb +3 -0
  17. data/examples/random-people-shared-addresses/what-to-query-on.rb +82 -0
  18. data/examples/random-people-shared-addresses/xampl-gen.rb +36 -0
  19. data/examples/random-people-shared-addresses/xml/people.xml +14 -0
  20. data/examples/random-people/Makefile +16 -0
  21. data/examples/random-people/batch-load-users.rb +61 -0
  22. data/examples/random-people/optimise.rb +16 -0
  23. data/examples/random-people/people.rb +22 -0
  24. data/examples/random-people/query.rb +73 -0
  25. data/examples/random-people/query2.rb +73 -0
  26. data/examples/random-people/random-names.csv +10000 -0
  27. data/examples/random-people/rawtc.rb +91 -0
  28. data/examples/random-people/settings.rb +3 -0
  29. data/examples/random-people/what-to-query-on.rb +80 -0
  30. data/examples/random-people/xampl-gen.rb +36 -0
  31. data/examples/random-people/xml/people.xml +11 -0
  32. data/examples/read-testing/Makefile +10 -0
  33. data/examples/read-testing/load.rb +65 -0
  34. data/examples/read-testing/read.rb +51 -0
  35. data/examples/read-testing/rrr.rb +87 -0
  36. data/examples/read-testing/settings.rb +2 -0
  37. data/examples/read-testing/xampl-gen.rb +36 -0
  38. data/examples/read-testing/xml/text.xml +8 -0
  39. data/examples/tokyo-cabinet-experimental/expt-query.rb +42 -0
  40. data/examples/tokyo-cabinet-experimental/expt-query2.rb +42 -0
  41. data/examples/tokyo-cabinet-experimental/expt-query3.rb +41 -0
  42. data/examples/tokyo-cabinet-experimental/expt-reader.rb +32 -0
  43. data/examples/tokyo-cabinet-experimental/expt.rb +61 -0
  44. data/examples/tokyo-cabinet-experimental/xampl-gen.rb +36 -0
  45. data/examples/tokyo-cabinet-experimental/xml/tcx.xml +6 -0
  46. data/lib/xampl-generator.rb +3 -0
  47. data/lib/xampl.rb +3 -0
  48. data/lib/xamplr-generator.rb +10 -0
  49. data/lib/xamplr.rb +37 -0
  50. data/lib/xamplr/README-POSSIBLE-PROBLEMS +5 -0
  51. data/lib/xamplr/TODO +1 -0
  52. data/lib/xamplr/exceptions.rb +97 -0
  53. data/lib/xamplr/from-xml-orig.rb +350 -0
  54. data/lib/xamplr/from-xml.rb +439 -0
  55. data/lib/xamplr/gen-elements.xml +6230 -0
  56. data/lib/xamplr/gen.elements.xml +108 -0
  57. data/lib/xamplr/generate-elements.rb +15 -0
  58. data/lib/xamplr/generator.rb +5 -0
  59. data/lib/xamplr/graphml-out.rb +470 -0
  60. data/lib/xamplr/handwritten/example.rb +698 -0
  61. data/lib/xamplr/handwritten/hand-example.rb +533 -0
  62. data/lib/xamplr/handwritten/test-handwritten.rb +873 -0
  63. data/lib/xamplr/indexed-array.rb +115 -0
  64. data/lib/xamplr/mixins.rb +397 -0
  65. data/lib/xamplr/my.gen.elements.xml +461 -0
  66. data/lib/xamplr/notifications.rb +57 -0
  67. data/lib/xamplr/obsolete/fsdb.rb +62 -0
  68. data/lib/xamplr/persist-to-xml.rb +249 -0
  69. data/lib/xamplr/persistence.rb +522 -0
  70. data/lib/xamplr/persistence.rb.more_thread_safe +771 -0
  71. data/lib/xamplr/persistence.rb.partially_thread_safe +763 -0
  72. data/lib/xamplr/persister.rb +310 -0
  73. data/lib/xamplr/persisters/caches.rb +186 -0
  74. data/lib/xamplr/persisters/caching.rb +172 -0
  75. data/lib/xamplr/persisters/filesystem.rb +60 -0
  76. data/lib/xamplr/persisters/in-memory.rb +180 -0
  77. data/lib/xamplr/persisters/simple.rb +59 -0
  78. data/lib/xamplr/persisters/tokyo-cabinet.rb +641 -0
  79. data/lib/xamplr/simpleTemplate/danger.rx +4 -0
  80. data/lib/xamplr/simpleTemplate/obsolete/input-c.r4 +35 -0
  81. data/lib/xamplr/simpleTemplate/obsolete/play.r6.txt +12 -0
  82. data/lib/xamplr/simpleTemplate/obsolete/play_more.r6.txt +20 -0
  83. data/lib/xamplr/simpleTemplate/obsolete/test001.r5 +8 -0
  84. data/lib/xamplr/simpleTemplate/obsolete/test002.r5 +13 -0
  85. data/lib/xamplr/simpleTemplate/obsolete/test003.r5 +37 -0
  86. data/lib/xamplr/simpleTemplate/old/r6.000.rb +122 -0
  87. data/lib/xamplr/simpleTemplate/old/r6.001.rb +145 -0
  88. data/lib/xamplr/simpleTemplate/play.r6 +12 -0
  89. data/lib/xamplr/simpleTemplate/play_more.r6 +20 -0
  90. data/lib/xamplr/simpleTemplate/play_noblanks.r6 +21 -0
  91. data/lib/xamplr/simpleTemplate/playq.r6 +16 -0
  92. data/lib/xamplr/simpleTemplate/r6.rb +87 -0
  93. data/lib/xamplr/simpleTemplate/simple-template.rb +75 -0
  94. data/lib/xamplr/templates/child.template +47 -0
  95. data/lib/xamplr/templates/child_indexed.template +89 -0
  96. data/lib/xamplr/templates/child_modules.template +5 -0
  97. data/lib/xamplr/templates/element_classes.template +11 -0
  98. data/lib/xamplr/templates/element_data.template +282 -0
  99. data/lib/xamplr/templates/element_empty.template +285 -0
  100. data/lib/xamplr/templates/element_mixed.template +277 -0
  101. data/lib/xamplr/templates/element_simple.template +276 -0
  102. data/lib/xamplr/templates/package.template +26 -0
  103. data/lib/xamplr/test-support/Makefile +47 -0
  104. data/lib/xamplr/test-support/bench-cache.rb +80 -0
  105. data/lib/xamplr/test-support/bench-script.rb +21 -0
  106. data/lib/xamplr/test-support/bench.rb +116 -0
  107. data/lib/xamplr/test-support/bench2.rb +132 -0
  108. data/lib/xamplr/test-support/test-cache.rb +147 -0
  109. data/lib/xamplr/test-support/test-data/binding.xml +7 -0
  110. data/lib/xamplr/test-support/test-data/example.xml +14 -0
  111. data/lib/xamplr/test-support/test-data/internationalization-utf8.txt +1 -0
  112. data/lib/xamplr/test-support/test-data/labels.xml +37 -0
  113. data/lib/xamplr/test-support/test-data/labels001.xml +38 -0
  114. data/lib/xamplr/test-support/test-deep-change.rb +135 -0
  115. data/lib/xamplr/test-support/test-elements.rb +109 -0
  116. data/lib/xamplr/test-support/test-indexed-array.rb +169 -0
  117. data/lib/xamplr/test-support/test-misc.rb +73 -0
  118. data/lib/xamplr/test-support/test-names.rb +67 -0
  119. data/lib/xamplr/test-support/test-rollback.rb +106 -0
  120. data/lib/xamplr/test-support/test.rb +1504 -0
  121. data/lib/xamplr/to-ruby.rb +220 -0
  122. data/lib/xamplr/to-xml.rb +158 -0
  123. data/lib/xamplr/version.rb +67 -0
  124. data/lib/xamplr/visitor.rb +140 -0
  125. data/lib/xamplr/visitors.rb +573 -0
  126. data/lib/xamplr/xampl-generator.rb +533 -0
  127. data/lib/xamplr/xampl-hand-generated.rb +1535 -0
  128. data/lib/xamplr/xampl-module.rb +36 -0
  129. data/lib/xamplr/xampl-object-internals.rb +6 -0
  130. data/lib/xamplr/xampl-object.rb +202 -0
  131. data/lib/xamplr/xampl-persisted-object.rb +122 -0
  132. data/lib/xamplr/xml-text.rb +117 -0
  133. data/lib/xamplr/xml/document.xml +7 -0
  134. data/lib/xamplr/xml/elements.xml +101 -0
  135. data/lib/xamplr/xml/elements000.xml +73 -0
  136. data/lib/xamplr/xml/example.xml +23 -0
  137. data/lib/xamplr/xml/options.xml +12 -0
  138. data/lib/xamplr/xml/uche.xml +38 -0
  139. data/lib/xamplr/yEd-sample.graphml +300 -0
  140. data/test/test_helper.rb +10 -0
  141. data/test/xamplr_test.rb +7 -0
  142. metadata +245 -0
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "xamplr"
4
+ include Xampl
5
+
6
+ require "tmp/XamplExample"
7
+ include XamplExample
8
+
9
+ require "benchmark"
10
+ include Benchmark
11
+
12
+ #
13
+ # results from 16 October 2005
14
+ #
15
+
16
+ #Rebuilding From String (XML) count: 1000 (est. ~ 11s)
17
+ # user system total real
18
+ #xml 5.970000 0.080000 6.050000 ( 6.573804)
19
+ #ruby 1.660000 0.030000 1.690000 ( 2.017015)
20
+
21
+ #Serialize to String (XML) count: 1000 (est. ~ 25s)
22
+ # user system total real
23
+ #xml 1.460000 0.020000 1.480000 ( 1.576753)
24
+ #ruby 0.890000 0.010000 0.900000 ( 1.102071)
25
+
26
+ #Round Tripping (XML) count: 1000 (est. ~ 40s)
27
+ # user system total real
28
+ #xml 7.890000 0.110000 8.000000 ( 8.860720)
29
+ #ruby 2.780000 0.040000 2.820000 ( 3.131707)
30
+
31
+ module Bench
32
+
33
+ def Bench.go
34
+ count = 1000
35
+
36
+ emph_content_1 = "there"
37
+ emph1 = Emph.new
38
+ emph1 << emph_content_1
39
+
40
+ emph_content_2 = "are"
41
+ emph2 = Emph.new
42
+ emph2.content = emph_content_2
43
+
44
+ desc1 = Description.new
45
+ desc1.kind = "desc1"
46
+
47
+ desc1.is_changed = nil
48
+ desc1 << "hello " << emph1 << "! How " << emph2 << " you?"
49
+
50
+ thing = Thing.new
51
+ thing.pid = "thing"
52
+ thing.new_stuff.kind = "stuff1"
53
+ thing << desc1
54
+
55
+ big_thing = Thing.new
56
+ big_thing << thing
57
+
58
+ #require "to-ruby"
59
+ #ruby_printer = RubyPrinter.new
60
+ #ruby_s = ruby_printer.to_ruby(thing)
61
+ ruby_s = thing.to_ruby
62
+ xml_s = thing.persist
63
+
64
+ puts xml_s
65
+ puts ruby_s
66
+ puts "++++++++++++++++++++++++++++++++++++"
67
+ puts "big_thing #{big_thing.object_id}, thing #{thing.object_id}"
68
+ puts big_thing.to_ruby
69
+ puts "++++++++++++++++++++++++++++++++++++"
70
+
71
+ puts "Rebuilding From String (XML) count: #{count} (est. ~ 11s)"
72
+ bm(10) do | x |
73
+ x.report("xml") {
74
+ count.times {
75
+ another_big_thing = XamplObject.from_xml_string(xml_s)
76
+ }
77
+ }
78
+ x.report("ruby") {
79
+ count.times {
80
+ XamplObject.from_ruby(ruby_s)
81
+ }
82
+ }
83
+ end
84
+
85
+ puts "Serialize to String (XML) count: #{count} (est. ~ 25s)"
86
+ bm(10) do | x |
87
+ x.report("xml") {
88
+ count.times {
89
+ xml_s = thing.persist
90
+ }
91
+ }
92
+ x.report("ruby") {
93
+ count.times {
94
+ ruby_s = thing.to_ruby
95
+ }
96
+ }
97
+ end
98
+
99
+ puts "Round Tripping (XML) count: #{count} (est. ~ 40s)"
100
+ bm(10) do | x |
101
+ x.report("xml") {
102
+ count.times {
103
+ another_thing = XamplObject.from_xml_string(thing.persist)
104
+ }
105
+ }
106
+ x.report("ruby") {
107
+ count.times {
108
+ XamplObject.from_ruby(thing.to_ruby)
109
+ }
110
+ }
111
+ end
112
+ end
113
+ end
114
+
115
+ Bench.go
116
+
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "xamplr"
4
+ include Xampl
5
+
6
+ require "tmp/XamplExample"
7
+ include XamplExample
8
+
9
+ require "benchmark"
10
+ include Benchmark
11
+
12
+ #require 'persister/fsdb'
13
+
14
+ module Bench
15
+
16
+ def Bench.go
17
+ count_things = 1000
18
+ count = 10
19
+
20
+ puts "NO ROLLBACKS..."
21
+ writes = 0
22
+ bm(10) do | x |
23
+ x.report("simple") {
24
+ Xampl.enable_persister("bench2_no_rollback_simple", :simple)
25
+ Bench.no_rollbacks(count_things, count)
26
+ }
27
+ x.report("in_memory") {
28
+ Xampl.enable_persister("bench2_no_rollback_in_memory", :in_memory)
29
+ Bench.no_rollbacks(count_things, count)
30
+ }
31
+ x.report("filesystem") {
32
+ Xampl.enable_persister("bench2_no_rollback_filesystem", :filesystem)
33
+ writes += Bench.no_rollbacks(count_things, count)
34
+ }
35
+ # x.report("fsdb") {
36
+ # Xampl.enable_persister("bench2_no_rollback_fsdb", :fsdb)
37
+ # Bench.no_rollbacks(count_things, count)
38
+ # }
39
+ end
40
+ puts " writes: #{writes}"
41
+
42
+ writes = 0
43
+ puts "WITH ROLLBACKS..."
44
+ bm(10) do | x |
45
+ x.report("simple") {
46
+ Xampl.enable_persister("bench2_rollback_simple", :simple)
47
+ Bench.rollbacks(count_things, count)
48
+ }
49
+ x.report("in_memory") {
50
+ Xampl.enable_persister("bench2_rollback_in_memory", :in_memory)
51
+ Bench.rollbacks(count_things, count)
52
+ }
53
+ x.report("filesystem") {
54
+ Xampl.enable_persister("bench2_rollback_filesystem", :filesystem)
55
+ writes += Bench.rollbacks(count_things, count)
56
+ }
57
+ # x.report("fsdb") {
58
+ # Xampl.enable_persister("bench2_rollback_fsdb", :fsdb)
59
+ # Bench.rollbacks(count_things, count)
60
+ # }
61
+ end
62
+ puts " writes: #{writes}"
63
+ end
64
+
65
+ def Bench.no_rollbacks(count_things, count)
66
+ writes = 0
67
+ things = []
68
+ count_things.times { | i |
69
+ thing = Bench.make_a_thing("thing-#{i}")
70
+ Xampl.introduce_to_persister(thing)
71
+ things << thing
72
+ }
73
+
74
+ things.each{ | thing | Xampl.introduce_to_persister(thing) }
75
+ count.times { | time |
76
+ things.each{ | thing |
77
+ thing.info = [thing.pid, time].join
78
+ }
79
+ writes += Xampl.sync
80
+ }
81
+ return writes
82
+ end
83
+
84
+ def Bench.rollbacks(count_things, count)
85
+ writes = 0
86
+ things = []
87
+ count_things.times { | i |
88
+ thing = Bench.make_a_thing("thing-#{i}")
89
+ Xampl.introduce_to_persister(thing)
90
+ things << thing
91
+ }
92
+
93
+ things.each{ | thing | Xampl.introduce_to_persister(thing) }
94
+ count.times { | time |
95
+ writes += Xampl.sync
96
+ Xampl.rollback
97
+
98
+ things.each{ | thing |
99
+ thing.info = [thing.pid, time].join
100
+ }
101
+ }
102
+ return writes
103
+ end
104
+
105
+ def Bench.make_a_thing(pid)
106
+ emph_content_1 = "there"
107
+ emph1 = Emph.new
108
+ emph1 << emph_content_1
109
+
110
+ emph_content_2 = "are"
111
+ emph2 = Emph.new
112
+ emph2.content = emph_content_2
113
+
114
+ desc1 = Description.new
115
+ desc1.kind = "desc1"
116
+
117
+ desc1.is_changed = nil
118
+ desc1 << "hello " << emph1 << "! How " << emph2 << " you?"
119
+
120
+ thing = Thing.new
121
+ thing.pid = pid
122
+ thing.info = pid
123
+ thing.new_stuff.kind = "stuff1"
124
+ thing << desc1
125
+
126
+ return thing
127
+ end
128
+
129
+ end
130
+
131
+ Bench.go
132
+
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require "test/unit"
4
+ require "xamplr"
5
+
6
+ class TestXampl < Test::Unit::TestCase
7
+
8
+ def setup
9
+ Xampl.disable_all_persisters
10
+ end
11
+
12
+ def test_lose_the_first
13
+ cache = Xampl::XamplCache.new(10)
14
+ assert(cache)
15
+
16
+ cache['first'] = 'first'
17
+ assert(cache['first'])
18
+
19
+ 10.times { | i |
20
+ id = "id.#{i}"
21
+ cache[id] = id
22
+ }
23
+ assert_nil(cache['first'])
24
+ end
25
+
26
+ def test_lose_the_second
27
+ cache = Xampl::XamplCache.new(10)
28
+ assert(cache)
29
+
30
+ cache['first'] = 'first'
31
+ cache['second'] = 'second'
32
+ assert(cache['first'])
33
+ assert(cache['second'])
34
+
35
+ 10.times { | i |
36
+ id = "id.#{i}"
37
+ cache[id] = id
38
+ use_first = cache['first']
39
+ }
40
+ assert(cache['first'])
41
+ assert_nil(cache['second'])
42
+ end
43
+
44
+ def test_lose_the_first_XamplCache
45
+ cache = Xampl::XamplCache.new(10)
46
+ assert(cache)
47
+
48
+ assert_nil(cache['dummy'])
49
+
50
+ cache['dummy'] = 'dummy'
51
+ assert_equal(1, cache.size)
52
+ cache.delete('dummy')
53
+ assert_equal(0, cache.size)
54
+ assert_nil(cache['dummy'])
55
+
56
+ cache['first'] = 'first-value'
57
+ assert(cache['first'])
58
+
59
+ 10.times { | i |
60
+ key = "thing.#{i}"
61
+ value = "value.#{i}"
62
+ cache[key] = value
63
+ }
64
+ assert_nil(cache['first'])
65
+ end
66
+
67
+ def test_lose_the_second_XamplCache
68
+ cache = Xampl::XamplCache.new(10)
69
+ assert(cache)
70
+
71
+ # fill the cache
72
+ 10.times { | i |
73
+ id = "id.#{i}"
74
+ cache[id] = id
75
+ use_first = cache['first']
76
+ }
77
+
78
+ cache['first'] = 'first'
79
+ cache['second'] = 'second'
80
+ assert(cache['first'])
81
+ assert(cache['second'])
82
+
83
+ 10.times { | i |
84
+ use_first = cache['first']
85
+
86
+ id = "id.#{10 + i}"
87
+ cache[id] = id
88
+ }
89
+
90
+ assert(cache['first'])
91
+ assert_nil(cache['second'])
92
+ end
93
+
94
+ def test_lose_the_first_XamplCacheLFU
95
+ cache = Xampl::XamplCacheLFU.new(10)
96
+ assert(cache)
97
+
98
+ assert_nil(cache['dummy'])
99
+
100
+ cache['dummy'] = 'dummy'
101
+ assert_equal(1, cache.size)
102
+ cache.delete('dummy')
103
+ assert_equal(0, cache.size)
104
+ assert_nil(cache['dummy'])
105
+
106
+ cache['first'] = 'first-value'
107
+ assert(cache['first'])
108
+ cache.delete('first')
109
+ assert_nil(cache['first'])
110
+ cache['first'] = 'first-value'
111
+
112
+ 10.times { | i |
113
+ key = "thing.#{i}"
114
+ value = "value.#{i}"
115
+ cache[key] = value
116
+ thing = cache[key]
117
+ }
118
+ assert_nil(cache['first'])
119
+ end
120
+
121
+ def test_lose_the_second_XamplCacheLFU
122
+ cache = Xampl::XamplCacheLFU.new(10)
123
+ assert(cache)
124
+
125
+ # fill the cache
126
+ 10.times { | i |
127
+ id = "id.#{i}"
128
+ cache[id] = id
129
+ use_first = cache['first']
130
+ }
131
+
132
+ cache['first'] = 'first'
133
+ cache['second'] = 'second'
134
+ assert(cache['first'])
135
+ assert(cache['second'])
136
+
137
+ 10.times { | i |
138
+ use_first = cache['first']
139
+
140
+ id = "id.#{10 + i}"
141
+ cache[id] = id
142
+ }
143
+
144
+ assert(cache['first'])
145
+ assert_nil(cache['second'])
146
+ end
147
+ end
@@ -0,0 +1,7 @@
1
+ <document>
2
+ <p>This
3
+ <emph>is</emph>
4
+ <strong>very</strong>
5
+ important
6
+ </p>
7
+ </document>
@@ -0,0 +1,14 @@
1
+ <things xmlns:xampl='http://xampl.com/example/play'>
2
+ <thing pid=''>
3
+ <description kind=''>blah
4
+ <emph>blah</emph>
5
+ blah
6
+ </description>
7
+ <keyValue id=''
8
+ value=''/>
9
+ <stuff kind=''
10
+ xampl:special=''/>
11
+ <thing pid=''/>
12
+ <things/>
13
+ </thing>
14
+ </things>
@@ -0,0 +1 @@
1
+ Iñtërnâtiônàlizætiøn
@@ -0,0 +1,37 @@
1
+ <labels>
2
+ <label id="tse"
3
+ added="2003-06-20">
4
+ <name>Thomas Eliot</name>
5
+ <address>
6
+ <street>3 Prufrock Lane</street>
7
+ <city>Stamford</city>
8
+ <state>CT</state>
9
+ </address>
10
+ <quote>
11
+ <emph>Midwinter Spring</emph>
12
+ is its own season&#8230;
13
+ </quote>
14
+ </label>
15
+ <label id="ep"
16
+ added="2003-06-10">
17
+ <name>Ezra Pound</name>
18
+ <address>
19
+ <street>45 Usura Place</street>
20
+ <city>Hailey</city>
21
+ <state>ID</state>
22
+ </address>
23
+ <quote>
24
+ What thou lovest well remains, the rest is dross&#8230;
25
+ </quote>
26
+ </label>
27
+ <!-- Throw in 10,000 more records just like this -->
28
+ <label id="lh"
29
+ added="2004-11-01">
30
+ <name>Langston Hughes</name>
31
+ <address>
32
+ <street>10 Bridge Tunnel</street>
33
+ <city>Harlem</city>
34
+ <state>NY</state>
35
+ </address>
36
+ </label>
37
+ </labels>