This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an Akka Stream Sink graph stage for Kinesis. (#47)
Add a `KinesisSinkGraphStage` that uses an underlying `KinesisProducerActor` to do the heavy lifting. The stream manages back pressure by allowing only a fixed number of outstanding messages. A materialized value is used to indicate when a stream has been finished (or failed).
- Loading branch information
1 parent
6ac885e
commit f6aaeb7
Showing
10 changed files
with
542 additions
and
15 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
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
49 changes: 49 additions & 0 deletions
49
...ala/com/weightwatchers/reactive/kinesis/stream/KinesisSinkGraphStageIntegrationSpec.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,49 @@ | ||
package com.weightwatchers.reactive.kinesis.stream | ||
|
||
import akka.stream.scaladsl.Source | ||
import com.weightwatchers.reactive.kinesis.common.{ | ||
AkkaUnitTestLike, | ||
KinesisConfiguration, | ||
KinesisSuite | ||
} | ||
import com.weightwatchers.reactive.kinesis.models.ProducerEvent | ||
import org.scalatest.{FreeSpec, Matchers} | ||
|
||
import scala.concurrent.duration._ | ||
|
||
class KinesisSinkGraphStageIntegrationSpec | ||
extends FreeSpec | ||
with KinesisSuite | ||
with KinesisConfiguration | ||
with AkkaUnitTestLike | ||
with Matchers { | ||
|
||
"KinesisSinkGraph" - { | ||
|
||
"produced messages are written to the stream" in new withKinesisConfForApp("sink_produce") { | ||
val messageCount = 100 | ||
val elements = 1.to(messageCount).map(_.toString) | ||
Source(elements) | ||
.map(num => ProducerEvent(num, num)) | ||
.runWith(Kinesis.sink(producerConf())) | ||
.futureValue | ||
val list = testConsumer.retrieveRecords(TestStreamName, messageCount) | ||
list should contain allElementsOf elements | ||
testConsumer.shutdown() | ||
} | ||
|
||
"upstream fail should fail the materialized value of the sink" in new withKinesisConfForApp( | ||
"sink_fail" | ||
) { | ||
Source | ||
.failed(new IllegalStateException("Boom")) | ||
.runWith(Kinesis.sink(producerConf())) | ||
.failed | ||
.futureValue shouldBe a[IllegalStateException] | ||
} | ||
} | ||
|
||
// do not create messages in setup, we will create messages inside the test | ||
override def TestStreamNrOfMessagesPerShard: Long = 0 | ||
override implicit def patienceConfig: PatienceConfig = PatienceConfig(60.seconds, 1.second) | ||
} |
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
Oops, something went wrong.