Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #287 from twitter/feature/memory_no_gen
Browse files Browse the repository at this point in the history
Feature/memory no gen
  • Loading branch information
johnynek committed Oct 10, 2013
2 parents e108e3a + 0038a0f commit 2bb1564
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object SummingbirdBuild extends Build {
"Twitter Maven" at "http://maven.twttr.com"
),

parallelExecution in Test := false, // until scalding 0.9.0 we can't do this
parallelExecution in Test := true,

scalacOptions ++= Seq(
"-unchecked",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class TestGraphs[P <: Platform[P], T: Manifest: Arbitrary, K: Arbitrary, V: Arbi
run: (P, P#Plan[_]) => Unit
){

def diamondChecker = forAll { (items: List[T], fnA: T => List[(K, V)], fnB: T => List[(K, V)]) =>
def diamondChecker(items: List[T], fnA: T => List[(K, V)], fnB: T => List[(K, V)]): Boolean = {
val currentStore = store()
val currentSink = sink()
// Use the supplied platform to execute the source into the
Expand All @@ -190,7 +190,7 @@ class TestGraphs[P <: Platform[P], T: Manifest: Arbitrary, K: Arbitrary, V: Arbi
* initial data source is generated using the supplied sourceMaker
* function.
*/
def singleStepChecker = forAll { (items: List[T], fn: T => List[(K, V)]) =>
def singleStepChecker(items: List[T], fn: T => List[(K, V)]): Boolean = {
val currentStore = store()
// Use the supplied platform to execute the source into the
// supplied store.
Expand All @@ -217,9 +217,9 @@ class TestGraphs[P <: Platform[P], T: Manifest: Arbitrary, K: Arbitrary, V: Arbi
* and the initial data source is generated using the supplied
* sourceMaker function.
*/
def leftJoinChecker[U: Arbitrary, JoinedU: Arbitrary](service: P#Service[K, JoinedU])
(serviceToFn: P#Service[K, JoinedU] => (K => Option[JoinedU])) =
forAll { (items: List[T], preJoinFn: T => List[(K, U)], postJoinFn: ((K, (U, Option[JoinedU]))) => List[(K, V)]) =>
def leftJoinChecker[U: Arbitrary, JoinedU: Arbitrary](service: P#Service[K, JoinedU], serviceToFn: P#Service[K, JoinedU] => (K => Option[JoinedU]),
items: List[T], preJoinFn: T => List[(K, U)],
postJoinFn: ((K, (U, Option[JoinedU]))) => List[(K, V)]): Boolean = {
val currentStore = store()

val plan = platform.plan {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import com.twitter.summingbird._
import org.scalacheck.{ Arbitrary, Properties }
import org.scalacheck.Prop._
import collection.mutable.{ Map => MutableMap, ListBuffer }
import org.specs._

/**
* Tests for Summingbird's in-memory planner.
*/

object MemoryLaws extends Properties("Memory") {
object MemoryLaws extends Specification {
// This is dangerous, obviously. The Memory platform tested here
// doesn't perform any batching, so the actual time extraction isn't
// needed.
Expand All @@ -37,6 +38,9 @@ object MemoryLaws extends Properties("Memory") {
def apply(t: T) = buf += t
}

def sample[T: Arbitrary]: T = Arbitrary.arbitrary[T].sample.get


def testGraph[T: Manifest: Arbitrary, K: Arbitrary, V: Monoid: Arbitrary: Equiv] =
new TestGraphs[Memory, T, K, V](new Memory)(
() => MutableMap.empty[K, V])(() => new BufferFunc[T])(
Expand All @@ -49,34 +53,40 @@ object MemoryLaws extends Properties("Memory") {
* operation.
*/
def singleStepLaw[T: Manifest: Arbitrary, K: Arbitrary, V: Monoid: Arbitrary: Equiv] =
testGraph[T, K, V].singleStepChecker

property("MemoryPlanner singleStep w/ Int, Int, Set[Int]") = singleStepLaw[Int, Int, Set[Int]]
property("MemoryPlanner singleStep w/ Int, String, List[Int]") = singleStepLaw[Int, String, List[Int]]
property("MemoryPlanner singleStep w/ String, Short, Map[Set[Int], Long]") =
singleStepLaw[String, Short, Map[Set[Int], Long]]
testGraph[T, K, V].singleStepChecker(sample[List[T]], sample[T => List[(K, V)]])

/**
* Tests the in-memory planner against a job with a single flatMap
* operation.
*/
def diamondLaw[T: Manifest: Arbitrary, K: Arbitrary, V: Monoid: Arbitrary: Equiv] =
testGraph[T, K, V].diamondChecker
testGraph[T, K, V].diamondChecker(sample[List[T]], sample[T => List[(K, V)]], sample[T => List[(K, V)]])

property("MemoryPlanner diamond w/ Int, Int, Set[Int]") = diamondLaw[Int, Int, Set[Int]]
property("MemoryPlanner diamond w/ Int, String, List[Int]") = diamondLaw[Int, String, List[Int]]
property("MemoryPlanner diamond w/ String, Short, Map[Set[Int], Long]") =
diamondLaw[String, Short, Map[Set[Int], Long]]

/**
* Tests the in-memory planner by generating arbitrary flatMap and
* service functions.
*/
def leftJoinLaw[T: Manifest: Arbitrary, K: Arbitrary, U: Arbitrary, JoinedU: Arbitrary, V: Monoid: Arbitrary: Equiv] = {
val serviceFn = Arbitrary.arbitrary[K => Option[JoinedU]].sample.get
testGraph[T, K, V].leftJoinChecker[U, JoinedU](serviceFn)(identity)
testGraph[T, K, V].leftJoinChecker[U, JoinedU](serviceFn, identity, sample[List[T]], sample[T => List[(K, U)]], sample[((K, (U, Option[JoinedU]))) => List[(K, V)]])
}

"The Memory Platform" should {
//Set up the job:
"singleStep w/ Int, Int, Set[Int]" in { singleStepLaw[Int, Int, Set[Int]] must be(true) }
"singleStep w/ Int, String, List[Int]" in { singleStepLaw[Int, String, List[Int]] must be(true) }
"singleStep w/ String, Short, Map[Set[Int], Long]" in {singleStepLaw[String, Short, Map[Set[Int], Long]] must be(true) }


"diamond w/ Int, Int, Set[Int]" in { diamondLaw[Int, Int, Set[Int]] must be(true) }
"diamond w/ Int, String, List[Int]" in { diamondLaw[Int, String, List[Int]] must be(true) }
"diamond w/ String, Short, Map[Set[Int], Long]" in { diamondLaw[String, Short, Map[Set[Int], Long]] must be(true) }

"leftJoin w/ Int, Int, String, Long, Set[Int]" in { leftJoinLaw[Int, Int, String, Long, Set[Int]] must be(true) }

}

property("MemoryPlanner leftJoin w/ Int, Int, String, Long, Set[Int]") =
leftJoinLaw[Int, Int, String, Long, Set[Int]]


}

0 comments on commit 2bb1564

Please # to comment.