Class: DangoTesterClient

Inherits:
Object show all
Defined in:
lib/dango/tester/dango_tester_client.rb

Overview

テスタークラス

Constant Summary collapse

ConnectionRetryTimes =

接続リトライ回数

10
ConnectionRetryIntervalSec =

接続リトライ時の間隔病数

3
GCIntervalSec =

GCの発生タイミング

5.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDangoTesterClient

テスターのイニシャライズ



17
18
19
20
21
22
23
24
25
# File 'lib/dango/tester/dango_tester_client.rb', line 17

def initialize
  @client_conns = {}
  Thread.abort_on_exception = true
  
  # GC発生タイミングを決定
  @gc_interval_sec = GCIntervalSec
  gc_thread_start()                     # GCスレッドの開始
  
end

Instance Attribute Details

#client_connsObject (readonly)

Returns the value of attribute client_conns.



62
63
64
# File 'lib/dango/tester/dango_tester_client.rb', line 62

def client_conns
  @client_conns
end

Class Method Details

.die(str) ⇒ Object



71
72
73
# File 'lib/dango/tester/dango_tester_client.rb', line 71

def self.die(str)
  die(str)
end

Instance Method Details

#die(str) ⇒ Object



64
65
66
67
68
69
# File 'lib/dango/tester/dango_tester_client.rb', line 64

def die(str)
  puts "============ die ============ #{Time.now_to_s}"
  pp caller()
  puts str
  exit 1
end

#gc_thread_startObject

GCスレッドの開始



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dango/tester/dango_tester_client.rb', line 76

def gc_thread_start
  th = Thread.start do
    loop do
      begin
        sleep @gc_interval_sec
        
        gc_start_time = Time.now
        GC.enable
        GC.start 
        GC.disable
        puts "GC #{Time.now - gc_start_time}sec #{Time.now_to_s}"
        
      rescue
        puts "Exception gc_thread_start #{Time.now_to_s} #{error_message($!, 'u')}"
      end
    end
  end
  th.priority = -1
end

#new_client(c_name, serv_info) ⇒ Object

クライアントを1個接続



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
# File 'lib/dango/tester/dango_tester_client.rb', line 28

def new_client(c_name, serv_info)
  config = {
    "network" => {
      "host"=>serv_info["host"],
      "port"=>serv_info["port"],
    }, 
  }
  env = "development"
  
  # 接続
  client_conn = nil
  ConnectionRetryTimes.times do |i|
    begin
      client_conn = TestClient.new(env, config, c_name)
      break
    rescue
      client_conn = nil
      raise("connection error for retry times over.") if i == ConnectionRetryTimes - 1
      puts "connection failed. sleep #{ConnectionRetryIntervalSec}"
      sleep ConnectionRetryIntervalSec
    end
  end
  raise("connection error.") if ! client_conn
  
  # client_nameメソッド作成とclient_nameを定義
  client_conn.client_name = c_name
  
  # 接続を入れて
  @client_conns[c_name] = client_conn
  
  # 接続インスタンスを返す
  client_conn
end