Sha256: 97cb9eec486067cfbc08b9371bd4f88459f01ccbdaaa053fb9a5e2df106c16b1

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

RSpec.describe Locator do
  subject(:locator) { Locator.new id }

  let(:id) { SecureRandom.uuid }
  let(:node) { Node.new('flashing-sparkle', '10.0.0.70') }
  let(:other_node) { Node.new('winking-tiger', '10.0.0.90') }
  let(:nodes) { [node, other_node] }
  let(:node_list) { spy(nodes_for: nodes, state: 'initial') }

  before do
    allow(Aggro).to receive(:node_list).and_return node_list
  end

  describe '#local?' do
    context 'primary node is a LocalNode' do
      let(:node) { LocalNode.new('flashing-sparkle') }

      it 'should return true' do
        expect(locator.local?).to be_truthy
      end
    end

    context 'primary node is not a LocalNode' do
      it 'should return true' do
        expect(locator.local?).to be_falsey
      end
    end
  end

  describe '#nodes' do
    it 'should return the nodes on which the aggregate should persist' do
      expect(locator.nodes.first.endpoint).to eq '10.0.0.70'
    end

    it 'should memorize the lookup to reduce hashing' do
      5.times { locator.nodes }

      expect(node_list).to have_received(:nodes_for).once
    end

    it 'should forget memorized servers if ring state changes' do
      locator.nodes
      allow(node_list).to receive(:state).and_return('changed')
      locator.nodes

      expect(node_list).to have_received(:nodes_for).twice
    end
  end

  describe '#primary_node' do
    it 'should return the first associated node' do
      expect(locator.primary_node).to eq node
    end
  end

  describe '#secondary_nodes' do
    it 'should return the rest of the associated nodes' do
      expect(locator.secondary_nodes).to eq [other_node]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aggro-0.0.4 spec/lib/aggro/locator_spec.rb
aggro-0.0.3 spec/lib/aggro/locator_spec.rb
aggro-0.0.2 spec/lib/aggro/locator_spec.rb