Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - txn.lease support #95

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/etcdv3/kv/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Transaction
version: 0,
create_revision: 1,
mod_revision: 2,
value: 3
value: 3,
lease: 4
}

attr_writer :compare, :success, :failure
Expand Down Expand Up @@ -73,6 +74,11 @@ def create_revision(key, compare_type, value)
generate_compare(:create_revision, key, compare_type, value)
end

# txn.lease('names', :equal, 12456)
def lease(key, compare_type, value)
generate_compare(:lease, key, compare_type, value)
end

private

def generate_compare(target_union, key, compare_type, value)
Expand Down
32 changes: 32 additions & 0 deletions spec/etcdv3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,38 @@
end
end
end

describe 'txn.lease' do
let!(:lease_id) { conn.lease_grant(2)['ID'] }
before { conn.put('txn', 'value') }
after { conn.del('txn') }
context 'success' do
subject! do
conn.transaction do |txn|
txn.compare = [ txn.lease('txn', :equal, lease_id) ]
txn.success = [ txn.put('txn-test', 'success') ]
txn.failure = [ txn.put('txn-test', 'failed') ]
end
end
it 'sets correct key' do
expect(conn.get('txn-test').kvs.first.value).to eq('success')
end
end
context 'failure' do
subject! do
conn.transaction do |txn|
txn.compare = [ txn.lease('txn', :equal, 123456)]
txn.success = [ txn.put('txn-test', 'success') ]
txn.failure = [ txn.put('txn-test', 'failed') ]
end
end
it 'sets correct key' do
puts conn.get('txn').inspect
expect(conn.get('txn-test').kvs.first.value).to eq('failed')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the txn.lease comparisons return successful no matter what the comparison is.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this hasn't been put into a release yet... Holding off on this..

end
end
end

end
end
end