Skip to content

Commit

Permalink
Add optimistic locking to Solr persister
Browse files Browse the repository at this point in the history
Fixes #453

Co-authored-by: Mike Tribone <[email protected]>
Co-authored-by: Anna Headley <[email protected]>
  • Loading branch information
3 people committed Aug 1, 2018
1 parent 3e925ac commit b7ad934
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/valkyrie/specs/shared_specs/locking_persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,27 @@ class MyLockingResource < Valkyrie::Resource
context "when updating a resource with an incorrect lock token" do
it "raises a Valkyrie::Persistence::StaleObjectError" do
resource = MyLockingResource.new(title: ["My Locked Resource"])
<<<<<<< HEAD
resource = persister.save(resource: resource)
# update the resource in the datastore to make its token stale
persister.save(resource: resource)

expect { persister.save(resource: resource) }.to raise_error(Valkyrie::Persistence::StaleObjectError, resource.id.to_s)
=======
initial_resource = persister.save(resource: resource)
initial_resource.send("#{Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK}=", [123])
expect { persister.save(resource: initial_resource) }.to raise_error(Valkyrie::Persistence::StaleObjectError, resource.id.to_s)
end
end

# The only error we catch is the 409 conflict
context "when updating a resource with an invalid token" do
it "raises an Rsolr 500 Error" do
resource = MyLockingResource.new(title: ["My Locked Resource"])
initial_resource = persister.save(resource: resource)
initial_resource.send("#{Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK}=", ["NOT_EVEN_A_VALID_TOKEN"])
expect { persister.save(resource: initial_resource) }.to raise_error(RSolr::Error::Http)
>>>>>>> Add optimistic locking to Solr persister
end
end

Expand Down Expand Up @@ -91,9 +107,13 @@ class MyLockingResource < Valkyrie::Resource
resource2 = MyLockingResource.new(title: ["My Locked Resource 2"])
resource3 = MyLockingResource.new(title: ["My Locked Resource 3"])
resource1, resource2, resource3 = persister.save_all(resources: [resource1, resource2, resource3])
<<<<<<< HEAD
# update a resource in the datastore to make its token stale
persister.save(resource: resource2)

=======
resource2.send("#{Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK}=", [123])
>>>>>>> Add optimistic locking to Solr persister
expect { persister.save_all(resources: [resource1, resource2, resource3]) }
.to raise_error(Valkyrie::Persistence::StaleObjectError, [resource1, resource2, resource3].map(&:id).join(", "))
end
Expand Down

0 comments on commit b7ad934

Please sign in to comment.