dryad 0.1.0

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.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +19 -0
  5. data/DRYAD_VERSION +1 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +51 -0
  8. data/LICENSE +19 -0
  9. data/README.md +35 -0
  10. data/Rakefile +6 -0
  11. data/dryad-cluster/.gitignore +11 -0
  12. data/dryad-cluster/.rspec +3 -0
  13. data/dryad-cluster/Gemfile +8 -0
  14. data/dryad-cluster/Gemfile.lock +48 -0
  15. data/dryad-cluster/LICENSE +19 -0
  16. data/dryad-cluster/README.md +35 -0
  17. data/dryad-cluster/Rakefile +6 -0
  18. data/dryad-cluster/bin/console +14 -0
  19. data/dryad-cluster/bin/setup +8 -0
  20. data/dryad-cluster/dryad-cluster.gemspec +29 -0
  21. data/dryad-cluster/lib/dryad/cluster/version.rb +10 -0
  22. data/dryad-cluster/lib/dryad/cluster.rb +17 -0
  23. data/dryad-cluster/spec/dryad/cluster_spec.rb +33 -0
  24. data/dryad-cluster/spec/dummy/config/dryad.yml +15 -0
  25. data/dryad-cluster/spec/spec_helper.rb +18 -0
  26. data/dryad-consul/.gitignore +11 -0
  27. data/dryad-consul/.rspec +3 -0
  28. data/dryad-consul/Gemfile +4 -0
  29. data/dryad-consul/Gemfile.lock +45 -0
  30. data/dryad-consul/LICENSE +19 -0
  31. data/dryad-consul/README.md +35 -0
  32. data/dryad-consul/Rakefile +6 -0
  33. data/dryad-consul/bin/console +14 -0
  34. data/dryad-consul/bin/setup +8 -0
  35. data/dryad-consul/dryad-consul.gemspec +30 -0
  36. data/dryad-consul/lib/dryad/consul/service.rb +33 -0
  37. data/dryad-consul/lib/dryad/consul/service_client.rb +15 -0
  38. data/dryad-consul/lib/dryad/consul/service_registry.rb +37 -0
  39. data/dryad-consul/lib/dryad/consul/version.rb +10 -0
  40. data/dryad-consul/lib/dryad/consul.rb +16 -0
  41. data/dryad-consul/spec/dryad/consul/service_client_spec.rb +6 -0
  42. data/dryad-consul/spec/dryad/consul/service_registry_spec.rb +33 -0
  43. data/dryad-consul/spec/dryad/consul/service_spec.rb +23 -0
  44. data/dryad-consul/spec/dryad/consul_spec.rb +10 -0
  45. data/dryad-consul/spec/spec_helper.rb +14 -0
  46. data/dryad-core/.gitignore +11 -0
  47. data/dryad-core/.rspec +3 -0
  48. data/dryad-core/.travis.yml +7 -0
  49. data/dryad-core/Gemfile +4 -0
  50. data/dryad-core/Gemfile.lock +35 -0
  51. data/dryad-core/LICENSE +19 -0
  52. data/dryad-core/README.md +35 -0
  53. data/dryad-core/Rakefile +6 -0
  54. data/dryad-core/bin/console +14 -0
  55. data/dryad-core/bin/setup +8 -0
  56. data/dryad-core/dryad-core.gemspec +27 -0
  57. data/dryad-core/lib/dryad/configuration.rb +22 -0
  58. data/dryad-core/lib/dryad/core/load_balancing.rb +8 -0
  59. data/dryad-core/lib/dryad/core/portal.rb +21 -0
  60. data/dryad-core/lib/dryad/core/schema.rb +9 -0
  61. data/dryad-core/lib/dryad/core/service.rb +39 -0
  62. data/dryad-core/lib/dryad/core/service_instance.rb +14 -0
  63. data/dryad-core/lib/dryad/core/version.rb +10 -0
  64. data/dryad-core/lib/dryad/core.rb +12 -0
  65. data/dryad-core/lib/dryad.rb +46 -0
  66. data/dryad-core/spec/dryad/core/load_balancing_spec.rb +6 -0
  67. data/dryad-core/spec/dryad/core/portal_spec.rb +13 -0
  68. data/dryad-core/spec/dryad/core/schema_spec.rb +7 -0
  69. data/dryad-core/spec/dryad/core/service_instance_spec.rb +7 -0
  70. data/dryad-core/spec/dryad/core/service_spec.rb +14 -0
  71. data/dryad-core/spec/dryad/core_spec.rb +6 -0
  72. data/dryad-core/spec/dryad_spec.rb +22 -0
  73. data/dryad-core/spec/dummy/config/dryad.yml +15 -0
  74. data/dryad-core/spec/spec_helper.rb +19 -0
  75. data/dryad.gemspec +28 -0
  76. metadata +202 -0
