This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
/
spec_helper.rb
145 lines (132 loc) · 4.89 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright (c) 2009-2011 VMware, Inc.
$:.unshift File.join(File.dirname(__FILE__), '..')
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'
require 'rspec'
require 'bundler/setup'
require 'vcap_services_base'
require "mysql_service/util"
require 'mysql_service/provisioner'
require 'mysql_service/node'
require 'mysql_service/with_warden'
# monkey patch of wardenized node
module VCAP::Services::Mysql::WithWarden
alias_method :pre_send_announcement_internal_ori, :pre_send_announcement_internal
def pre_send_announcement_internal(options)
unless @options[:not_start_instances]
pre_send_announcement_internal_ori(options)
else
@pool_mutex = Mutex.new
@pools = {}
@logger.info("Not to start instances")
mysqlProvisionedService.all.each do |instance|
new_port(instance.port)
setup_pool(instance)
end
end
end
def create_missing_pools
mysqlProvisionedService.all.each do |instance|
unless @pools.keys.include?(instance.name)
new_port(instance.port)
setup_pool(instance)
end
end
end
alias_method :shutdown_ori, :shutdown
def shutdown
if @use_warden && @options[:not_start_instances]
super
else
shutdown_ori
end
end
end
module Boolean; end
class ::TrueClass; include Boolean; end
class ::FalseClass; include Boolean; end
def getLogger()
logger = Logger.new( STDOUT)
logger.level = Logger::ERROR
return logger
end
def connect_to_mysql(options)
host, user, password, port, db = %w{hostname user password port name}.map { |opt| options[opt] }
Mysql2::Client.new(:host => host, :username => user, :password => password, :database => db, :port => port)
end
def connection_pool_klass
VCAP::Services::Mysql::Util::ConnectionPool
end
def parse_property(hash, key, type, options = {})
obj = hash[key]
if obj.nil?
raise "Missing required option: #{key}" unless options[:optional]
nil
elsif type == Range
raise "Invalid Range object: #{obj}" unless obj.kind_of?(Hash)
first, last = obj["first"], obj["last"]
raise "Invalid Range object: #{obj}" unless first.kind_of?(Integer) and last.kind_of?(Integer)
Range.new(first, last)
else
raise "Invalid #{type} object: #{obj}" unless obj.kind_of?(type)
obj
end
end
def config_base_dir
File.join(File.dirname(__FILE__), '..', 'config')
end
def getNodeTestConfig()
config_file = File.join(config_base_dir, 'mysql_node.yml')
config = YAML.load_file(config_file)
options = {
:logger => getLogger,
:base_dir => parse_property(config, "base_dir", String),
:plan => parse_property(config, "plan", String),
:capacity => parse_property(config, "capacity", Integer),
:gzip_bin => parse_property(config, "gzip_bin", String),
:max_db_size => parse_property(config, "max_db_size", Integer),
:max_long_query => parse_property(config, "max_long_query", Integer),
:node_id => parse_property(config, "node_id", String),
:connection_pool_size => parse_property(config, "connection_pool_size", Hash),
:mbus => parse_property(config, "mbus", String),
:local_db => parse_property(config, "local_db", String),
:mysql => parse_property(config, "mysql", Hash),
:ip_route => parse_property(config, "ip_route", String, :optional => true),
:max_long_tx => parse_property(config, "max_long_tx", Integer),
:kill_long_tx => parse_property(config, "kill_long_tx", Boolean),
:max_user_conns => parse_property(config, "max_user_conns", Integer, :optional => true),
:connection_wait_timeout => 10,
:max_disk => parse_property(config, "max_disk", Integer),
:use_warden => parse_property(config, "use_warden", Boolean),
:supported_versions => parse_property(config, "supported_versions", Array),
}
if options[:use_warden]
warden_config = parse_property(config, "warden", Hash, :optional => true)
options[:service_log_dir] = parse_property(warden_config, "service_log_dir", String)
options[:image_dir] = parse_property(warden_config, "image_dir", String)
options[:port_range] = parse_property(warden_config, "port_range", Range)
options[:service_start_timeout] = parse_property(warden_config, "service_start_timeout", Integer, :optional => true, :default => 3)
options[:filesystem_quota] = parse_property(warden_config, "filesystem_quota", Boolean, :optional => true)
else
options[:ip_route] = "127.0.0.1"
end
options
end
def getProvisionerTestConfig()
config_file = File.join(config_base_dir, 'mysql_gateway.yml')
config = YAML.load_file(config_file)
config = VCAP.symbolize_keys(config)
options = {
:logger => getLogger,
:version => config[:service][:version],
:local_ip => config[:host],
:plan_management => config[:plan_management],
:mbus => config[:mbus]
}
options
end
def new_node(options)
opts = options.dup
opts[:not_start_instances] = true if opts[:use_warden]
VCAP::Services::Mysql::Node.new(opts)
end