Sha256: 3e5c9e530c8dd9c39c4a46b5a1460289b017085e1c095282ff97736f8018b210

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 KB

Contents

# encoding: utf-8
require "logstash/inputs/metrics"
require "spec_helper"

describe LogStash::Inputs::Metrics do
  before :each do
    LogStash::Instrument::Collector.instance.clear
  end

  let(:queue) { [] }

  describe "#run" do
    it "should register itself to the collector observer" do
      expect(LogStash::Instrument::Collector.instance).to receive(:add_observer).with(subject)
      t = Thread.new { subject.run(queue) }
      sleep(0.1) # give a bit of time to the thread to start
      subject.stop
    end
  end

  describe "#update" do
    let(:namespaces)  { [:root, :base] }
    let(:key)        { :foo }
    let(:metric_store) { LogStash::Instrument::MetricStore.new }

    it "should fill up the queue with received events" do
      Thread.new { subject.run(queue) }
      sleep(0.1)
      subject.stop

      metric_store.fetch_or_store(namespaces, key, LogStash::Instrument::MetricType::Counter.new(namespaces, key))
      subject.update(LogStash::Instrument::Snapshot.new(metric_store))
      expect(queue.count).to eq(1)
    end
  end

  describe "#stop" do
    it "should remove itself from the the collector observer" do
      expect(LogStash::Instrument::Collector.instance).to receive(:delete_observer).with(subject)
      t = Thread.new { subject.run(queue) }
      sleep(0.1) # give a bit of time to the thread to start
      subject.stop
    end

    it "should unblock the input" do
      t = Thread.new { subject.run(queue) }
      sleep(0.1) # give a bit of time to the thread to start
      subject.do_stop
      wait_for { t.status }.to be_falsey
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
logstash-core-5.0.0.alpha4.snapshot1-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot8-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot7-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot6-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot5-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot4-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot2-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha3.snapshot1-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha2-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha2.snapshot2-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha2.snapshot1-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha1-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha1.snapshot2-java spec/logstash/inputs/metrics_spec.rb
logstash-core-5.0.0.alpha1.snapshot1-java spec/logstash/inputs/metrics_spec.rb