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,91 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
|
|
3
|
+
require 'norikra/typedef'
|
|
4
|
+
|
|
5
|
+
module Norikra
|
|
6
|
+
class TypedefManager
|
|
7
|
+
attr_reader :typedefs
|
|
8
|
+
|
|
9
|
+
def initialize(opts={})
|
|
10
|
+
@typedefs = {} # {target => Typedef}
|
|
11
|
+
@mutex = Mutex.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def field_list(target)
|
|
15
|
+
@typedefs[target].fields.values.sort{|a,b| a.name <=> b.name}.map(&:to_hash)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_target(target, fields)
|
|
19
|
+
# fields nil => lazy
|
|
20
|
+
# fields {'fieldname' => 'type'}
|
|
21
|
+
@mutex.synchronize do
|
|
22
|
+
raise RuntimeError, "target #{target} already exists" if @typedefs[target]
|
|
23
|
+
@typedefs[target] = Typedef.new(fields)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def lazy?(target)
|
|
28
|
+
@typedefs[target].lazy?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def activate(target, fieldset)
|
|
32
|
+
@typedefs[target].activate(fieldset)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def reserve(target, field, type)
|
|
36
|
+
@typedefs[target].reserve(field, type)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def fields_defined?(target, field_name_list)
|
|
40
|
+
@typedefs[target].field_defined?(field_name_list)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def bind_fieldset(target, level, fieldset)
|
|
44
|
+
fieldset.bind(target, level)
|
|
45
|
+
@typedefs[target].push(level, fieldset)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def generate_base_fieldset(target, event)
|
|
49
|
+
guessed = Norikra::FieldSet.simple_guess(event, false) # all fields are non-optional
|
|
50
|
+
guessed.update(@typedefs[target].fields, false)
|
|
51
|
+
guessed
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def generate_query_fieldset(target, field_name_list)
|
|
55
|
+
# all fields of field_name_list should exists in definitions of typedef fields
|
|
56
|
+
# for this premise, call 'bind_fieldset' for data fieldset before this method.
|
|
57
|
+
required_fields = {}
|
|
58
|
+
@mutex.synchronize do
|
|
59
|
+
@typedefs[target].fields.each do |fieldname, field|
|
|
60
|
+
if field_name_list.include?(fieldname) || !(field.optional?)
|
|
61
|
+
required_fields[fieldname] = {:type => field.type, :optional => field.optional}
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
Norikra::FieldSet.new(required_fields)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def base_fieldset(target)
|
|
69
|
+
@typedefs[target].baseset
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def subsets(target, fieldset) # for data fieldset
|
|
73
|
+
sets = []
|
|
74
|
+
@mutex.synchronize do
|
|
75
|
+
@typedefs[target].queryfieldsets.each do |set|
|
|
76
|
+
sets.push(set) if set.subset?(fieldset)
|
|
77
|
+
end
|
|
78
|
+
sets.push(@typedefs[target].baseset)
|
|
79
|
+
end
|
|
80
|
+
sets
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def refer(target, event)
|
|
84
|
+
@typedefs[target].refer(event)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def format(target, event)
|
|
88
|
+
@typedefs[target].format(event)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/norikra.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'norikra/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "norikra"
|
|
8
|
+
spec.version = Norikra::VERSION
|
|
9
|
+
spec.authors = ["TAGOMORI Satoshi"]
|
|
10
|
+
spec.email = ["tagomoris@gmail.com"]
|
|
11
|
+
spec.summary = %q{CEP engine/server with Esper and JRuby}
|
|
12
|
+
spec.description = %q{CEP: Complex Event Processor with Esper EPL qeury language, messagepack rpc for inbound event data}
|
|
13
|
+
spec.homepage = "https://github.com/tagomoris/norikra"
|
|
14
|
+
spec.license = "GPLv2"
|
|
15
|
+
spec.platform = "java"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files`.split($/)
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib", "esper"]
|
|
21
|
+
|
|
22
|
+
spec.add_runtime_dependency "mizuno", "~> 0.6"
|
|
23
|
+
spec.add_runtime_dependency "rack"
|
|
24
|
+
spec.add_runtime_dependency "msgpack-rpc-over-http-jruby", ">= 0.0.5.jruby1"
|
|
25
|
+
spec.add_runtime_dependency "thor"
|
|
26
|
+
spec.add_runtime_dependency "norikra-client-jruby"
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
29
|
+
spec.add_development_dependency "rake"
|
|
30
|
+
spec.add_development_dependency "rspec", "~> 2.0"
|
|
31
|
+
spec.add_development_dependency "spork"
|
|
32
|
+
spec.add_development_dependency "pry"
|
|
33
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'drb'
|
|
4
|
+
require 'pry'
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
begin
|
|
8
|
+
DRb.start_service("druby://localhost:0")
|
|
9
|
+
rescue SocketError, Errno::EADDRNOTAVAIL
|
|
10
|
+
DRb.start_service("druby://:0")
|
|
11
|
+
end
|
|
12
|
+
$spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
|
|
13
|
+
rescue DRb::DRbConnError
|
|
14
|
+
err.puts "No DRb server is running. Running in local process instead ..."
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def rspec(file=nil)
|
|
18
|
+
if file
|
|
19
|
+
$spec_server.run(["--color", "--format", "s", file], STDERR, STDOUT)
|
|
20
|
+
else
|
|
21
|
+
$spec_server.run(["--color", 'spec'], STDERR, STDOUT)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
puts <<DESC
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
> rspec 'spec/xxx_spec.rb'
|
|
29
|
+
or (for all tests)
|
|
30
|
+
> rspec
|
|
31
|
+
|
|
32
|
+
DESC
|
|
33
|
+
|
|
34
|
+
$LOAD_PATH.push './lib'
|
|
35
|
+
$LOAD_PATH.push './esper'
|
|
36
|
+
|
|
37
|
+
require 'norikra'
|
|
38
|
+
|
|
39
|
+
require 'java'
|
|
40
|
+
require 'esper-4.9.0.jar'
|
|
41
|
+
require 'esper/lib/commons-logging-1.1.1.jar'
|
|
42
|
+
require 'esper/lib/antlr-runtime-3.2.jar'
|
|
43
|
+
require 'esper/lib/cglib-nodep-2.2.jar'
|
|
44
|
+
|
|
45
|
+
Pry.start
|
data/spec/field_spec.rb
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require_relative './spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'norikra/typedef'
|
|
4
|
+
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'digest'
|
|
7
|
+
|
|
8
|
+
describe Norikra::Field do
|
|
9
|
+
describe '.valid_type?' do
|
|
10
|
+
it 'returns normalized type strings' do
|
|
11
|
+
expect(Norikra::Field.valid_type?('String')).to eql('string')
|
|
12
|
+
expect(Norikra::Field.valid_type?('STRING')).to eql('string')
|
|
13
|
+
expect(Norikra::Field.valid_type?(:string)).to eql('string')
|
|
14
|
+
expect(Norikra::Field.valid_type?('string')).to eql('string')
|
|
15
|
+
|
|
16
|
+
expect(Norikra::Field.valid_type?('boolean')).to eql('boolean')
|
|
17
|
+
expect(Norikra::Field.valid_type?('BOOLEAN')).to eql('boolean')
|
|
18
|
+
expect(Norikra::Field.valid_type?('Int')).to eql('int')
|
|
19
|
+
expect(Norikra::Field.valid_type?('lonG')).to eql('long')
|
|
20
|
+
expect(Norikra::Field.valid_type?('FLOAT')).to eql('float')
|
|
21
|
+
expect(Norikra::Field.valid_type?('Double')).to eql('double')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'raises ArgumentError for unknown type string' do
|
|
25
|
+
expect { Norikra::Field.valid_type?('foo') }.to raise_error(ArgumentError)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'when initialized' do
|
|
30
|
+
it 'value of field name is normalized to string' do
|
|
31
|
+
expect(Norikra::Field.new('foo', 'string').name).to be_instance_of String
|
|
32
|
+
expect(Norikra::Field.new(:foo, 'string').name).to be_instance_of String
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'value of type is normalized with .valid_type?' do
|
|
36
|
+
expect(Norikra::Field.new('foo', 'String').type).to eql(Norikra::Field.valid_type?('String'))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'default value of optional is nil' do
|
|
40
|
+
expect(Norikra::Field.new(:foo, 'String').optional).to be_nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'has non-nil value for optional' do
|
|
45
|
+
describe '#dup' do
|
|
46
|
+
context 'without values' do
|
|
47
|
+
it 'saves original boolean value' do
|
|
48
|
+
f = Norikra::Field.new('foo', 'string', false)
|
|
49
|
+
expect(f.dup.optional).to eql(false)
|
|
50
|
+
|
|
51
|
+
f = Norikra::Field.new('foo', 'int', true)
|
|
52
|
+
expect(f.dup.optional).to eql(true)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context 'with value' do
|
|
57
|
+
it 'will be overwritten with specified value' do
|
|
58
|
+
f = Norikra::Field.new('bar', 'float', false)
|
|
59
|
+
expect(f.dup(true).optional).to eql(true)
|
|
60
|
+
|
|
61
|
+
f = Norikra::Field.new('bar', 'double', true)
|
|
62
|
+
expect(f.dup(false).optional).to eql(false)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'defined as string field' do
|
|
69
|
+
describe '#format' do
|
|
70
|
+
it 'converts specified value as string' do
|
|
71
|
+
f = Norikra::Field.new('x', 'string')
|
|
72
|
+
expect(f.format('foo bar')).to eql('foo bar')
|
|
73
|
+
expect(f.format('foo bar'.to_sym)).to eql('foo bar')
|
|
74
|
+
expect(f.format(500)).to eql('500')
|
|
75
|
+
expect(f.format(' ')).to eql(' ')
|
|
76
|
+
expect(f.format(true)).to eql('true')
|
|
77
|
+
expect(f.format(false)).to eql('false')
|
|
78
|
+
expect(f.format(nil)).to eql('')
|
|
79
|
+
expect(f.format({})).to eql('{}')
|
|
80
|
+
expect(f.format([])).to eql('[]')
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'defined as boolean' do
|
|
86
|
+
describe '#format' do
|
|
87
|
+
it 'converts specified value as boolean' do
|
|
88
|
+
f = Norikra::Field.new('x', 'boolean')
|
|
89
|
+
expect(f.format(true)).to eql(true)
|
|
90
|
+
expect(f.format(false)).to eql(false)
|
|
91
|
+
expect(f.format(nil)).to eql(false)
|
|
92
|
+
expect(f.format('')).to eql(true)
|
|
93
|
+
|
|
94
|
+
expect(f.format('true')).to eql(true)
|
|
95
|
+
expect(f.format('false')).to eql(false)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context 'defined as numeric value (int/long/float/double)' do
|
|
101
|
+
describe '#format' do
|
|
102
|
+
it 'convertes specified value as numeric' do
|
|
103
|
+
f = Norikra::Field.new('x', 'int')
|
|
104
|
+
expect(f.format('1')).to eql(1)
|
|
105
|
+
expect(f.format('1.0')).to eql(1)
|
|
106
|
+
expect(f.format('0.1')).to eql(0)
|
|
107
|
+
expect(f.format('.1')).to eql(0)
|
|
108
|
+
expect(f.format('')).to eql(0)
|
|
109
|
+
expect(f.format(' ')).to eql(0)
|
|
110
|
+
expect(f.format(nil)).to eql(0)
|
|
111
|
+
|
|
112
|
+
f = Norikra::Field.new('x', 'long')
|
|
113
|
+
expect(f.format('1')).to eql(1)
|
|
114
|
+
expect(f.format('1.0')).to eql(1)
|
|
115
|
+
expect(f.format('0.1')).to eql(0)
|
|
116
|
+
expect(f.format('.1')).to eql(0)
|
|
117
|
+
expect(f.format('')).to eql(0)
|
|
118
|
+
expect(f.format(' ')).to eql(0)
|
|
119
|
+
expect(f.format(nil)).to eql(0)
|
|
120
|
+
|
|
121
|
+
f = Norikra::Field.new('x', 'float')
|
|
122
|
+
expect(f.format('1')).to eql(1.0)
|
|
123
|
+
expect(f.format('1.0')).to eql(1.0)
|
|
124
|
+
expect(f.format('0.1')).to eql(0.1)
|
|
125
|
+
expect(f.format('.1')).to eql(0.1)
|
|
126
|
+
expect(f.format('')).to eql(0.0)
|
|
127
|
+
expect(f.format(' ')).to eql(0.0)
|
|
128
|
+
expect(f.format(nil)).to eql(0.0)
|
|
129
|
+
|
|
130
|
+
f = Norikra::Field.new('x', 'double')
|
|
131
|
+
expect(f.format('1')).to eql(1.0)
|
|
132
|
+
expect(f.format('1.0')).to eql(1.0)
|
|
133
|
+
expect(f.format('0.1')).to eql(0.1)
|
|
134
|
+
expect(f.format('.1')).to eql(0.1)
|
|
135
|
+
expect(f.format('')).to eql(0.0)
|
|
136
|
+
expect(f.format(' ')).to eql(0.0)
|
|
137
|
+
expect(f.format(nil)).to eql(0.0)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
require_relative './spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'norikra/typedef'
|
|
4
|
+
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'digest'
|
|
7
|
+
|
|
8
|
+
describe Norikra::FieldSet do
|
|
9
|
+
describe '.simple_guess' do
|
|
10
|
+
it 'can guess field definitions with class of values' do
|
|
11
|
+
t = Norikra::FieldSet.simple_guess({'key1' => true, 'key2' => false, 'key3' => 10, 'key4' => 3.1415, 'key5' => 'foobar'})
|
|
12
|
+
r = t.definition
|
|
13
|
+
expect(r['key1']).to eql('boolean')
|
|
14
|
+
expect(r['key2']).to eql('boolean')
|
|
15
|
+
expect(r['key3']).to eql('long')
|
|
16
|
+
expect(r['key4']).to eql('double')
|
|
17
|
+
expect(r['key5']).to eql('string')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'does not guess with content of string values' do
|
|
21
|
+
t = Norikra::FieldSet.simple_guess({'key1' => 'TRUE', 'key2' => 'false', 'key3' => "10", 'key4' => '3.1415', 'key5' => {:a => 1}})
|
|
22
|
+
r = t.definition
|
|
23
|
+
expect(r['key1']).to eql('string')
|
|
24
|
+
expect(r['key2']).to eql('string')
|
|
25
|
+
expect(r['key3']).to eql('string')
|
|
26
|
+
expect(r['key4']).to eql('string')
|
|
27
|
+
expect(r['key5']).to eql('string')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'can be initialized with both of Hash parameter and String' do
|
|
32
|
+
it 'accepts String as type' do
|
|
33
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long'})
|
|
34
|
+
expect(set.fields['x'].type).to eql('string')
|
|
35
|
+
expect(set.fields['y'].type).to eql('long')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'sets optional specification nil as defaults' do
|
|
39
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long'})
|
|
40
|
+
expect(set.fields['x'].optional).to be_nil
|
|
41
|
+
expect(set.fields['y'].optional).to be_nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'accepts second argument as optional specification' do
|
|
45
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long'}, false)
|
|
46
|
+
expect(set.fields['x'].optional?).to be_false
|
|
47
|
+
expect(set.fields['y'].optional?).to be_false
|
|
48
|
+
|
|
49
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long'}, true)
|
|
50
|
+
expect(set.fields['x'].optional?).to be_true
|
|
51
|
+
expect(set.fields['y'].optional?).to be_true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'sets summary as comma-separated labeled field-type string with sorted field order' do
|
|
55
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long'})
|
|
56
|
+
expect(set.summary).to eql('x:string,y:long')
|
|
57
|
+
|
|
58
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long', 'a' => 'Boolean'})
|
|
59
|
+
expect(set.summary).to eql('a:boolean,x:string,y:long')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context 'initialized with some fields' do
|
|
64
|
+
set = Norikra::FieldSet.new({'x' => 'string', 'y' => 'long', 'a' => 'Boolean'})
|
|
65
|
+
|
|
66
|
+
describe '#dup' do
|
|
67
|
+
it 'make duplicated object with different internal instance' do
|
|
68
|
+
x = set.dup
|
|
69
|
+
expect(x.fields.object_id).not_to eql(set.fields.object_id)
|
|
70
|
+
expect(x.fields).to eq(set.fields)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#field_names_key' do
|
|
75
|
+
it 'returns comman-separeted sorted field names' do
|
|
76
|
+
expect(set.field_names_key).to eql('a,x,y')
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#udpate_summary' do
|
|
81
|
+
it 'changes summary with current @fields' do
|
|
82
|
+
x = set.dup
|
|
83
|
+
x.fields = set.fields.dup
|
|
84
|
+
|
|
85
|
+
oldsummary = x.summary
|
|
86
|
+
|
|
87
|
+
x.fields['x'] = Norikra::Field.new('x', 'int')
|
|
88
|
+
|
|
89
|
+
expect(x.summary).to eql(oldsummary)
|
|
90
|
+
|
|
91
|
+
x.update_summary
|
|
92
|
+
|
|
93
|
+
expect(x.summary).not_to eql(oldsummary)
|
|
94
|
+
expect(x.summary).to eql('a:boolean,x:int,y:long')
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#update' do
|
|
99
|
+
it 'changes field definition of this instance' do
|
|
100
|
+
x = set.dup
|
|
101
|
+
expect(x.fields['a'].type).to eql('boolean')
|
|
102
|
+
expect(x.fields['x'].type).to eql('string')
|
|
103
|
+
|
|
104
|
+
expect(x.fields['y'].type).to eql('long')
|
|
105
|
+
expect(x.fields['y'].optional).to be_nil
|
|
106
|
+
|
|
107
|
+
x.update([Norikra::Field.new('y', 'int'), Norikra::Field.new('a','string')], false)
|
|
108
|
+
|
|
109
|
+
expect(x.fields['y'].type).to eql('int')
|
|
110
|
+
expect(x.fields['y'].optional).to eql(false)
|
|
111
|
+
|
|
112
|
+
expect(x.fields['x'].type).to eql('string')
|
|
113
|
+
expect(x.fields['a'].type).to eql('string')
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'adds field definition' do
|
|
117
|
+
x = set.dup
|
|
118
|
+
expect(x.fields.size).to eql(3)
|
|
119
|
+
x.update([Norikra::Field.new('z', 'string')], true)
|
|
120
|
+
expect(x.fields.size).to eql(4)
|
|
121
|
+
expect(x.summary).to eql('a:boolean,x:string,y:long,z:string')
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe '#definition' do
|
|
126
|
+
it 'returns hash instance of fieldname => esper type' do
|
|
127
|
+
d = set.definition
|
|
128
|
+
expect(d).to be_instance_of(Hash)
|
|
129
|
+
expect(d.size).to eql(3)
|
|
130
|
+
expect(d['a']).to eql('boolean')
|
|
131
|
+
expect(d['x']).to eql('string')
|
|
132
|
+
expect(d['y']).to eql('long')
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '#subset?' do
|
|
137
|
+
it 'returns true when other instance has all fields of self' do
|
|
138
|
+
other = Norikra::FieldSet.new({'a' => 'boolean', 'x' => 'string'})
|
|
139
|
+
expect(set.subset?(other)).to be_false
|
|
140
|
+
|
|
141
|
+
other.update([Norikra::Field.new('y', 'long')], false)
|
|
142
|
+
expect(set.subset?(other)).to be_true
|
|
143
|
+
|
|
144
|
+
other.update([Norikra::Field.new('z', 'double')], false)
|
|
145
|
+
expect(set.subset?(other)).to be_true
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe '#bind' do
|
|
150
|
+
it 'sets event_type_name internally, and returns self' do
|
|
151
|
+
x = set.dup
|
|
152
|
+
|
|
153
|
+
expect(x.instance_eval{ @event_type_name }).to be_nil
|
|
154
|
+
|
|
155
|
+
expect(x.bind('TargetExample', :query)).to eql(x)
|
|
156
|
+
|
|
157
|
+
expect(x.instance_eval{ @event_type_name }).not_to be_nil
|
|
158
|
+
expect(x.instance_eval{ @event_type_name }).to eql('q_' + Digest::MD5.hexdigest("TargetExample\tquery\t" + x.summary))
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
describe '#event_type_name' do
|
|
163
|
+
it 'returns duplicated string of @event_type_name' do
|
|
164
|
+
x = set.dup
|
|
165
|
+
x.bind('TargetExample', :query)
|
|
166
|
+
internal = x.instance_eval{ @event_type_name }
|
|
167
|
+
expect(x.event_type_name.object_id).not_to eql(internal.object_id)
|
|
168
|
+
expect(x.event_type_name).to eql(internal)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|