Sha256: aadfc914430e1bc9962379173e81fb41928f3bf109d642b0591c85baae14a2cc

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

module Ripple
  module Conflict
    module TestHelper
      def create_conflict(main_record, *modifiers)
        # We have to disable all on conflict resolvers while we create conflict
        # so that they don't auto-resolve it.
        orig_hooks = Riak::RObject.on_conflict_hooks.dup
        Riak::RObject.on_conflict_hooks.clear

        begin
          klass, key = main_record.class, main_record.key
          records = modifiers.map { |_| klass.find!(key) }

          records.zip(modifiers).each do |(record, modifier)|
            # necessary to get conflict, so riak thinks they are being saved by different clients
            Ripple.client.client_id += 1

            modifier.call(record)
            record.save!
          end

          robject = klass.bucket.get(key)
          raise "#{robject} is not in conflict as expected." unless robject.conflict?
        ensure
          orig_hooks.each do |hook|
            Riak::RObject.on_conflict(&hook)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
seomoz-ripple-1.0.0.pre lib/ripple/conflict/test_helper.rb
ripple-1.0.0.beta lib/ripple/conflict/test_helper.rb