I'm working on a backend migration on some scala code. The code current returns com.twitter.util.Future[A] and I am taking the response from my new backend and transforming it into Future[A] as well
To monitor the migration, I want to do a comparison so I can tell how often the response from the 2 backends differ, so I have something like
val b1Resp: Future[A] = getResponseFromBackend1()
val b2Resp: Future[A] = getResponseFromBackend2() map { resp => convert(resp)}
return b1Resp
I want to verify that the results of the futures are either the same or that they both fail. On discrepancies, I will be publishing a metric.
Moreover, I don't want to delay the return. I don't really care when the metric is published (within reason of course), so it's okay to allow execution to continue
How do I do the comparison?
The broad outline of what you want to do is
Note that
Future.join.foreach
just arranges for the comparison etc. to happen in the future; it should only add a few microseconds to the block.For standard library futures, the equivalent to
Future.join.foreach
is (assuming an implicitExecutionContext
is in scope):