0

I'm trying to write some code as part of a larger integration test.

I have a function that creates a KinesisSource of type Source[KinesisRecord, Future[Done]:

protected def createKinesisSource(config: KinesisClientLibConfiguration): Source[KinesisRecord, Future[Done]]#Repr[MyFile.KinesisFlow] = {
  KinesisSource(config).mapAsync(1)(processRecord)
}

protected def processRecord(record: KinesisRecord): Future[KinesisFlow] = {
    Future { validateRecord(record) }
}

I want to create a fake source of the same type from a file. I have (pardon the code, I'm new to scala):

val records = scala.io.Source.fromFile("testFile.txt").getLines.toList
  .map(i => {
    new KinesisRecord( ByteString.fromString(i), "x", None, "x", None, Instant.now(), "x")
  })

Source(records).mapAsync(1)(processRecord)

That gives me a Source[KinesisRecord, NotUsed]. How can I change that to Source[KinesisRecord, Future[Done]]? I understand that the second parameter is the materialized value (see this post), but I'm not sure how to specify that value without actually applying a run function.

Łukasz Gawron
  • 897
  • 10
  • 20

1 Answers1

3

You could use mapMaterializedValue(_ => Future.successful(Done)) or Future.never

But if the materialized value has impact in your integration tests this will affect them because the Future will complete right after stream materialization or never.

gabrielgiussi
  • 9,245
  • 7
  • 41
  • 71