3

I'd like to test a Finagle Resolver properly.

Let's get a sample code:

import com.twitter.finagle.{Addr, Address, Resolver}
import com.twitter.util._

class DummyResolver extends Resolver {

  override val scheme: String = "sample"

  override def bind(arg: String): Var[Addr] = {

    val delegate = SomeFactory.fromArgs(arg).build()

    Var.async(Addr.Pending: Addr)(u => addrOf(u)(delegate))
  }
}

The use of a static factory prevents me from unit-testing the resolver.

As far as I know, the only way to provide the resolver to Finagle is to declare it into the com.twitter.finagle.Resolver file in META-INF/services. Thus, I cannot provide an instance myself.

Given those constraints, how to design the resolver to either:

  • be able to provide an instance of the delegate,
  • or be able to properly test the behavior (and mock the delegate)?
Alban Dericbourg
  • 1,616
  • 2
  • 16
  • 39
  • Did you manage to fix it?. I´m really consider leave finagle framework, there´s no documentation and a big community behind. – paul May 13 '17 at 11:57
  • 1
    No, I did not. What I did is extracting as much code as possible from the DummyResolver class and test that extracted code. The DummyResolver remains un-properly tested. – Alban Dericbourg May 13 '17 at 13:30

0 Answers0