str =15252 Add dsl consistency spec

This commit is contained in:
Patrik Nordwall 2014-05-22 08:00:14 +02:00
parent e46319fa79
commit db5b27c17e
2 changed files with 81 additions and 4 deletions

View file

@ -169,12 +169,15 @@ public class FlowTest {
@Override @Override
public scala.collection.immutable.Seq<String> onTermination(Option<Throwable> e) { public scala.collection.immutable.Seq<String> onTermination(Option<Throwable> e) {
if (e.isEmpty()) return Util.immutableSeq(new String[0]); if (e.isEmpty())
else return Util.immutableSingletonSeq(e.get().getMessage()); return Util.immutableSeq(new String[0]);
else
return Util.immutableSingletonSeq(e.get().getMessage());
} }
@Override @Override
public void onError(Throwable e) {} public void onError(Throwable e) {
}
@Override @Override
public boolean isComplete() { public boolean isComplete() {
@ -375,7 +378,7 @@ public class FlowTest {
if (e == null) if (e == null)
probe.getRef().tell("done", ActorRef.noSender()); probe.getRef().tell("done", ActorRef.noSender());
else else
probe.getRef().tell(e, ActorRef.noSender()); probe.getRef().tell(e.getMessage(), ActorRef.noSender());
} }
}); });

View file

@ -0,0 +1,74 @@
/**
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.stream
import java.lang.reflect.Method
import org.scalatest.Matchers
import org.scalatest.WordSpec
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class DslConsistencySpec extends WordSpec with Matchers {
val ignore = Set("equals", "hashCode", "notify", "notifyAll", "wait", "create", "apply", "toString", "getClass",
"ops", "appendJava")
val allowMissing: Map[Class[_], Set[String]] = Map.empty
def materializing(m: Method): Boolean = m.getParameterTypes.contains(classOf[FlowMaterializer])
val sflowClass = classOf[akka.stream.scaladsl.Flow[_]]
val sductClass = classOf[akka.stream.scaladsl.Duct[_, _]]
val jflowClass = classOf[akka.stream.javadsl.Flow[_]]
val jductClass = classOf[akka.stream.javadsl.Duct[_, _]]
def assertHasMethod(c: Class[_], name: String): Unit = {
// include class name to get better error message
if (!allowMissing.getOrElse(c, Set.empty).contains(name))
c.getMethods.collect { case m if !ignore(m.getName) c.getName + "." + m.getName } should
contain(c.getName + "." + name)
}
"Java and Scala DSLs" must {
"provide same Flow and Duct transforming operators" in {
val classes = List(sflowClass, sductClass, jflowClass, jductClass)
val allOps =
(for {
c classes
m c.getMethods
if !ignore(m.getName)
if !materializing(m)
} yield m.getName).toSet
for (c classes; op allOps)
assertHasMethod(c, op)
}
"provide same Flow materializing operators" in {
val classes = List(sflowClass, jflowClass)
val materializingOps =
(for {
c classes
m c.getMethods
if !ignore(m.getName)
if materializing(m)
} yield m.getName).toSet
for (c classes; op materializingOps)
assertHasMethod(c, op)
}
"provide same Duct materializing operators" in {
val classes = List(sductClass, jductClass)
val materializingOps =
(for {
c classes
m c.getMethods
if !ignore(m.getName)
if materializing(m)
} yield m.getName).toSet
for (c classes; op materializingOps)
assertHasMethod(c, op)
}
}
}