Class: Rhoconnect::RhoInternalBenchmarkAdapter
- Inherits:
-
Model::Base
- Object
- Model::Base
- Rhoconnect::RhoInternalBenchmarkAdapter
show all
- Defined in:
- lib/rhoconnect/predefined_adapters/bench_adapter.rb
Instance Attribute Summary
Attributes inherited from Model::Base
#result, #session, #source
Instance Method Summary
collapse
Methods inherited from Model::Base
#after_query, #ask, #before_query, create, #current_user, #do_query, enable, #expire_bulk_data, #get_data, load, load_source_model, #logoff, partition_name, #push_deletes, #push_objects, #run_validators, #search, #stash_result, #sync, #validate
extended, #validators
#bind_handler
Constructor Details
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_name ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 60
def db_name
res = ''
if @source.user_id[0..1] == 'nq'
res = "test_db_storage:#{@source.app_id}:nquser"
elsif @source.user_id[0..1] == 'mq'
res = "test_db_storage:#{@source.app_id}:mquser"
else
res = "test_db_storage:#{@source.app_id}:benchuser"
end
res
end
|
#delete(delete_hash) ⇒ Object
52
53
54
55
56
57
58
|
# 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
id
end
|
#lock_name ⇒ Object
72
73
74
|
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 72
def lock_name
"lock:#{db_name}"
end
|
#login ⇒ Object
14
15
16
|
# File 'lib/rhoconnect/predefined_adapters/bench_adapter.rb', line 14
def login
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
sleep @source.simulate_time
end
@result = Rhoconnect::Store.get_data(db_name)
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
|