Replace couchbase counters with drb version

This commit is contained in:
2014-08-05 17:49:16 +02:00
parent c0c25673bf
commit 99a9536c68
20 changed files with 400 additions and 282 deletions
+43
View File
@@ -0,0 +1,43 @@
# This is a non thread safe replacement for the
# couchbase counter mechanism since every test needs
# a clean start and Hash#clear is soooo much faster than
# a couchbase bucket flush
class InMemoryQCounter
attr_reader :store
def initialize
@store = {}
end
def get(key, options = {})
store[key]
end
def set(key, value)
store[key] = value
end
def incr(key, options = {})
# store[key] ||= options[:initial].to_i
# store[key] += 1
if store[key]
store[key] += 1
else
store[key] = options[:initial].to_i
end
end
def decr(key, options = {})
# store[key] ||= options[:initial].to_i
# store[key] -= 1
if store[key]
store[key] -= 1
else
store[key] = options[:initial].to_i
end
end
def flush
store.clear
end
end