Sha256: 6714f8dada8e984a73d8d38e9a0c97126ed7d0a83ed07160fbfc98a3fd974675

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

describe MassiveRecord::Wrapper::Row do
  before :all do
    @connection = MassiveRecord::Wrapper::Connection.new(:host => MR_CONFIG['host'], :port => MR_CONFIG['port'])
    @connection.open
    @table = MassiveRecord::Wrapper::Table.new(@connection, MR_CONFIG['table']).tap do |table|
      table.column_families.create(:misc)
      table.save
    end
  end

  after do
    @table.all.each &:destroy
  end
  
  after :all do
    @table.destroy
    @connection.close
  end

  
  let(:atomic_inc_attr_name) { 'misc:atomic' }
  subject do
    MassiveRecord::Wrapper::Row.new.tap do |row|
      row.id = "ID1"
      row.table = @table
      row.save
    end
  end




  describe "#atomic_increment" do
    it "increments to 1 when called on a new value" do
      subject.atomic_increment(atomic_inc_attr_name).should eq 1
    end

    it "increments by 2 when asked to do so" do
      subject.atomic_increment(atomic_inc_attr_name, 2).should eq 2
    end
  end

  describe "#read_atomic_integer_value" do
    it "returns 0 if no atomic increment operation has been performed" do
      subject.read_atomic_integer_value(atomic_inc_attr_name).should eq 0
    end

    it "returns 1 after one incrementation of 1" do
      subject.atomic_increment(atomic_inc_attr_name)
      subject.read_atomic_integer_value(atomic_inc_attr_name).should eq 1
    end

    it "returns -1 after one decrementation of 1" do
      subject.atomic_decrement(atomic_inc_attr_name).should eq -1
      subject.read_atomic_integer_value(atomic_inc_attr_name).should eq -1
    end
  end


  describe "#atomic_decrement" do
    it "decrements to -1 when called on a new value" do
      subject.atomic_decrement(atomic_inc_attr_name).should eq -1
    end

    it "decrements by 2 when asked to do so" do
      subject.atomic_decrement(atomic_inc_attr_name, 2).should eq -2
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massive_record-0.2.2 spec/adapter/thrift/atomic_increment_spec.rb
massive_record-0.2.2.rc2 spec/adapter/thrift/atomic_increment_spec.rb
massive_record-0.2.2.rc1 spec/adapter/thrift/atomic_increment_spec.rb