@@ -0,0 +1,33 @@
1
+ module Dryad
2
+ module Consul
3
+ class Service < Dryad::Core::Service
4
+ def to_registers
5
+ portals.map do |portal|
6
+ {
7
+ ID: portal.id,
8
+ Name: Service.full_name(portal.schema, name),
9
+ Address: address,
10
+ Port: portal.port,
11
+ EnableTagOverride: true,
12
+ Tags: tags(portal)
13
+ }
14
+ end
15
+ end
16
+
17
+ private
18
+ def tags(portal)
19
+ tags = [
20
+ "type = \"#{type_name}\"",
21
+ "priority = \"#{priority}\"",
22
+ "group = \"#{group}\"",
23
+ "schema = \"#{portal.schema}\"",
24
+ "pattern = \"#{portal.pattern}\""
25
+ ]
26
+ if portal.non_certifications.count > 0
27
+ tags << "non_certifications = \"#{portal.non_certifications.join(",")}\""
28
+ end
29
+ tags.concat(load_balancing.map{|lb| "load_balancing = \"#{lb}\"" })
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module Dryad
2
+ module Consul
3
+ class ServiceClient
4
+ class << self
5
+ def method_missing(name, *args, &block)
6
+ Diplomat::Service.send(name, *args, &block) || super
7
+ end
8
+
9
+ def respond_to_missing?(meth_id, with_private = false)
10
+ access_method?(meth_id) || super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ module Dryad
2
+ module Consul
3
+ class ServiceRegistry
4
+ class << self
5
+ def register(service)
6
+ service.to_registers.each do |register|
7
+ ServiceClient.register(register)
8
+ end
9
+ end
10
+
11
+ def deregister(service)
12
+ service.portals.each do |portal|
13
+ ServiceClient.deregister(portal.id)
14
+ end
15
+ end
16
+
17
+ def service_instances(name, schema, groups)
18
+ all_services = ServiceClient.get(Dryad::Core::Service.full_name(schema, name), :all)
19
+ services = []
20
+ all_services.each do |service|
21
+ groups.each do |group|
22
+ services << service if service.ServiceTags.include?("group = \"#{group}\"")
23
+ end
24
+ end
25
+ services.map do |service|
26
+ Dryad::Core::ServiceInstance.new(
27
+ name: name,
28
+ schema: schema,
29
+ address: service.ServiceAddress,
30
+ port: service.ServicePort
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module Dryad
2
+ module Consul
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ PRE = nil
7
+
8
+ VERSION = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require "diplomat"
2
+ require "dryad"
3
+ require "dryad/consul/version"
4
+ require "dryad/consul/service_client"
5
+ require "dryad/consul/service_registry"
6
+ require "dryad/consul/service"
7
+
8
+ module Dryad
9
+ module Consul
10
+ class Error < StandardError; end
11
+
12
+ ::Diplomat.configure do |config|
13
+ config.url = "http://#{Dryad.configuration.consul[:host]}:#{Dryad.configuration.consul[:port]}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.describe Dryad::Consul::ServiceClient do
2
+ it "can get all services" do
3
+ services = Dryad::Consul::ServiceClient.get_all()
4
+ expect(services.consul.count).to be(0)
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+ RSpec.describe Dryad::Consul::ServiceRegistry do
2
+ before do
3
+ @portal = Dryad::Core::Portal.new(
4
+ schema: Dryad::Core::Schema::HTTP,
5
+ port: 3000,
6
+ pattern: '/*',
7
+ non_certifications: ['/*']
8
+ )
9
+ @service = Dryad::Consul::Service.new(
10
+ name: 'rails',
11
+ address: '127.0.0.1',
12
+ group: 'staging',
13
+ portals: [@portal],
14
+ priority: 10,
15
+ load_balancing: [Dryad::Core::LoadBalancing::URL_HASH]
16
+ )
17
+ end
18
+
19
+ it "gets the instances for a service" do
20
+ Dryad::Consul::ServiceRegistry.register(@service)
21
+ registers = @service.to_registers
22
+ service_instances = Dryad::Consul::ServiceRegistry.service_instances(
23
+ @service.name,
24
+ Dryad::Core::Schema::HTTP,
25
+ [@service.group]
26
+ )
27
+ expect(service_instances.count).to eq(registers.count)
28
+ service_instances.zip(registers).each do |instance, register|
29
+ expect(instance.name).to eq(register[:Name])
30
+ end
31
+ Dryad::Consul::ServiceRegistry.deregister(@service)
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ RSpec.describe Dryad::Consul::Service do
2
+ before do
3
+ @portal = Dryad::Core::Portal.new(
4
+ schema: Dryad::Core::Schema::HTTP,
5
+ port: 3000,
6
+ pattern: '/*',
7
+ non_certifications: ['/*']
8
+ )
9
+ @service = Dryad::Consul::Service.new(
10
+ name: 'http-service',
11
+ address: '127.0.0.1',
12
+ group: 'staging',
13
+ portals: [@portal],
14
+ priority: 10,
15
+ load_balancing: [Dryad::Core::LoadBalancing::URL_HASH]
16
+ )
17
+ end
18
+
19
+ it "gets all registers" do
20
+ registers = @service.to_registers
21
+ expect(registers.count).to eq(@service.portals.count)
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ RSpec.describe Dryad::Consul do
2
+ it "has a version number" do
3
+ version = File.read(File.expand_path("../../../DRYAD_VERSION", __dir__)).strip
4
+ expect(Dryad::Consul::VERSION).to eq(version)
5
+ end
6
+
7
+ it "has configured dependencies" do
8
+ expect(::Diplomat.configuration.url).to eq("http://localhost:8500")
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "dryad/consul"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/dryad-core/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dryad-core.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dryad-core (0.1.0.alpha)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 2.0)
30
+ dryad-core!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 2.0.1
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Dryad::Core
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dryad/core`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dryad-core'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dryad-core
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dryad-core.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dryad/core"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dryad/core/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dryad-core"
8
+ spec.version = Dryad::Core::VERSION
9
+ spec.authors = ["Pan Jie"]
10
+ spec.email = ["panjie@growingio.com"]
11
+
12
+ spec.summary = %q{Dryad core library.}
13
+ spec.description = %q{Dryad core includes the basic objects.}
14
+ spec.homepage = "https://github.com/jack0pan/dryad.rb"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 2.0"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,22 @@
1
+ module Dryad
2
+ class Configuration
3
+ attr_accessor :consul, :namespace, :group, :registry, :service
4
+
5
+ DEFAULT_OPTIONS = {
6
+ consul: {
7
+ host: 'localhost',
8
+ port: 8500
9
+ },
10
+ service: {}
11
+ }
12
+
13
+ def initialize(opts = {})
14
+ opts = DEFAULT_OPTIONS.merge(opts)
15
+ @consul = opts[:consul]
16
+ @namespace = opts[:namespace]
17
+ @group = opts[:group]
18
+ @registry = opts[:registry]
19
+ @service = opts[:service]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ module Dryad
2
+ module Core
3
+ module LoadBalancing
4
+ URL_HASH = "url_chash"
5
+ ROUND_ROBIN = "round_robin"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ require 'securerandom'
2
+
3
+ module Dryad
4
+ module Core
5
+ class Portal
6
+ attr_accessor :id, :schema, :port, :pattern, :check, :non_certifications
7
+
8
+ DEFAULT_OPTIONS = {
9
+ :non_certifications => []
10
+ }
11
+
12
+ def initialize(options = DEFAULT_OPTIONS)
13
+ @id = SecureRandom.uuid
14
+ @schema = options[:schema]
15
+ @port = options[:port]
16
+ @pattern = options[:pattern]
17
+ @non_certifications = options[:non_certifications]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Dryad
2
+ module Core
3
+ module Schema
4
+ HTTP = "http"
5
+ GRPC = "grpc"
6
+ WEB_SOCKET = "web-socket"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ module Dryad
2
+ module Core
3
+ class Service
4
+ attr_accessor :name, :address, :group, :portals, :priority, :load_balancing
5
+
6
+ TYPE = "microservice"
7
+
8
+ DEFAULT_OPTIONS = {
9
+ :portals => [],
10
+ :load_balancing => []
11
+ }
12
+
13
+ def initialize(options = {})
14
+ options = DEFAULT_OPTIONS.merge(options)
15
+ @name = options[:name]
16
+ @address = options[:address]
17
+ @group = options[:group]
18
+ @portals = options[:portals]
19
+ @priority = options[:priority]
20
+ @load_balancing = options[:load_balancing]
21
+ end
22
+
23
+ def type_name
24
+ Dryad::Core::Service::TYPE
25
+ end
26
+
27
+ class << self
28
+ def full_name(schema, name)
29
+ case schema
30
+ when Schema::HTTP
31
+ name
32
+ else
33
+ "#{name}-#{schema}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ module Dryad
2
+ module Core
3
+ class ServiceInstance
4
+ attr_accessor :name, :schema, :address, :port
5
+
6
+ def initialize(options = {})
7
+ @name = options[:name]
8
+ @schema = options[:schema]
9
+ @address = options[:address]
10
+ @port = options[:port]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module Dryad
2
+ module Core
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ PRE = nil
7
+
8
+ VERSION = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require "dryad/core/version"
2
+ require "dryad/core/service_instance"
3
+ require "dryad/core/service"
4
+ require "dryad/core/portal"
5
+ require "dryad/core/load_balancing"
6
+ require "dryad/core/schema"
7
+
8
+ module Dryad
9
+ module Core
10
+ class Error < StandardError; end
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ require "dryad/configuration"
2
+ require "dryad/core"
3
+ require "yaml"
4
+ require "erb"
5
+
6
+ DRYAD_COFNIG_FILE = ENV["DRYAD_CONFIG_FILE"] || "config/dryad.yml"
7
+
8
+ module Dryad
9
+ class Error < StandardError; end
10
+
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration)
21
+ end
22
+
23
+ def self.configure_with_file
24
+ environment = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "default"
25
+ opts = YAML.load(ERB.new(File.read(DRYAD_COFNIG_FILE)).result)[environment] || Configuration::DEFAULT_OPTIONS
26
+
27
+ if opts.respond_to? :deep_symbolize_keys!
28
+ opts.deep_symbolize_keys!
29
+ else
30
+ symbolize_keys_deep!(opts)
31
+ end
32
+
33
+ @configuration = Configuration.new(opts)
34
+ end
35
+
36
+ private
37
+ def self.symbolize_keys_deep!(hash)
38
+ hash.keys.each do |k|
39
+ symkey = k.respond_to?(:to_sym) ? k.to_sym : k
40
+ hash[symkey] = hash.delete k
41
+ symbolize_keys_deep! hash[symkey] if hash[symkey].is_a? Hash
42
+ end
43
+ end
44
+ end
45
+
46
+ Dryad.configure_with_file if File.exist?(DRYAD_COFNIG_FILE)
@@ -0,0 +1,6 @@
1
+ RSpec.describe Dryad::Core::LoadBalancing do
2
+ it "values are correct" do
3
+ expect(Dryad::Core::LoadBalancing::URL_HASH).to eq("url_chash")
4
+ expect(Dryad::Core::LoadBalancing::ROUND_ROBIN).to eq("round_robin")
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.describe Dryad::Core::Portal do
2
+ it "creates with default options" do
3
+ portal = Dryad::Core::Portal.new
4
+ expect(portal.id).not_to be(nil)
5
+ expect(portal.non_certifications).to eq([])
6
+ end
7
+
8
+ it "creates portals with different id" do
9
+ portals = Array.new(100) { Dryad::Core::Portal.new }
10
+ ids_set = portals.map{|portal| portal.id }.to_set
11
+ expect(ids_set.count).to eq(portals.count)
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.describe Dryad::Core::Schema do
2
+ it "has valid values" do
3
+ expect(Dryad::Core::Schema::HTTP).to eq("http")
4
+ expect(Dryad::Core::Schema::GRPC).to eq("grpc")
5
+ expect(Dryad::Core::Schema::WEB_SOCKET).to eq("web-socket")
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.describe Dryad::Core::ServiceInstance do
2
+ it 'can be created and access' do
3
+ si = Dryad::Core::ServiceInstance.new(name: 'grpc-service', schema: 'grpc', address: 'localhost', port: 19000)
4
+ expect(si.name).to eq('grpc-service')
5
+ expect(si.schema).to eq('grpc')
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.describe Dryad::Core::Service do
2
+ it "create with default options" do
3
+ service = Dryad::Core::Service.new
4
+ expect(service.type_name).to eq(Dryad::Core::Service::TYPE)
5
+ expect(service.portals).to eq([])
6
+ expect(service.load_balancing).to eq([])
7
+ end
8
+
9
+ it "create with options" do
10
+ service = Dryad::Core::Service.new(name: "rails", address: "localhost", group: "staging", priority: 10)
11
+ expect(service.name).to eq("rails")
12
+ expect(service.address).to eq("localhost")
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.describe Dryad::Core do
2
+ it "has a version number" do
3
+ version = File.read(File.expand_path("../../../DRYAD_VERSION", __dir__)).strip
4
+ expect(Dryad::Core::VERSION).to eq(version)
5
+ end
6
+ end