Files
mozo-backend/spec/support/in_memory_q_counter.rb
T

30 lines
561 B
Ruby

# 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
STORE = {}
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
end
def decr(key, options = {})
STORE[key] ||= options[:initial].to_i
STORE[key] -= 1
end
def flush
STORE.clear
end
end