42 lines
801 B
Ruby
42 lines
801 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
|
|
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
|
|
end
|
|
|
|
def decr(key, options = {})
|
|
store[key] ||= options[:initial].to_i
|
|
store[key] -= 1
|
|
end
|
|
|
|
def flush
|
|
store.clear
|
|
end
|
|
end
|
|
|
|
=begin Make drb server
|
|
require 'drb'
|
|
DRb.start_service 'druby://:9000', InMemoryQCounter.new
|
|
puts "Counter server running at #{DRb.uri}"
|
|
trap("INT") { DRb.stop_service }
|
|
DRb.thread.join
|
|
=end
|