Sha256: 0cfb706148522728b0031f02d13559260fe77cf9184bb821b2eab2bf2dbc2517

Contents?: true

Size: 1.68 KB

Versions: 8

Compression:

Stored size: 1.68 KB

Contents

require_relative "../../../spec/es_spec_helper"

describe "client create actions", :integration => true do
  require "logstash/outputs/elasticsearch"
  require "elasticsearch"

  def get_es_output(action, id = nil)
    settings = {
      "manage_template" => true,
      "index" => "logstash-create",
      "template_overwrite" => true,
      "hosts" => get_host(),
      "port" => get_port(),
      "action" => action
    }
    settings['document_id'] = id unless id.nil?
    LogStash::Outputs::ElasticSearch.new(settings)
  end

  before :each do
    @es = get_client
    # Delete all templates first.
    # Clean ES of data before we start.
    @es.indices.delete_template(:name => "*")
    # This can fail if there are no indexes, ignore failure.
    @es.indices.delete(:index => "*") rescue nil
  end

  context "when action => create" do
    it "should create new documents with or without id" do
      subject = get_es_output("create", "id123")
      subject.register
      subject.receive(LogStash::Event.new("message" => "sample message here"))
      subject.buffer_flush(:final => true)
      @es.indices.refresh
      # Wait or fail until everything's indexed.
      Stud::try(3.times) do
        r = @es.search
        insist { r["hits"]["total"] } == 1
      end
    end

    it "should create new documents without id" do
      subject = get_es_output("create")
      subject.register
      subject.receive(LogStash::Event.new("message" => "sample message here"))
      subject.buffer_flush(:final => true)
      @es.indices.refresh
      # Wait or fail until everything's indexed.
      Stud::try(3.times) do
        r = @es.search
        insist { r["hits"]["total"] } == 1
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
logstash-output-elasticsearch-2.1.2-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.1.1-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.1.0-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.0.0.beta6-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.0.0.beta5-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.0.0.beta4-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.0.0.pre.beta2-java spec/integration/outputs/create_spec.rb
logstash-output-elasticsearch-2.0.0.pre.beta-java spec/integration/outputs/create_spec.rb