-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Elasticsearch: Handle failed Future when invoking endpoint in Source (#…
- Loading branch information
1 parent
c76657c
commit 0de667e
Showing
2 changed files
with
73 additions
and
7 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
54 changes: 54 additions & 0 deletions
54
...h/src/test/scala/akka/stream/alpakka/elasticsearch/impl/ElasticsearchSourcStageTest.scala
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,54 @@ | ||
/* | ||
* Copyright (C) 2016-2020 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.stream.alpakka.elasticsearch.impl | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.{Http, HttpExt} | ||
import akka.stream.Materializer | ||
import akka.stream.alpakka.elasticsearch._ | ||
import akka.stream.alpakka.testkit.scaladsl.LogCapturing | ||
import akka.stream.scaladsl.{Keep, Source} | ||
import akka.stream.testkit.scaladsl.TestSink | ||
import akka.testkit.TestKit | ||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
class ElasticsearchSourcStageTest | ||
extends TestKit(ActorSystem("elasticsearchSourceStagetest")) | ||
with AnyWordSpecLike | ||
with BeforeAndAfterAll | ||
with LogCapturing { | ||
|
||
implicit val mat: Materializer = Materializer(system) | ||
implicit val http: HttpExt = Http() | ||
|
||
"ElasticsearchSourceStage" when { | ||
"client cannot connect to ES" should { | ||
"stop the stream" in { | ||
val downstream = Source | ||
.fromGraph( | ||
new impl.ElasticsearchSourceStage[String]( | ||
ElasticsearchParams.V7("es-simple-flow-index"), | ||
Map("query" -> """{ "match_all":{}}"""), | ||
ElasticsearchSourceSettings(ElasticsearchConnectionSettings("http://wololo:9202")), | ||
(json: String) => ScrollResponse(Some(json), None) | ||
) | ||
) | ||
.toMat(TestSink.probe)(Keep.right) | ||
.run() | ||
|
||
downstream.request(1) | ||
downstream.expectError() | ||
} | ||
} | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
super.afterAll() | ||
TestKit.shutdownActorSystem(system) | ||
} | ||
} |