norikra 0.0.1-java
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.
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE +339 -0
- data/README.md +104 -0
- data/Rakefile +10 -0
- data/bin/norikra +8 -0
- data/esper/changelog.txt +1066 -0
- data/esper/esper-4.9.0.jar +0 -0
- data/esper/esper-license.txt +95 -0
- data/esper/esper/lib/antlr-runtime-3.2.jar +0 -0
- data/esper/esper/lib/cglib-nodep-2.2.jar +0 -0
- data/esper/esper/lib/commons-logging-1.1.1.jar +0 -0
- data/esper/esper/lib/esper_3rdparties.license +299 -0
- data/esper/esper/lib/log4j-1.2.16.jar +0 -0
- data/esper/esper/lib/readme.txt +38 -0
- data/esper/esperio-amqp-4.9.0.jar +0 -0
- data/esper/esperio-amqp/lib/commons-cli-1.1.jar +0 -0
- data/esper/esperio-amqp/lib/commons-io-1.2.jar +0 -0
- data/esper/esperio-amqp/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-amqp/lib/esperio_amqp_jars.txt +2 -0
- data/esper/esperio-amqp/lib/rabbitmq-client.jar +0 -0
- data/esper/esperio-csv-4.9.0.jar +0 -0
- data/esper/esperio-csv/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-db-4.9.0.jar +0 -0
- data/esper/esperio-db/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-http-4.9.0.jar +0 -0
- data/esper/esperio-http/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-http/lib/httpclient-4.0.1.jar +0 -0
- data/esper/esperio-http/lib/httpcore-4.0.1.jar +0 -0
- data/esper/esperio-http/lib/httpcore-nio-4.0.1.jar +0 -0
- data/esper/esperio-license.txt +95 -0
- data/esper/esperio-socket-4.9.0.jar +0 -0
- data/esper/esperio-socket/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-springjms-4.9.0.jar +0 -0
- data/esper/esperio-springjms/lib/activation-1.1.jar +0 -0
- data/esper/esperio-springjms/lib/activemq-core-5.7.0.jar +0 -0
- data/esper/esperio-springjms/lib/activemq-pool-5.7.0.jar +0 -0
- data/esper/esperio-springjms/lib/commons-pool-1.6.jar +0 -0
- data/esper/esperio-springjms/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-springjms/lib/geronimo-j2ee-management_1.1_spec-1.0.1.jar +0 -0
- data/esper/esperio-springjms/lib/geronimo-jms_1.1_spec-1.1.1.jar +0 -0
- data/esper/esperio-springjms/lib/junit-4.8.2.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.asm-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.beans-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.context-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.core-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.expression-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.jms-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/org.springframework.transaction-3.1.1.RELEASE.jar +0 -0
- data/esper/esperio-springjms/lib/slf4j-api-1.7.2.jar +0 -0
- data/esper/esperio-springjms/lib/slf4j-log4j12-1.7.2.jar +0 -0
- data/esper/esperio-stax-4.9.0.jar +0 -0
- data/esper/esperio-stax/lib/axiom-api-1.2.9.jar +0 -0
- data/esper/esperio-stax/lib/axiom-c14n-1.2.9.jar +0 -0
- data/esper/esperio-stax/lib/axiom-dom-1.2.9.jar +0 -0
- data/esper/esperio-stax/lib/axiom-impl-1.2.9.jar +0 -0
- data/esper/esperio-stax/lib/commons-logging-1.1.1.jar +0 -0
- data/esper/esperio-stax/lib/commons-logging-LICENSE.txt +203 -0
- data/esper/esperio-stax/lib/esperio_3rdparties.license +1328 -0
- data/esper/esperio-stax/lib/geronimo-activation-LICENSE.txt +203 -0
- data/esper/esperio-stax/lib/geronimo-activation_1.1_spec-1.0.2.jar +0 -0
- data/esper/esperio-stax/lib/geronimo-javamail-LICENSE.txt +203 -0
- data/esper/esperio-stax/lib/geronimo-javamail_1.4_spec-1.6.jar +0 -0
- data/esper/esperio-stax/lib/geronimo-stax-api-LICENSE.txt +203 -0
- data/esper/esperio-stax/lib/geronimo-stax-api_1.0_spec-1.0.1.jar +0 -0
- data/esper/esperio-stax/lib/jaxen-1.1.1.jar +0 -0
- data/esper/esperio-stax/lib/jaxen-LICENSE.txt +33 -0
- data/esper/esperio-stax/lib/wstx-LICENSE.txt +203 -0
- data/esper/esperio-stax/lib/wstx-asl-3.2.9.jar +0 -0
- data/junks/esper-test.rb +79 -0
- data/junks/glassfish.rb +17 -0
- data/junks/mizuno.rb +28 -0
- data/junks/simple_test.rb +35 -0
- data/junks/type_confliction.rb +46 -0
- data/junks/type_conversion.rb +49 -0
- data/junks/type_inherit.rb +67 -0
- data/lib/norikra.rb +13 -0
- data/lib/norikra/cli.rb +24 -0
- data/lib/norikra/engine.rb +231 -0
- data/lib/norikra/output_pool.rb +45 -0
- data/lib/norikra/query.rb +173 -0
- data/lib/norikra/rpc.rb +6 -0
- data/lib/norikra/rpc/handler.rb +57 -0
- data/lib/norikra/rpc/http.rb +36 -0
- data/lib/norikra/server.rb +41 -0
- data/lib/norikra/typedef.rb +307 -0
- data/lib/norikra/typedef_manager.rb +91 -0
- data/lib/norikra/version.rb +3 -0
- data/norikra.gemspec +33 -0
- data/script/spec_server_pry +45 -0
- data/spec/field_spec.rb +141 -0
- data/spec/fieldset_spec.rb +172 -0
- data/spec/output_pool_spec.rb +75 -0
- data/spec/query_spec.rb +82 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/typedef_manager_spec.rb +128 -0
- data/spec/typedef_spec.rb +248 -0
- metadata +328 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require_relative './spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'norikra/output_pool'
|
|
4
|
+
|
|
5
|
+
describe Norikra::OutputPool do
|
|
6
|
+
context 'without any events in pool' do
|
|
7
|
+
describe '#pop' do
|
|
8
|
+
it 'returns blank array' do
|
|
9
|
+
expect(subject.pop('TestTable query1')).to eql([])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#push' do
|
|
14
|
+
context 'with empty array' do
|
|
15
|
+
subject { p = Norikra::OutputPool.new; p.push('TestTable query1', []); p }
|
|
16
|
+
its(:pool){ should == {'TestTable query1' => []} }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'with event array' do
|
|
20
|
+
it 'has pool with event' do
|
|
21
|
+
pool = Norikra::OutputPool.new
|
|
22
|
+
t = Time.now.to_i
|
|
23
|
+
pool.push('TestTable query1', [{'count'=>1},{'count'=>2}])
|
|
24
|
+
|
|
25
|
+
pool.pool.keys.should eql(['TestTable query1'])
|
|
26
|
+
events = pool.pool['TestTable query1']
|
|
27
|
+
|
|
28
|
+
expect(events.size).to eq(1) # pool event bucket size is equal to times of #push
|
|
29
|
+
expect(events.first.size).to eq(2) # bucket size if equal to event num of #push
|
|
30
|
+
|
|
31
|
+
bucket = events.first
|
|
32
|
+
|
|
33
|
+
expect(t..(t+1)).to cover(bucket[0].first) # time
|
|
34
|
+
expect(bucket[0].last).to eql({'count'=>1})
|
|
35
|
+
|
|
36
|
+
expect(t..(t+1)).to cover(bucket[1].first) # time
|
|
37
|
+
expect(bucket[1].first).to eql(bucket[0].first)
|
|
38
|
+
expect(bucket[1].last).to eql({'count'=>2})
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with events in pool' do
|
|
45
|
+
describe '#pop' do
|
|
46
|
+
it 'returns all events of specified query in pool' do
|
|
47
|
+
pool = Norikra::OutputPool.new
|
|
48
|
+
t = Time.now.to_i
|
|
49
|
+
pool.push('TestTable query1', [{'count'=>1},{'count'=>2}])
|
|
50
|
+
pool.push('TestTable query2', [{'count'=>3},{'count'=>4}])
|
|
51
|
+
|
|
52
|
+
expect(pool.pop('TestTable query0').size).to eql(0)
|
|
53
|
+
expect(pool.pop('TestTable query1').size).to eql(2)
|
|
54
|
+
expect(pool.pool.size).to eql(1)
|
|
55
|
+
expect(pool.pop('TestTable query1').size).to eql(0)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#sweep' do
|
|
60
|
+
it 'returns all events for all queries in pool' do
|
|
61
|
+
pool = Norikra::OutputPool.new
|
|
62
|
+
t = Time.now.to_i
|
|
63
|
+
pool.push('TestTable query1', [{'count'=>1},{'count'=>2}])
|
|
64
|
+
pool.push('TestTable query2', [{'count'=>3},{'count'=>4},{'count'=>5}])
|
|
65
|
+
|
|
66
|
+
chunk = pool.sweep
|
|
67
|
+
expect(chunk.keys.size).to eql(2)
|
|
68
|
+
|
|
69
|
+
expect(chunk['TestTable query1'].size).to eql(2)
|
|
70
|
+
expect(chunk['TestTable query2'].size).to eql(3)
|
|
71
|
+
expect(chunk['TestTable query2'].last.last['count']).to eql(5)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/spec/query_spec.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require_relative './spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'norikra/query'
|
|
4
|
+
|
|
5
|
+
describe Norikra::Query do
|
|
6
|
+
context 'when instanciate' do
|
|
7
|
+
describe '#initialize' do
|
|
8
|
+
context 'with simple query' do
|
|
9
|
+
expression = 'SELECT count(*) AS cnt FROM TestTable.win:time_batch(10 sec) WHERE path="/" AND size > 100 and param.length() > 0'
|
|
10
|
+
subject { Norikra::Query.new(
|
|
11
|
+
:name => 'TestTable query1', :expression => expression
|
|
12
|
+
) }
|
|
13
|
+
its(:name){ should == 'TestTable query1' }
|
|
14
|
+
its(:expression){ should == expression }
|
|
15
|
+
its(:target){ should == 'TestTable' }
|
|
16
|
+
its(:fields){ should == ['param', 'path', 'size'] }
|
|
17
|
+
end
|
|
18
|
+
context 'with query including Static lib call'
|
|
19
|
+
expression = 'SELECT count(*) AS cnt FROM TestTable.win:time_batch(10 sec) WHERE path="/" AND Math.abs(-1 * size) > 3'
|
|
20
|
+
subject { Norikra::Query.new(
|
|
21
|
+
:name => 'TestTable query1', :expression => expression
|
|
22
|
+
) }
|
|
23
|
+
its(:name){ should == 'TestTable query1' }
|
|
24
|
+
its(:expression){ should == expression }
|
|
25
|
+
its(:target){ should == 'TestTable' }
|
|
26
|
+
its(:fields){ should == ['path', 'size'] }
|
|
27
|
+
end
|
|
28
|
+
describe '#dup_with_stream_name' do
|
|
29
|
+
context 'with simple query' do
|
|
30
|
+
expression = 'SELECT count(*) AS cnt FROM TestTable.win:time_batch(10 sec) WHERE path="/" AND size > 100 and param.length() > 0'
|
|
31
|
+
it 'returns duplicated object, with replaced ' do
|
|
32
|
+
query = Norikra::Query.new(
|
|
33
|
+
:name => 'TestTable query1', :expression => expression
|
|
34
|
+
)
|
|
35
|
+
expect(query.dup_with_stream_name('hoge').expression).to eql(
|
|
36
|
+
'SELECT count(*) AS cnt FROM hoge.win:time_batch(10 sec) WHERE path="/" AND size > 100 and param.length() > 0'
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
context 'with query with newlines' do
|
|
41
|
+
expression = <<EOQ
|
|
42
|
+
SELECT
|
|
43
|
+
count(*) AS cnt
|
|
44
|
+
FROM TestTable.win:time_batch(10 sec)
|
|
45
|
+
WHERE path="/" AND size > 100
|
|
46
|
+
AND param.length() > 0
|
|
47
|
+
EOQ
|
|
48
|
+
expected_query = <<EOQ
|
|
49
|
+
SELECT
|
|
50
|
+
count(*) AS cnt
|
|
51
|
+
FROM hoge.win:time_batch(10 sec)
|
|
52
|
+
WHERE path="/" AND size > 100
|
|
53
|
+
AND param.length() > 0
|
|
54
|
+
EOQ
|
|
55
|
+
it 'returns duplicated object, with replaced ' do
|
|
56
|
+
query = Norikra::Query.new(
|
|
57
|
+
:name => 'TestTable query1', :expression => expression
|
|
58
|
+
)
|
|
59
|
+
expect(query.dup_with_stream_name('hoge').expression).to eql(expected_query)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
describe '.imported_java_class?' do
|
|
65
|
+
it 'can do judge passed name exists under java package tree or not' do
|
|
66
|
+
expect(Norikra::Query.imported_java_class?('String')).to be_true
|
|
67
|
+
expect(Norikra::Query.imported_java_class?('Long')).to be_true
|
|
68
|
+
expect(Norikra::Query.imported_java_class?('Void')).to be_true
|
|
69
|
+
expect(Norikra::Query.imported_java_class?('BigDecimal')).to be_true
|
|
70
|
+
expect(Norikra::Query.imported_java_class?('Format')).to be_true
|
|
71
|
+
expect(Norikra::Query.imported_java_class?('Normalizer')).to be_true
|
|
72
|
+
expect(Norikra::Query.imported_java_class?('Date')).to be_true
|
|
73
|
+
expect(Norikra::Query.imported_java_class?('HashSet')).to be_true
|
|
74
|
+
expect(Norikra::Query.imported_java_class?('Random')).to be_true
|
|
75
|
+
expect(Norikra::Query.imported_java_class?('Timer')).to be_true
|
|
76
|
+
|
|
77
|
+
expect(Norikra::Query.imported_java_class?('unexpected')).to be_false
|
|
78
|
+
expect(Norikra::Query.imported_java_class?('parameter')).to be_false
|
|
79
|
+
expect(Norikra::Query.imported_java_class?('param')).to be_false
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'spork'
|
|
3
|
+
#uncomment the following line to use spork with the debugger
|
|
4
|
+
#require 'spork/ext/ruby-debug'
|
|
5
|
+
|
|
6
|
+
Spork.prefork do
|
|
7
|
+
# Loading more in this block will cause your tests to run faster. However,
|
|
8
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
|
9
|
+
# need to restart spork for it take effect.
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Spork.each_run do
|
|
14
|
+
# This code will be run each time you run your specs.
|
|
15
|
+
Dir.glob('./lib/norikra/**/*.rb').each do |file|
|
|
16
|
+
load file
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# --- Instructions ---
|
|
21
|
+
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
|
|
22
|
+
# block.
|
|
23
|
+
#
|
|
24
|
+
# The Spork.prefork block is run only once when the spork server is started.
|
|
25
|
+
# You typically want to place most of your (slow) initializer code in here, in
|
|
26
|
+
# particular, require'ing any 3rd-party gems that you don't normally modify
|
|
27
|
+
# during development.
|
|
28
|
+
#
|
|
29
|
+
# The Spork.each_run block is run each time you run your specs. In case you
|
|
30
|
+
# need to load files that tend to change during development, require them here.
|
|
31
|
+
# With Rails, your application modules are loaded automatically, so sometimes
|
|
32
|
+
# this block can remain empty.
|
|
33
|
+
#
|
|
34
|
+
# Note: You can modify files loaded *from* the Spork.each_run block without
|
|
35
|
+
# restarting the spork server. However, this file itself will not be reloaded,
|
|
36
|
+
# so if you change any of the code inside the each_run block, you still need to
|
|
37
|
+
# restart the server. In general, if you have non-trivial code in this file,
|
|
38
|
+
# it's advisable to move it into a separate file so you can easily edit it
|
|
39
|
+
# without restarting spork. (For example, with RSpec, you could move
|
|
40
|
+
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
|
|
41
|
+
# spec/support/* files are require'd from inside the each_run block.)
|
|
42
|
+
#
|
|
43
|
+
# Any code that is left outside the two blocks will be run during preforking
|
|
44
|
+
# *and* during each_run -- that's probably not what you want.
|
|
45
|
+
#
|
|
46
|
+
# These instructions should self-destruct in 10 seconds. If they don't, feel
|
|
47
|
+
# free to delete them.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
require 'rubygems'
|
|
53
|
+
require 'rspec'
|
|
54
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
|
55
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../esper')
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require_relative './spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'norikra/typedef_manager'
|
|
4
|
+
|
|
5
|
+
require 'norikra/typedef'
|
|
6
|
+
|
|
7
|
+
describe Norikra::TypedefManager do
|
|
8
|
+
context 'when instanciated with a target without fields definition' do
|
|
9
|
+
manager = Norikra::TypedefManager.new
|
|
10
|
+
manager.add_target('sample', nil)
|
|
11
|
+
|
|
12
|
+
describe '#lazy?' do
|
|
13
|
+
it 'returns true' do
|
|
14
|
+
expect(manager.lazy?('sample')).to be_true
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#generate_base_fieldset' do
|
|
19
|
+
it 'returns fieldsets specified as all fields required' do
|
|
20
|
+
r = manager.generate_base_fieldset('sample', {'a'=>'foo','b'=>'bar','x'=>'yeeeees!'})
|
|
21
|
+
expect(r).to be_instance_of(Norikra::FieldSet)
|
|
22
|
+
|
|
23
|
+
expect(r.fields['a'].type).to eql('string')
|
|
24
|
+
expect(r.fields['a'].optional?).to be_false
|
|
25
|
+
expect(r.fields['b'].type).to eql('string')
|
|
26
|
+
expect(r.fields['b'].optional?).to be_false
|
|
27
|
+
expect(r.fields['x'].type).to eql('string')
|
|
28
|
+
expect(r.fields['x'].optional?).to be_false
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#activate' do
|
|
33
|
+
it 'does not fail, and target will become non-lazy status' do
|
|
34
|
+
r = manager.generate_base_fieldset('sample', {'a'=>'foo','b'=>'bar','x'=>'yeeeees!'})
|
|
35
|
+
manager.activate('sample', r)
|
|
36
|
+
expect(manager.lazy?('sample')).to be_false
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'when instanciated with a target with fields definition' do
|
|
42
|
+
manager = Norikra::TypedefManager.new
|
|
43
|
+
manager.add_target('sample', {'a'=>'string','b'=>'string','c'=>'double'})
|
|
44
|
+
|
|
45
|
+
set_query_base = Norikra::FieldSet.new({'a'=>'string','b'=>'string','c'=>'double'})
|
|
46
|
+
|
|
47
|
+
it 'three fields are defined as non-optional fields' do
|
|
48
|
+
expect(manager.typedefs['sample'].fields['a'].type).to eql('string')
|
|
49
|
+
expect(manager.typedefs['sample'].fields['a'].optional?).to be_false
|
|
50
|
+
expect(manager.typedefs['sample'].fields['b'].type).to eql('string')
|
|
51
|
+
expect(manager.typedefs['sample'].fields['b'].optional?).to be_false
|
|
52
|
+
expect(manager.typedefs['sample'].fields['c'].type).to eql('double')
|
|
53
|
+
expect(manager.typedefs['sample'].fields['c'].optional?).to be_false
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#lazy?' do
|
|
57
|
+
it 'returns false' do
|
|
58
|
+
expect(manager.lazy?('sample')).to be_false
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
describe '#reserve' do
|
|
62
|
+
it 'does not fail' do
|
|
63
|
+
manager.reserve('sample', 'x', 'long')
|
|
64
|
+
expect(manager.typedefs['sample'].fields['x'].type).to eql('long')
|
|
65
|
+
expect(manager.typedefs['sample'].fields['x'].optional?).to be_true
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
describe '#fields_defined?' do
|
|
69
|
+
it 'does not fail' do
|
|
70
|
+
expect(manager.fields_defined?('sample', ['a','b','x'])).to be_true
|
|
71
|
+
expect(manager.fields_defined?('sample', ['a','b','z'])).to be_false
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
describe '#bind_fieldset' do
|
|
75
|
+
it 'does not fail' do
|
|
76
|
+
manager.bind_fieldset('sample', :query, set_query_base)
|
|
77
|
+
expect(set_query_base.target).to eql('sample')
|
|
78
|
+
expect(set_query_base.level).to eql(:query)
|
|
79
|
+
expect(manager.typedefs['sample'].queryfieldsets.include?(set_query_base)).to be_true
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe '#base_fieldset' do
|
|
84
|
+
it 'returns baseset of specified target' do
|
|
85
|
+
expect(manager.base_fieldset('sample').object_id).to eql(manager.typedefs['sample'].baseset.object_id)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#refer' do
|
|
90
|
+
it 'does not fail' do
|
|
91
|
+
expect(manager.refer('sample', {'a'=>'foo','b'=>'bar','c'=>'0.03'})).to be_instance_of(Norikra::FieldSet)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe '#format' do
|
|
96
|
+
it 'does not fail' do
|
|
97
|
+
expect(manager.format('sample', {'a'=>'foo','b'=>'bar','c'=>'0.03'})).to be_instance_of(Hash)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#subsets' do
|
|
102
|
+
it 'returns list of query fieldset (and base set), subset of specified fieldset, owned by manager for specified target' do
|
|
103
|
+
base = {'a'=>'string','b'=>'string','c'=>'double'}
|
|
104
|
+
set_d = Norikra::FieldSet.new(base.merge({'d'=>'int'}))
|
|
105
|
+
manager.bind_fieldset('sample', :query, set_d)
|
|
106
|
+
set_e = Norikra::FieldSet.new(base.merge({'e'=>'double'}))
|
|
107
|
+
manager.bind_fieldset('sample', :query, set_e)
|
|
108
|
+
set_f = Norikra::FieldSet.new(base.merge({'f'=>'boolean'}))
|
|
109
|
+
manager.bind_fieldset('sample', :query, set_f)
|
|
110
|
+
|
|
111
|
+
list = manager.subsets('sample', Norikra::FieldSet.new(base.merge({'d'=>'string','e'=>'string','g'=>'string'})))
|
|
112
|
+
expect(list.size).to eql(4) # set_query_base, set_d, set_e, baseset
|
|
113
|
+
expect(list.include?(set_query_base)).to be_true
|
|
114
|
+
expect(list.include?(set_d)).to be_true
|
|
115
|
+
expect(list.include?(set_e)).to be_true
|
|
116
|
+
expect(list.include?(set_f)).to be_false
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe '#generate_query_fieldset' do
|
|
121
|
+
it 'returns fieldset instance with all required(non-optional) fields of target, and fields of query requires' do
|
|
122
|
+
r = manager.generate_query_fieldset('sample', ['a', 'b','f'])
|
|
123
|
+
expect(r.fields.size).to eql(4) # a,b,c,f
|
|
124
|
+
expect(r.summary).to eql('a:string,b:string,c:double,f:boolean')
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
require_relative './spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'norikra/typedef'
|
|
4
|
+
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'digest'
|
|
7
|
+
|
|
8
|
+
describe Norikra::Typedef do
|
|
9
|
+
context 'instanciated as lazy typedef' do
|
|
10
|
+
it 'has no fields' do
|
|
11
|
+
t = Norikra::Typedef.new
|
|
12
|
+
expect(t.fields.size).to eql(0)
|
|
13
|
+
expect(t.baseset).to be_nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'has no query/data fieldsets' do
|
|
17
|
+
t = Norikra::Typedef.new
|
|
18
|
+
expect(t.queryfieldsets.size).to eql(0)
|
|
19
|
+
expect(t.datafieldsets.size).to eql(0)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#lazy?' do
|
|
23
|
+
it 'returns true' do
|
|
24
|
+
t = Norikra::Typedef.new
|
|
25
|
+
expect(t.lazy?).to be_true
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#reserve' do
|
|
30
|
+
it 'add field definition without any baseset' do
|
|
31
|
+
t = Norikra::Typedef.new
|
|
32
|
+
|
|
33
|
+
t.reserve('k', 'string')
|
|
34
|
+
expect(t.fields['k'].type).to eql('string')
|
|
35
|
+
expect(t.fields['k'].optional?).to be_true
|
|
36
|
+
|
|
37
|
+
t.reserve('l', 'long', false)
|
|
38
|
+
expect(t.fields['l'].type).to eql('long')
|
|
39
|
+
expect(t.fields['l'].optional?).to be_false
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe '#activate' do
|
|
44
|
+
context 'without any fields reserved' do
|
|
45
|
+
it 'stores all fields in specified fieldset' do
|
|
46
|
+
t = Norikra::Typedef.new
|
|
47
|
+
set = Norikra::FieldSet.new({'a'=>'string','b'=>'long','c'=>'double'})
|
|
48
|
+
t.activate(set)
|
|
49
|
+
expect(t.fields.size).to eql(3)
|
|
50
|
+
expect(t.fields['a'].optional?).to be_false
|
|
51
|
+
expect(t.fields.object_id).not_to eql(set.fields.object_id)
|
|
52
|
+
expect(t.baseset.object_id).not_to eql(set.object_id)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'instanciated as non-lazy typedef' do
|
|
59
|
+
it 'has no query/data fieldsets' do
|
|
60
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
61
|
+
expect(t.queryfieldsets.size).to eql(0)
|
|
62
|
+
expect(t.datafieldsets.size).to eql(0)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'has all fields as required' do
|
|
66
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
67
|
+
|
|
68
|
+
expect(t.fields['a'].type).to eql('string')
|
|
69
|
+
expect(t.fields['a'].optional?).to be_false
|
|
70
|
+
|
|
71
|
+
expect(t.fields['b'].type).to eql('long')
|
|
72
|
+
expect(t.fields['b'].optional?).to be_false
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe '#lazy?' do
|
|
76
|
+
it 'returns false' do
|
|
77
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
78
|
+
expect(t.lazy?).to be_false
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe '#field_defined?' do
|
|
83
|
+
it 'returns boolean to indicate all fields specified exists or not' do
|
|
84
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
85
|
+
expect(t.field_defined?(['a','b'])).to be_true
|
|
86
|
+
expect(t.field_defined?(['a'])).to be_true
|
|
87
|
+
expect(t.field_defined?(['b'])).to be_true
|
|
88
|
+
expect(t.field_defined?([])).to be_true
|
|
89
|
+
expect(t.field_defined?(['a','b','c'])).to be_false
|
|
90
|
+
expect(t.field_defined?(['a','c'])).to be_false
|
|
91
|
+
expect(t.field_defined?(['c'])).to be_false
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe '#reserve' do
|
|
96
|
+
it 'adds field definitions as required or optional' do
|
|
97
|
+
t = Norikra::Typedef.new({'a' => 'string'})
|
|
98
|
+
|
|
99
|
+
expect(t.fields.size).to eql(1)
|
|
100
|
+
|
|
101
|
+
t.reserve('b', 'boolean', false)
|
|
102
|
+
expect(t.fields.size).to eql(2)
|
|
103
|
+
expect(t.fields['b'].type).to eql('boolean')
|
|
104
|
+
expect(t.fields['b'].optional?).to be_false
|
|
105
|
+
|
|
106
|
+
t.reserve('c', 'double', true)
|
|
107
|
+
expect(t.fields.size).to eql(3)
|
|
108
|
+
expect(t.fields['c'].type).to eql('double')
|
|
109
|
+
expect(t.fields['c'].optional?).to be_true
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe '#consistent?' do
|
|
114
|
+
context 'without any additional reserved fields' do
|
|
115
|
+
it 'checks all fields of specified fieldset are super-set of baseset or not' do
|
|
116
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
117
|
+
|
|
118
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long'})
|
|
119
|
+
expect(t.consistent?(set)).to be_true
|
|
120
|
+
|
|
121
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long', 'c' => 'double'})
|
|
122
|
+
expect(t.consistent?(set)).to be_true
|
|
123
|
+
|
|
124
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'int'})
|
|
125
|
+
expect(t.consistent?(set)).to be_false
|
|
126
|
+
|
|
127
|
+
set = Norikra::FieldSet.new({'a' => 'string'})
|
|
128
|
+
expect(t.consistent?(set)).to be_false
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context 'with some additional reserved fields' do
|
|
133
|
+
it 'checks all fields of specified fieldset with baseset and additional reserved fields' do
|
|
134
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
135
|
+
t.reserve('c', 'double', false) # required
|
|
136
|
+
t.reserve('d', 'boolean', true) # optional
|
|
137
|
+
|
|
138
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long'})
|
|
139
|
+
expect(t.consistent?(set)).to be_false
|
|
140
|
+
|
|
141
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long', 'c' => 'double'})
|
|
142
|
+
expect(t.consistent?(set)).to be_true
|
|
143
|
+
|
|
144
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long', 'c' => 'double', 'd' => 'boolean'})
|
|
145
|
+
expect(t.consistent?(set)).to be_true
|
|
146
|
+
|
|
147
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long', 'c' => 'double', 'd' => 'string'})
|
|
148
|
+
expect(t.consistent?(set)).to be_false
|
|
149
|
+
|
|
150
|
+
set = Norikra::FieldSet.new({'a' => 'string', 'b' => 'long', 'c' => 'double', 'd' => 'boolean', 'e' => 'string'})
|
|
151
|
+
expect(t.consistent?(set)).to be_true
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe '#push' do
|
|
157
|
+
it 'does not accepts fieldset which conflicts pre-defined fields' do
|
|
158
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
159
|
+
expect { t.push(:query, Norikra::FieldSet.new({'a'=>'string','b'=>'int'})) }.to raise_error(ArgumentError)
|
|
160
|
+
expect { t.push(:data, Norikra::FieldSet.new({'a'=>'string'})) }.to raise_error(ArgumentError)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'accepts fieldsets which is consistent with self' do
|
|
164
|
+
t = Norikra::Typedef.new({'a'=>'string','b'=>'long'})
|
|
165
|
+
expect(t.fields.size).to eql(2)
|
|
166
|
+
|
|
167
|
+
expect { t.push(:query, Norikra::FieldSet.new({'a'=>'string','b'=>'long'})) }.not_to raise_error(ArgumentError)
|
|
168
|
+
expect { t.push(:data, Norikra::FieldSet.new({'a'=>'string','b'=>'long'})) }.not_to raise_error(ArgumentError)
|
|
169
|
+
|
|
170
|
+
expect(t.fields.size).to eql(2)
|
|
171
|
+
|
|
172
|
+
set_a = Norikra::FieldSet.new({'a'=>'string','b'=>'long','c'=>'double'})
|
|
173
|
+
t.push(:data, set_a)
|
|
174
|
+
expect(t.fields.size).to eql(3)
|
|
175
|
+
expect(t.fields['c'].type).to eql('double')
|
|
176
|
+
expect(t.fields['c'].optional?).to be_true
|
|
177
|
+
|
|
178
|
+
t.push(:query, Norikra::FieldSet.new({'a'=>'string','b'=>'long','d'=>'string'}))
|
|
179
|
+
expect(t.fields.size).to eql(4)
|
|
180
|
+
expect(t.fields['d'].type).to eql('string')
|
|
181
|
+
expect(t.fields['d'].optional?).to be_true
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe '#refer' do
|
|
186
|
+
context 'for event defined by data-fieldset already known' do
|
|
187
|
+
it 'returns fieldset that already known itself' do
|
|
188
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
189
|
+
|
|
190
|
+
set1 = Norikra::FieldSet.new({'a'=>'string','b'=>'long'})
|
|
191
|
+
t.push(:data, set1)
|
|
192
|
+
|
|
193
|
+
r = t.refer({'a'=>'foobar','b'=>200000000})
|
|
194
|
+
expect(r).to be_instance_of(Norikra::FieldSet)
|
|
195
|
+
expect(r.object_id).to eql(set1.object_id)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
context 'for event with known fields only' do
|
|
200
|
+
it 'returns fieldset that is overwritten with known field definitions' do
|
|
201
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
202
|
+
t.reserve('c','boolean',true)
|
|
203
|
+
t.reserve('d','double',true)
|
|
204
|
+
|
|
205
|
+
r = t.refer({'a'=>'hoge','b'=>'2000','c'=>'true','d'=>'3.14'})
|
|
206
|
+
expect(t.datafieldsets.include?(r)).to be_false
|
|
207
|
+
|
|
208
|
+
expect(r.fields['a'].type).to eql('string')
|
|
209
|
+
expect(r.fields['b'].type).to eql('long')
|
|
210
|
+
expect(r.fields['c'].type).to eql('boolean')
|
|
211
|
+
expect(r.fields['d'].type).to eql('double')
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
context 'for event with some unknown fields' do
|
|
216
|
+
it 'returns fieldset that contains fields as string for unknowns' do
|
|
217
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
218
|
+
|
|
219
|
+
r = t.refer({'a'=>'hoge','b'=>'2000','c'=>'true','d'=>'3.14'})
|
|
220
|
+
expect(t.datafieldsets.include?(r)).to be_false
|
|
221
|
+
|
|
222
|
+
expect(r.fields['a'].type).to eql('string')
|
|
223
|
+
expect(r.fields['b'].type).to eql('long')
|
|
224
|
+
expect(r.fields['c'].type).to eql('string')
|
|
225
|
+
expect(r.fields['d'].type).to eql('string')
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
describe '#format' do
|
|
231
|
+
it 'returns hash value with formatted fields as defined' do
|
|
232
|
+
t = Norikra::Typedef.new({'a' => 'string', 'b' => 'long'})
|
|
233
|
+
t.reserve('c','boolean',true)
|
|
234
|
+
t.reserve('d','double',true)
|
|
235
|
+
|
|
236
|
+
d = t.format({'a'=>'hoge','b'=>'2000','c'=>'true','d'=>'3.14'})
|
|
237
|
+
expect(d['a']).to be_instance_of(String)
|
|
238
|
+
expect(d['a']).to eql('hoge')
|
|
239
|
+
expect(d['b']).to be_instance_of(Fixnum)
|
|
240
|
+
expect(d['b']).to eql(2000)
|
|
241
|
+
expect(d['c']).to be_instance_of(TrueClass)
|
|
242
|
+
expect(d['c']).to eql(true)
|
|
243
|
+
expect(d['d']).to be_instance_of(Float)
|
|
244
|
+
expect(d['d']).to eql(3.14)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|