diametric 0.0.4 → 0.1.1
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 +15 -0
- data/Gemfile +21 -18
- data/Jarfile +15 -1
- data/README.md +22 -14
- data/Rakefile +17 -1
- data/bin/datomic-rest +33 -0
- data/bin/download-datomic +13 -0
- data/datomic_version.yml +4 -0
- data/diametric.gemspec +9 -6
- data/ext/diametric/DiametricCollection.java +147 -0
- data/ext/diametric/DiametricConnection.java +113 -0
- data/ext/diametric/DiametricDatabase.java +107 -0
- data/ext/diametric/DiametricEntity.java +90 -0
- data/ext/diametric/DiametricListenableFuture.java +47 -0
- data/ext/diametric/DiametricObject.java +66 -0
- data/ext/diametric/DiametricPeer.java +414 -0
- data/ext/diametric/DiametricService.java +102 -0
- data/ext/diametric/DiametricUUID.java +61 -0
- data/ext/diametric/DiametricUtils.java +183 -0
- data/lib/boolean_type.rb +3 -0
- data/lib/diametric.rb +24 -0
- data/lib/diametric/entity.rb +219 -14
- data/lib/diametric/generators/active_model.rb +2 -2
- data/lib/diametric/persistence.rb +0 -1
- data/lib/diametric/persistence/common.rb +28 -9
- data/lib/diametric/persistence/peer.rb +122 -87
- data/lib/diametric/persistence/rest.rb +4 -3
- data/lib/diametric/query.rb +94 -23
- data/lib/diametric/rest_service.rb +74 -0
- data/lib/diametric/service_base.rb +77 -0
- data/lib/diametric/transactor.rb +86 -0
- data/lib/diametric/version.rb +1 -1
- data/lib/diametric_service.jar +0 -0
- data/lib/value_enums.rb +8 -0
- data/spec/conf_helper.rb +55 -0
- data/spec/config/free-transactor-template.properties +73 -0
- data/spec/config/logback.xml +59 -0
- data/spec/data/seattle-data0.dtm +452 -0
- data/spec/data/seattle-data1.dtm +326 -0
- data/spec/developer_create_sample.rb +39 -0
- data/spec/developer_query_spec.rb +120 -0
- data/spec/diametric/config_spec.rb +1 -1
- data/spec/diametric/entity_spec.rb +263 -0
- data/spec/diametric/peer_api_spec.rb +147 -0
- data/spec/diametric/persistence/peer_many2many_spec.rb +76 -0
- data/spec/diametric/persistence/peer_spec.rb +13 -22
- data/spec/diametric/persistence/rest_spec.rb +12 -19
- data/spec/diametric/query_spec.rb +4 -5
- data/spec/diametric/rest_service_spec.rb +56 -0
- data/spec/diametric/transactor_spec.rb +68 -0
- data/spec/integration_spec.rb +5 -3
- data/spec/parent_child_sample.rb +42 -0
- data/spec/peer_integration_spec.rb +106 -22
- data/spec/peer_seattle_spec.rb +200 -0
- data/spec/rc2013_seattle_big.rb +82 -0
- data/spec/rc2013_seattle_small.rb +60 -0
- data/spec/rc2013_simple_sample.rb +72 -0
- data/spec/seattle_integration_spec.rb +106 -0
- data/spec/simple_validation_sample.rb +31 -0
- data/spec/spec_helper.rb +31 -45
- data/spec/support/entities.rb +157 -0
- data/spec/support/gen_entity_class.rb +2 -0
- data/spec/support/persistence_examples.rb +9 -5
- data/spec/test_version_file.yml +4 -0
- metadata +131 -75
- data/Jarfile.lock +0 -134
- data/lib/jrclj.rb +0 -63
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'conf_helper'
|
|
2
|
+
|
|
3
|
+
class Developer
|
|
4
|
+
include Diametric::Entity
|
|
5
|
+
include Diametric::Persistence::Peer
|
|
6
|
+
|
|
7
|
+
attribute :name, String
|
|
8
|
+
attribute :friends, Ref, :cardinality => :many
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "RailsConf 2013", :jruby => true do
|
|
12
|
+
context Developer do
|
|
13
|
+
before(:all) do
|
|
14
|
+
datomic_uri = "datomic:mem://developer-#{SecureRandom.uuid}"
|
|
15
|
+
@conn = Diametric::Persistence::Peer.connect(datomic_uri)
|
|
16
|
+
end
|
|
17
|
+
after(:all) do
|
|
18
|
+
@conn.release
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should create schema and save instaces" do
|
|
22
|
+
binding.pry
|
|
23
|
+
Developer.create_schema(@conn)
|
|
24
|
+
|
|
25
|
+
yoko = Developer.new
|
|
26
|
+
yoko.name = "Yoko Harada"
|
|
27
|
+
yoko.save
|
|
28
|
+
binding.pry
|
|
29
|
+
|
|
30
|
+
clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
|
|
31
|
+
clinton.save
|
|
32
|
+
binding.pry
|
|
33
|
+
|
|
34
|
+
ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
|
|
35
|
+
ryan.save
|
|
36
|
+
binding.pry
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Developer
|
|
4
|
+
include Diametric::Entity
|
|
5
|
+
include Diametric::Persistence::Peer
|
|
6
|
+
|
|
7
|
+
attribute :name, String
|
|
8
|
+
attribute :nerd_rate, Integer
|
|
9
|
+
attribute :friends, Ref, :cardinality => :many
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe Developer, :jruby => true do
|
|
13
|
+
before do
|
|
14
|
+
datomic_uri = "datomic:mem://developer-#{SecureRandom.uuid}"
|
|
15
|
+
@conn = Diametric::Persistence::Peer.connect(datomic_uri)
|
|
16
|
+
Developer.create_schema(@conn)
|
|
17
|
+
end
|
|
18
|
+
after do
|
|
19
|
+
@conn.release
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should save an instace and get it" do
|
|
23
|
+
yoko = Developer.new
|
|
24
|
+
yoko.name = "Yoko Harada"
|
|
25
|
+
yoko.save(@conn)
|
|
26
|
+
query = Diametric::Query.new(Developer, @conn, true)
|
|
27
|
+
result = query.all
|
|
28
|
+
result.size.should == 1
|
|
29
|
+
result.first.name.should == "Yoko Harada"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should make query with the argument" do
|
|
33
|
+
yoko = Developer.new
|
|
34
|
+
yoko.name = "Yoko Harada"
|
|
35
|
+
yoko.nerd_rate = 50
|
|
36
|
+
yoko.save(@conn)
|
|
37
|
+
query = Diametric::Query.new(Developer, @conn, true).where(:name => "Yoko Harada")
|
|
38
|
+
query_data = "[:find ?e :in $ [?name] :where [?e :developer/name ?name]]"
|
|
39
|
+
query.data.first.gsub(" ", "").should == query_data.gsub(" ", "")
|
|
40
|
+
result = query.all
|
|
41
|
+
result.size.should == 1
|
|
42
|
+
result.first.nerd_rate.should == 50
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should not resolve referenced object" do
|
|
46
|
+
yoko = Developer.new
|
|
47
|
+
yoko.name = "Yoko Harada"
|
|
48
|
+
yoko.nerd_rate = 50
|
|
49
|
+
yoko.save(@conn)
|
|
50
|
+
clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
|
|
51
|
+
clinton.nerd_rate = 98
|
|
52
|
+
clinton.save(@conn)
|
|
53
|
+
|
|
54
|
+
query = Diametric::Query.new(Developer, @conn).where(:name => "Clinton N. Dreisbach")
|
|
55
|
+
result = query.all
|
|
56
|
+
result.size.should == 1
|
|
57
|
+
|
|
58
|
+
developer = Developer.from_dbid_or_entity(result.first, @conn.db, false)
|
|
59
|
+
friends = developer.friends
|
|
60
|
+
friends.each do |f|
|
|
61
|
+
f.should be_a(Java::DatomicQuery::EntityMap)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should find three developers" do
|
|
66
|
+
yoko = Developer.new
|
|
67
|
+
yoko.name = "Yoko Harada"
|
|
68
|
+
yoko.nerd_rate = 50
|
|
69
|
+
yoko.save(@conn)
|
|
70
|
+
clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
|
|
71
|
+
clinton.nerd_rate = 98
|
|
72
|
+
clinton.save(@conn)
|
|
73
|
+
ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
|
|
74
|
+
ryan.nerd_rate = 80
|
|
75
|
+
ryan.save(@conn)
|
|
76
|
+
|
|
77
|
+
query = Diametric::Query.new(Developer, @conn)
|
|
78
|
+
result = query.all
|
|
79
|
+
result.size.should == 3
|
|
80
|
+
resolved_result = result.map {|m| Developer.from_dbid_or_entity(m, @conn)}
|
|
81
|
+
resolved_result.collect(&:nerd_rate).should =~ [50, 98, 80]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should filter out developers" do
|
|
85
|
+
yoko = Developer.new
|
|
86
|
+
yoko.name = "Yoko Harada"
|
|
87
|
+
yoko.nerd_rate = 50
|
|
88
|
+
yoko.save(@conn)
|
|
89
|
+
clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
|
|
90
|
+
clinton.nerd_rate = 98
|
|
91
|
+
clinton.save(@conn)
|
|
92
|
+
ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
|
|
93
|
+
ryan.nerd_rate = 80
|
|
94
|
+
ryan.save(@conn)
|
|
95
|
+
|
|
96
|
+
query = Diametric::Query.new(Developer, @conn).filter(:>, :nerd_rate, 70)
|
|
97
|
+
query_data = "[:find ?e :in $ :where [?e :developer/nerd_rate ?nerd_rate] [(> ?nerd_rate 70)]]"
|
|
98
|
+
query.data.first.gsub(" ", "").should == query_data.gsub(" ", "")
|
|
99
|
+
result = query.all
|
|
100
|
+
result.size.should == 2
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should resolve referenced objects" do
|
|
104
|
+
yoko = Developer.new
|
|
105
|
+
yoko.name = "Yoko Harada"
|
|
106
|
+
yoko.nerd_rate = 50
|
|
107
|
+
yoko.save(@conn)
|
|
108
|
+
clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
|
|
109
|
+
clinton.nerd_rate = 98
|
|
110
|
+
clinton.save(@conn)
|
|
111
|
+
ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
|
|
112
|
+
ryan.nerd_rate = 80
|
|
113
|
+
ryan.save(@conn)
|
|
114
|
+
|
|
115
|
+
query = Diametric::Query.new(Developer, @conn, true).where(:name => "Ryan Neufeld")
|
|
116
|
+
result = query.all
|
|
117
|
+
result.size.should == 1
|
|
118
|
+
result.first.friends.collect(&:name).should =~ ["Yoko Harada", "Clinton N. Dreisbach"]
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -52,7 +52,7 @@ describe Diametric::Config do
|
|
|
52
52
|
|
|
53
53
|
describe ".connect!" do
|
|
54
54
|
it "establishes a base connection" do
|
|
55
|
-
settings =
|
|
55
|
+
settings = double
|
|
56
56
|
Diametric::Persistence.should_receive(:establish_base_connection).with(settings)
|
|
57
57
|
Diametric::Config.connect!(settings)
|
|
58
58
|
end
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
require 'diametric/entity'
|
|
3
|
+
|
|
4
|
+
require 'rspec/expectations'
|
|
5
|
+
|
|
6
|
+
RSpec::Matchers.define :be_an_equivalent_hash do |expected|
|
|
7
|
+
match do |actual|
|
|
8
|
+
status = true
|
|
9
|
+
expected.each do |k, v|
|
|
10
|
+
next if k == ":db/id"
|
|
11
|
+
status = false if actual[k].nil?
|
|
12
|
+
status = false unless actual[k] == v
|
|
13
|
+
end
|
|
14
|
+
status
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
RSpec::Matchers.define :be_an_equivalent_array do |expected|
|
|
19
|
+
match do |actual|
|
|
20
|
+
status = true
|
|
21
|
+
expected.each_with_index do |e, index|
|
|
22
|
+
next if e == "#db/id[:db.part/user]"
|
|
23
|
+
status = false unless actual[index] == e
|
|
24
|
+
end
|
|
25
|
+
status
|
|
26
|
+
end
|
|
27
|
+
end
|
|
2
28
|
|
|
3
29
|
describe Diametric::Entity do
|
|
4
30
|
describe "in a class" do
|
|
@@ -210,4 +236,241 @@ describe Diametric::Entity do
|
|
|
210
236
|
end
|
|
211
237
|
|
|
212
238
|
end
|
|
239
|
+
|
|
240
|
+
context "boolean type" do
|
|
241
|
+
subject { Choice }
|
|
242
|
+
|
|
243
|
+
it "should generate a schema" do
|
|
244
|
+
expected = []
|
|
245
|
+
if is_jruby?
|
|
246
|
+
expected = [
|
|
247
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
248
|
+
":db/ident" => ":choice/item",
|
|
249
|
+
":db/valueType" => ":db.type/string",
|
|
250
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
251
|
+
":db.install/_attribute" => ":db.part/db" },
|
|
252
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
253
|
+
":db/ident" => ":choice/checked",
|
|
254
|
+
":db/valueType" => ":db.type/boolean",
|
|
255
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
256
|
+
":db.install/_attribute" => ":db.part/db" }
|
|
257
|
+
]
|
|
258
|
+
else
|
|
259
|
+
expected = [
|
|
260
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
261
|
+
:"db/ident" => :"choice/item",
|
|
262
|
+
:"db/valueType" => :"db.type/string",
|
|
263
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
264
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
265
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
266
|
+
:"db/ident" => :"choice/checked",
|
|
267
|
+
:"db/valueType" => :"db.type/boolean",
|
|
268
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
269
|
+
:"db.install/_attribute" => :"db.part/db" }
|
|
270
|
+
]
|
|
271
|
+
end
|
|
272
|
+
@created_schema = subject.schema
|
|
273
|
+
expected.each do |e|
|
|
274
|
+
@created_schema.shift.should be_an_equivalent_hash(e)
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
context "uuid type" do
|
|
280
|
+
subject { Customer }
|
|
281
|
+
|
|
282
|
+
it "should generate a schema" do
|
|
283
|
+
expected = []
|
|
284
|
+
if is_jruby?
|
|
285
|
+
expected = [
|
|
286
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
287
|
+
":db/ident" => ":customer/name",
|
|
288
|
+
":db/valueType" => ":db.type/string",
|
|
289
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
290
|
+
":db.install/_attribute" => ":db.part/db" },
|
|
291
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
292
|
+
":db/ident" => ":customer/id",
|
|
293
|
+
":db/valueType" => ":db.type/uuid",
|
|
294
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
295
|
+
":db.install/_attribute" => ":db.part/db" }
|
|
296
|
+
]
|
|
297
|
+
else
|
|
298
|
+
expected = [
|
|
299
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
300
|
+
:"db/ident" => :"customer/name",
|
|
301
|
+
:"db/valueType" => :"db.type/string",
|
|
302
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
303
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
304
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
305
|
+
:"db/ident" => :"customer/id",
|
|
306
|
+
:"db/valueType" => :"db.type/uuid",
|
|
307
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
308
|
+
:"db.install/_attribute" => :"db.part/db" }
|
|
309
|
+
]
|
|
310
|
+
end
|
|
311
|
+
@created_schema = subject.schema
|
|
312
|
+
expected.each do |e|
|
|
313
|
+
@created_schema.shift.should be_an_equivalent_hash(e)
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
context "Float, Double type" do
|
|
319
|
+
subject { Account }
|
|
320
|
+
|
|
321
|
+
it "should generate a schema" do
|
|
322
|
+
expected = []
|
|
323
|
+
if is_jruby?
|
|
324
|
+
expected = [
|
|
325
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
326
|
+
":db/ident" => ":account/name",
|
|
327
|
+
":db/valueType" => ":db.type/string",
|
|
328
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
329
|
+
":db.install/_attribute" => ":db.part/db" },
|
|
330
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
331
|
+
":db/ident" => ":account/deposit",
|
|
332
|
+
":db/valueType" => ":db.type/double",
|
|
333
|
+
":db/cardinality" => ":db.cardinality/many",
|
|
334
|
+
":db.install/_attribute" => ":db.part/db" },
|
|
335
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
336
|
+
":db/ident" => ":account/amount",
|
|
337
|
+
":db/valueType" => ":db.type/double",
|
|
338
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
339
|
+
":db.install/_attribute" => ":db.part/db" }
|
|
340
|
+
]
|
|
341
|
+
else
|
|
342
|
+
expected = [
|
|
343
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
344
|
+
:"db/ident" => :"account/name",
|
|
345
|
+
:"db/valueType" => :"db.type/string",
|
|
346
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
347
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
348
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
349
|
+
:"db/ident" => :"account/deposit",
|
|
350
|
+
:"db/valueType" => :"db.type/double",
|
|
351
|
+
:"db/cardinality" => :"db.cardinality/many",
|
|
352
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
353
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
354
|
+
:"db/ident" => :"account/amount",
|
|
355
|
+
:"db/valueType" => :"db.type/double",
|
|
356
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
357
|
+
:"db.install/_attribute" => :"db.part/db" }
|
|
358
|
+
]
|
|
359
|
+
end
|
|
360
|
+
@created_schema = subject.schema
|
|
361
|
+
expected.each do |e|
|
|
362
|
+
@created_schema.shift.should be_an_equivalent_hash(e)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
context "community sample" do
|
|
368
|
+
subject { Organization }
|
|
369
|
+
|
|
370
|
+
it { should respond_to(:attribute) }
|
|
371
|
+
it { should respond_to(:enum) }
|
|
372
|
+
it { should respond_to(:schema) }
|
|
373
|
+
|
|
374
|
+
it "should generate a schema" do
|
|
375
|
+
expected = [
|
|
376
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
377
|
+
:"db/ident" => :"organization/name",
|
|
378
|
+
:"db/valueType" => :"db.type/string",
|
|
379
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
380
|
+
:"db/fulltext" => true,
|
|
381
|
+
:"db/doc" => "A organization's name",
|
|
382
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
383
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
384
|
+
:"db/ident" => :"organization/url",
|
|
385
|
+
:"db/valueType" => :"db.type/string",
|
|
386
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
387
|
+
:"db/doc" => "A organization's url",
|
|
388
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
389
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
390
|
+
:"db/ident" => :"organization/neighborhood",
|
|
391
|
+
:"db/valueType" => :"db.type/ref",
|
|
392
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
393
|
+
:"db/doc" => "A organization's neighborhood",
|
|
394
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
395
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
396
|
+
:"db/ident" => :"organization/category",
|
|
397
|
+
:"db/valueType" => :"db.type/string",
|
|
398
|
+
:"db/cardinality" => :"db.cardinality/many",
|
|
399
|
+
:"db/fulltext" => true,
|
|
400
|
+
:"db/doc" => "All organization categories",
|
|
401
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
402
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
403
|
+
:"db/ident" => :"organization/orgtype",
|
|
404
|
+
:"db/valueType" => :"db.type/ref",
|
|
405
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
406
|
+
:"db/doc" => "A organization orgtype enum value",
|
|
407
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
408
|
+
{ :"db/id" => subject.send(:tempid, :"db.part/db"),
|
|
409
|
+
:"db/ident" => :"organization/type",
|
|
410
|
+
:"db/valueType" => :"db.type/ref",
|
|
411
|
+
:"db/cardinality" => :"db.cardinality/one",
|
|
412
|
+
:"db/doc" => "A organization type enum value",
|
|
413
|
+
:"db.install/_attribute" => :"db.part/db" },
|
|
414
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.orgtype/community" ],
|
|
415
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.orgtype/commercial" ],
|
|
416
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.orgtype/nonprofit"],
|
|
417
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.orgtype/personal"],
|
|
418
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/email-list"],
|
|
419
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/twitter"],
|
|
420
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/facebook-page" ],
|
|
421
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/blog" ],
|
|
422
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/website" ],
|
|
423
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/wiki" ],
|
|
424
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/myspace" ],
|
|
425
|
+
[ :"db/add", subject.send(:tempid, :"db.part/user"), :"db/ident", :"organization.type/ning"]
|
|
426
|
+
]
|
|
427
|
+
|
|
428
|
+
@created_schema = Organization.schema
|
|
429
|
+
expected.each do |e|
|
|
430
|
+
@created_schema.shift.should == e
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
context "seattle sample", :jruby do
|
|
437
|
+
describe Diametric::Entity do
|
|
438
|
+
subject { District }
|
|
439
|
+
|
|
440
|
+
it "should create peer schema" do
|
|
441
|
+
expected = [
|
|
442
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
443
|
+
":db/ident" => ":district/name",
|
|
444
|
+
":db/valueType" => ":db.type/string",
|
|
445
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
446
|
+
":db/unique" => ":db.unique/identity",
|
|
447
|
+
":db/doc" => "A unique district name (upsertable)",
|
|
448
|
+
":db.install/_attribute" => ":db.part/db" },
|
|
449
|
+
{ ":db/id" => subject.send(:tempid, ":db.part/db"),
|
|
450
|
+
":db/ident" => ":district/region",
|
|
451
|
+
":db/valueType" => ":db.type/ref",
|
|
452
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
453
|
+
":db/doc" => "A district region enum value",
|
|
454
|
+
":db.install/_attribute" => ":db.part/db" },
|
|
455
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/n"],
|
|
456
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/ne"],
|
|
457
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/e"],
|
|
458
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/se"],
|
|
459
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/s"],
|
|
460
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/sw"],
|
|
461
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/w"],
|
|
462
|
+
[ ":db/add", "#db/id[:db.part/user]", ":db/ident", ":district.region/nw"]
|
|
463
|
+
]
|
|
464
|
+
@created_schema = District.schema
|
|
465
|
+
expected.each do |e|
|
|
466
|
+
if e.is_a? Hash
|
|
467
|
+
@created_schema.shift.should be_an_equivalent_hash(e)
|
|
468
|
+
else
|
|
469
|
+
@created_schema.shift.should be_an_equivalent_array(e)
|
|
470
|
+
end
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
|
|
213
476
|
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'securerandom'
|
|
3
|
+
|
|
4
|
+
if is_jruby?
|
|
5
|
+
describe Diametric::Persistence::Peer, :jruby => true do
|
|
6
|
+
@db_name = "test-#{SecureRandom.uuid}"
|
|
7
|
+
|
|
8
|
+
it 'should create database' do
|
|
9
|
+
subject.create_database("datomic:mem://#{@db_name}").should be_true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context Diametric::Persistence::Peer do
|
|
13
|
+
it 'should connect to the database' do
|
|
14
|
+
subject.connect("datomic:mem://#{@db_name}").should be_true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should get tempid' do
|
|
18
|
+
subject.tempid(":db.part/db").to_s.should match(/#db\/id\[:db.part\/db\s-\d+\]/)
|
|
19
|
+
subject.tempid(":db.part/user").to_s.should match(/#db\/id\[:db.part\/user\s-\d+\]/)
|
|
20
|
+
subject.tempid(":db.part/user", -1).to_s.should match(/#db\/id\[:db.part\/user\s-1\]/)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should return uuid from squuid" do
|
|
24
|
+
re = Regexp.new(/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/)
|
|
25
|
+
subject.squuid.to_s.should match(re)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should return Fixnum from squuid_time_millis" do
|
|
29
|
+
du = Diametric::Persistence::UUID.new
|
|
30
|
+
subject.squuid_time_millis(du).class.should == Fixnum
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context Diametric::Persistence::Connection do
|
|
35
|
+
@db_name = "test-#{SecureRandom.uuid}"
|
|
36
|
+
let(:connection) { Diametric::Persistence::Peer.connect("datomic:mem://#{@db_name}") }
|
|
37
|
+
let(:tempid) { Diametric::Persistence::Peer.tempid(":db.part/db") }
|
|
38
|
+
let(:tx_data) {
|
|
39
|
+
[{
|
|
40
|
+
":db/id" => tempid,
|
|
41
|
+
":db/ident" => ":person/name",
|
|
42
|
+
":db/valueType" => ":db.type/string",
|
|
43
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
44
|
+
":db/doc" => "A person's name",
|
|
45
|
+
":db.install/_attribute" => ":db.part/db"
|
|
46
|
+
}]
|
|
47
|
+
}
|
|
48
|
+
let(:user_data) {
|
|
49
|
+
[{":db/id" => user_part_tempid, ":person/name" => "Alice"},
|
|
50
|
+
{":db/id" => user_part_tempid, ":person/name" => "Bob"},
|
|
51
|
+
{":db/id" => user_part_tempid, ":person/name" => "Chris"}]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it 'should transact schema' do
|
|
55
|
+
connection.transact(tx_data).class.should == Diametric::Persistence::ListenableFuture
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'should get future object for schema' do
|
|
59
|
+
connection.transact(tx_data).get.should be_true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'should transact data' do
|
|
63
|
+
connection.transact(tx_data).get
|
|
64
|
+
connection.transact(user_data).get.should be_true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'should resolve tempid' do
|
|
68
|
+
tmp_tempid = user_part_tempid
|
|
69
|
+
connection.transact(tx_data).get
|
|
70
|
+
map = connection.transact([{":db/id" => tmp_tempid, ":person/name" => "Alice"}]).get
|
|
71
|
+
resolved_tempid = Diametric::Persistence::Peer.resolve_tempid(map, tmp_tempid)
|
|
72
|
+
resolved_tempid.should be_true
|
|
73
|
+
resolved_tempid.to_s.should match(/\d+/)
|
|
74
|
+
#puts "resolved_tempid: #{resolved_tempid}"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context 'Diametric query' do
|
|
79
|
+
before do
|
|
80
|
+
tx_data =
|
|
81
|
+
[{
|
|
82
|
+
":db/id" => Diametric::Persistence::Peer.tempid(":db.part/db"),
|
|
83
|
+
":db/ident" => ":person/name",
|
|
84
|
+
":db/valueType" => ":db.type/string",
|
|
85
|
+
":db/cardinality" => ":db.cardinality/one",
|
|
86
|
+
":db/doc" => "A person's name",
|
|
87
|
+
":db.install/_attribute" => ":db.part/db"
|
|
88
|
+
}]
|
|
89
|
+
user_data =
|
|
90
|
+
[{":db/id" => Diametric::Persistence::Peer.tempid(":db.part/user"), ":person/name" => "Alice"},
|
|
91
|
+
{":db/id" => Diametric::Persistence::Peer.tempid(":db.part/user"), ":person/name" => "Bob"},
|
|
92
|
+
{":db/id" => Diametric::Persistence::Peer.tempid(":db.part/user"), ":person/name" => "Chris"}]
|
|
93
|
+
@db_name = "test-#{SecureRandom.uuid}"
|
|
94
|
+
@connection = Diametric::Persistence::Peer.connect("datomic:mem://#{@db_name}")
|
|
95
|
+
|
|
96
|
+
@connection.transact(tx_data).get
|
|
97
|
+
@connection.transact(user_data).get
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'should get ids from datomic' do
|
|
101
|
+
results = Diametric::Persistence::Peer.q("[:find ?c :where [?c :person/name]]", @connection.db)
|
|
102
|
+
results.class.should == Array
|
|
103
|
+
results.size.should be >= 3
|
|
104
|
+
#puts results.inspect
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'should get names from datomic' do
|
|
108
|
+
results = Diametric::Persistence::Peer.q("[:find ?c ?name :where [?c :person/name ?name]]\
|
|
109
|
+
", @connection.db)
|
|
110
|
+
results.flatten.should include("Alice")
|
|
111
|
+
results.flatten.should include("Bob")
|
|
112
|
+
results.flatten.should include("Chris")
|
|
113
|
+
#puts results.inspect
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'should get entity by id' do
|
|
117
|
+
results = Diametric::Persistence::Peer.q("[:find ?c :where [?c :person/name]]",\
|
|
118
|
+
@connection.db)
|
|
119
|
+
id = results[0][0]
|
|
120
|
+
@connection.db.entity(id).should be_true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'should get keys from entity id' do
|
|
124
|
+
results = Diametric::Persistence::Peer.q("[:find ?c :where [?c :person/name]]",\
|
|
125
|
+
@connection.db)
|
|
126
|
+
id = results[0][0]
|
|
127
|
+
entity = @connection.db.entity(id)
|
|
128
|
+
entity.keys.should include(":person/name")
|
|
129
|
+
#puts entity.keys
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'should get value from entity id' do
|
|
133
|
+
results = Diametric::Persistence::Peer.q("[:find ?c :where [?c :person/name]]",\
|
|
134
|
+
@connection.db)
|
|
135
|
+
id = results[0][0]
|
|
136
|
+
entity = @connection.db.entity(id)
|
|
137
|
+
value = entity.get(entity.keys[0])
|
|
138
|
+
value.should match(/Alice|Bob|Chris/)
|
|
139
|
+
#puts value
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def user_part_tempid
|
|
146
|
+
Diametric::Persistence::Peer.tempid(":db.part/user")
|
|
147
|
+
end
|