Class: Rhoconnect::RhoInternalBenchmarkAdapter

Inherits:
SourceAdapter show all
Defined in:
lib/rhoconnect/predefined_adapters/bench_adapter.rb

Instance Attribute Summary

Attributes inherited from SourceAdapter

#result, #session

Instance Method Summary collapse

Methods inherited from SourceAdapter

#ask, create, #do_query, #expire_bulk_data, #logoff, #save, #search, #stash_result, #sync, #validate

Constructor Details

#initialize(source) ⇒ RhoInternalBenchmarkAdapter

Returns a new instance of RhoInternalBenchmarkAdapter.



10
11
12
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 10

def initialize(source) 
  super(source)
end

Instance Method Details

#create(create_hash) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 31

def create(create_hash)
  id = create_hash['mock_id']
  Rhoconnect::Store.lock(lock_name,1) do
    Rhoconnect::Store.put_data(db_name,{id=>create_hash},true) if id
  end
  id
end

#db_nameObject



59
60
61
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 59

def db_name
  "test_db_storage:#{@source.app_id}:#{@source.user_id}"
end

#delete(delete_hash) ⇒ Object



52
53
54
55
56
57
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 52

def delete(delete_hash)
  id = delete_hash.delete('id')
  Rhoconnect::Store.lock(lock_name,1) do
    Rhoconnect::Store.delete_data(db_name,{id=>delete_hash}) if id
  end
end

#lock_nameObject



63
64
65
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 63

def lock_name
  "lock:#{db_name}"
end

#loginObject



14
15
16
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 14

def 
  true
end

#query(params = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 18

def query(params=nil)
  if @source.simulate_time > 0
    #for i in 1..10
    #  RestClient.get('www.google.com')
    #end
    sleep @source.simulate_time
  end
  Rhoconnect::Store.lock(lock_name,1) do
    @result = Rhoconnect::Store.get_data(db_name)
  end
  @result
end

#update(update_hash) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 39

def update(update_hash)
  id = update_hash.delete('id')
  return unless id
  Rhoconnect::Store.lock(lock_name,1) do
    data = Rhoconnect::Store.get_data(db_name)
    return unless data and data[id]
    update_hash.each do |attrib,value|
      data[id][attrib] = value
    end
    Rhoconnect::Store.put_data(db_name,data)
  end
end