Skip to content

Commit

Permalink
Test isolation semantics for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Johnson committed Feb 15, 2016
1 parent 3491a6e commit 13cffbe
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions lib/rdf/spec/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@
end

describe '#execute' do
# @todo: test isolation semantics!

let(:st) { RDF::Statement(:s, RDF::URI('p'), 'o') }
context 'after rollback' do
before { subject.rollback }

Expand All @@ -203,6 +203,74 @@
.to raise_error RDF::Transaction::TransactionError
end
end

context 'when :read_committed' do
it 'does not read uncommitted statements' do
unless subject.isolation_level == :read_uncommitted
read_tx = klass.new(repository, mutable: true)
subject.insert(st)

expect(read_tx.statements).not_to include(st)
end
end

it 'reads committed statements' do
if subject.isolation_level == :read_committed
read_tx = klass.new(repository)
subject.insert(st)
subject.execute

expect(read_tx.statements).to include(st)
end
end
end

context 'when :repeatable_read' do
it 'does not read committed statements already read' do
if subject.isolation_level == :repeatable_read ||
subject.isolation_level == :snapshot ||
subject.isolation_level == :serializable
read_tx = klass.new(repository)
subject.insert(st)
subject.execute

expect(read_tx.statements).not_to include(st)
end
end
end

context 'when :snapshot' do
it 'does not read committed statements' do
if subject.isolation_level == :snapshot ||
subject.isolation_level == :serializable
read_tx = klass.new(repository)
subject.insert(st)
subject.execute

expect(read_tx.statements).not_to include(st)
end
end

it 'reads current transaction state' do
if subject.isolation_level == :snapshot ||
subject.isolation_level == :serializable
subject.insert(st)
expect(subject.statements).to include(st)
end
end
end

context 'when :serializable' do
it 'raises an error if conflicting changes are present' do
if subject.isolation_level == :serializable
subject.insert(st)
repository.insert(st)

expect { subject.execute }
.to raise_error RDF::Transaction::TransactionError
end
end
end
end

describe '#rollback' do
Expand Down

0 comments on commit 13cffbe

Please sign in to comment.