-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to Zookeeper reporter to periodically "touch" node (#126)
This essentially implements a heartbeat mechanism for persistent nodes, in order to keep the node's `mtime` up-to-date.
- Loading branch information
Showing
7 changed files
with
546 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
nerve (0.9.5) | ||
nerve (0.9.6) | ||
bunny (= 1.1.0) | ||
dogstatsd-ruby (~> 3.3.0) | ||
etcd (~> 0.2.3) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'thread' | ||
|
||
module Nerve | ||
class AtomicValue | ||
def initialize(initial_value) | ||
@mu = Mutex.new | ||
set(initial_value) | ||
end | ||
|
||
def get | ||
return @mu.synchronize { @value } | ||
end | ||
|
||
def set(new_value) | ||
@mu.synchronize { | ||
@value = new_value | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Nerve | ||
VERSION = "0.9.5" | ||
VERSION = "0.9.6" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'spec_helper' | ||
require 'nerve/atomic' | ||
|
||
describe Nerve::AtomicValue do | ||
let(:initial_value) { 'mock-value' } | ||
let(:internal_mu) { subject.instance_variable_get(:@mu) } | ||
|
||
subject { Nerve::AtomicValue.new(initial_value) } | ||
|
||
describe '#initialize' do | ||
it 'creates successfully' do | ||
expect { subject }.not_to raise_error | ||
end | ||
|
||
it 'sets the initial value' do | ||
expect(subject.get).to eq(initial_value) | ||
end | ||
|
||
context 'without a provided value' do | ||
it 'raises an error' do | ||
expect { Nerve::AtomicValue.new }.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
|
||
describe '#get' do | ||
let(:value) { 'new-value' } | ||
|
||
before :each do | ||
subject.instance_variable_set(:@value, value) | ||
end | ||
|
||
it 'returns the internal value' do | ||
expect(subject.get).to eq(value) | ||
end | ||
|
||
it 'holds a lock' do | ||
expect(internal_mu).to receive(:synchronize).exactly(:once) | ||
subject.get | ||
end | ||
|
||
it 'releases lock after call' do | ||
expect(internal_mu.locked?).to eq(false) | ||
subject.get | ||
end | ||
|
||
context 'after a set' do | ||
it 'returns the new value' do | ||
subject.set(value) | ||
expect(subject.get).to eq(value) | ||
end | ||
end | ||
end | ||
|
||
describe '#set' do | ||
let(:value) { 'new-value' } | ||
|
||
it 'sets the internal value' do | ||
expect { subject.set(value) } | ||
.to change { subject.instance_variable_get(:@value) } | ||
.from(initial_value).to(value) | ||
end | ||
|
||
it 'holds a lock' do | ||
expect(internal_mu).to receive(:synchronize).exactly(:once) | ||
subject.set(value) | ||
end | ||
|
||
it 'releases lock after call' do | ||
expect(internal_mu.locked?).to eq(false) | ||
subject.set(value) | ||
end | ||
end | ||
end |
Oops, something went wrong.