This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 266
Test to illustrate https://github.com/twitter/summingbird/issues/671 #672
Open
pankajroark
wants to merge
7
commits into
develop
Choose a base branch
from
pg/options_break
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4a602fd
Test to illustrate https://github.com/twitter/summingbird/issues/671
pankajroark 86c24c3
Add back sparseEquiv import.
pankajroark 54ef23b
Try to create scalding platform tests for the same issue.
pankajroark 5ab3053
Add tests for named options for scalding platform.
pankajroark 2cada35
Fix scalding named option test.
pankajroark 7422550
More scalding platform named option tests.
pankajroark b502b7b
Fix https://github.com/twitter/summingbird/issues/671
pankajroark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
217 changes: 217 additions & 0 deletions
217
...bird-scalding-test/src/test/scala/com/twitter/summingbird/scalding/NamedOptionsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
/* | ||
Copyright 2013 Twitter, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.twitter.summingbird.scalding | ||
|
||
import cascading.flow.FlowDef | ||
import cascading.pipe.Pipe | ||
import cascading.property.ConfigDef | ||
import cascading.property.ConfigDef.Setter | ||
import cascading.tuple.Fields | ||
import com.twitter.scalding.{Test => TestMode, _} | ||
import com.twitter.summingbird._ | ||
import com.twitter.summingbird.batch.option.Reducers | ||
import com.twitter.summingbird.option.MonoidIsCommutative | ||
import org.scalatest.WordSpec | ||
|
||
/** | ||
* Tests for application of named options. | ||
*/ | ||
class NamedOptionsSpec extends WordSpec { | ||
|
||
private val ReducerKey = "mapred.reduce.tasks" | ||
private val FlatMapNodeName1 = "FM1" | ||
private val FlatMapNodeName2 = "FM2" | ||
private val SummerNodeName1 = "SM1" | ||
private val SummerNodeName2 = "SM2" | ||
|
||
private val IdentitySink = new Sink[Int] { | ||
override def write(incoming: PipeFactory[Int]): PipeFactory[Int] = incoming | ||
} | ||
|
||
implicit def timeExtractor[T <: (Int, _)] = | ||
new TimeExtractor[T] { | ||
override def apply(t: T) = t._1.toLong | ||
} | ||
|
||
def pipeConfig(pipe: Pipe): Map[String, List[String]] = { | ||
val configCollector = new Setter { | ||
var config = Map.empty[String, List[String]] | ||
override def set(key: String, value: String): String = { | ||
if (config.contains(key)) { | ||
config = config.updated(key, value :: config(key)) | ||
} else { | ||
config += key -> List(value) | ||
} | ||
"" | ||
} | ||
override def get(key: String): String = ??? | ||
override def update(key: String, value: String): String = ??? | ||
} | ||
|
||
def recurse(p: Pipe): Unit = { | ||
val cfg = p.getStepConfigDef | ||
if (!cfg.isEmpty) { | ||
cfg.apply(ConfigDef.Mode.REPLACE, configCollector) | ||
} | ||
p.getPrevious.foreach(recurse(_)) | ||
} | ||
|
||
recurse(pipe) | ||
configCollector.config | ||
} | ||
|
||
def verify[T]( | ||
options: Map[String, Options], | ||
expectedReducers: Int)( | ||
jobGen: (Producer[Scalding, (Int, Int)], scalding.Store[Int, Int]) => TailProducer[Scalding, Any]) = { | ||
|
||
val src = Scalding.sourceFromMappable { dr => IterableSource(List.empty[(Int, Int)]) } | ||
val store = TestStore[Int, Int]("store", TestUtil.simpleBatcher, Map.empty[Int, Int], Long.MaxValue) | ||
val job = jobGen(src, store) | ||
val interval = TestUtil.toTimeInterval(1L, Long.MaxValue) | ||
|
||
val scaldingPlatform = Scalding("named options test", options) | ||
val mode: Mode = TestMode(t => (store.sourceToBuffer).get(t)) | ||
|
||
val flowToPipe = scaldingPlatform | ||
.plan(job) | ||
.apply((interval, mode)) | ||
.right | ||
.get | ||
._2 | ||
|
||
val fd = new FlowDef | ||
val typedPipe = flowToPipe.apply((fd, mode)) | ||
def tupleSetter[T] = new TupleSetter[T] { | ||
override def apply(arg: T) = { | ||
val tup = cascading.tuple.Tuple.size(1) | ||
tup.set(0, arg) | ||
tup | ||
} | ||
override def arity = 1 | ||
} | ||
val pipe = typedPipe.toPipe(new Fields("0"))(fd, mode, tupleSetter) | ||
val numReducers = pipeConfig(pipe)(ReducerKey).head.toInt | ||
assert(numReducers === expectedReducers) | ||
} | ||
|
||
"The ScaldingPlatform" should { | ||
"with same setting on multiple names use the one for the node" in { | ||
val fmReducers = 50 | ||
val smReducers = 100 | ||
|
||
val options = Map( | ||
FlatMapNodeName1 -> Options().set(Reducers(fmReducers)), | ||
SummerNodeName1 -> Options().set(Reducers(smReducers))) | ||
|
||
verify(options, smReducers) { (source, store) => | ||
source | ||
.flatMap(Some(_)).name(FlatMapNodeName1) | ||
.sumByKey(store).name(SummerNodeName1) | ||
} | ||
} | ||
|
||
"use named option from the closest node when two names defined one after the other" in { | ||
val smReducers1 = 50 | ||
val smReducers2 = 100 | ||
|
||
val options = Map( | ||
SummerNodeName1 -> Options().set(Reducers(smReducers1)), | ||
SummerNodeName2 -> Options().set(Reducers(smReducers2))) | ||
|
||
verify(options, smReducers1) { (source, store) => | ||
source | ||
.flatMap(Some(_)) | ||
.sumByKey(store).name(SummerNodeName1).name(SummerNodeName2) | ||
} | ||
} | ||
|
||
"use named option from the upstream node if option not defined on current node" in { | ||
val fmReducers1 = 50 | ||
val fmReducers2 = 100 | ||
|
||
val options = Map( | ||
FlatMapNodeName1 -> Options().set(Reducers(fmReducers1)), | ||
FlatMapNodeName2 -> Options().set(Reducers(fmReducers2))) | ||
|
||
verify(options, fmReducers2) { (source, store) => | ||
source | ||
.flatMap(Some(_)).name(FlatMapNodeName1) | ||
.sumByKey(store).name(SummerNodeName1) | ||
.map { case (k, (optV, v)) => k }.name(FlatMapNodeName2) | ||
.write(IdentitySink) | ||
} | ||
} | ||
|
||
"use named option from the upstream node if option not defined on current node, even if upstream node is more than a node apart" in { | ||
val fmReducers1 = 50 | ||
val fmReducers2 = 100 | ||
|
||
val options = Map( | ||
FlatMapNodeName1 -> Options().set(Reducers(fmReducers1)), | ||
FlatMapNodeName2 -> Options().set(Reducers(fmReducers2))) | ||
|
||
verify(options, fmReducers2) { (source, store) => | ||
source | ||
.flatMap(Some(_)).name(FlatMapNodeName1) | ||
.sumByKey(store).name(SummerNodeName1) | ||
.flatMap { case (k, (optV, v)) => Some(k) } | ||
.flatMap { k => List(k, k) }.name(FlatMapNodeName2) | ||
.write(IdentitySink) | ||
} | ||
} | ||
|
||
"use named option from the closest upstream node if same option defined on two upstream nodes" in { | ||
val fmReducers1 = 50 | ||
val fmReducers2 = 100 | ||
|
||
val options = Map( | ||
FlatMapNodeName1 -> Options().set(Reducers(fmReducers1)), | ||
FlatMapNodeName2 -> Options().set(Reducers(fmReducers2))) | ||
|
||
verify(options, fmReducers1) { (source, store) => | ||
source | ||
.flatMap(Some(_)) | ||
.sumByKey(store).name(SummerNodeName1) | ||
.flatMap { case (k, (optV, v)) => Some(k) }.name(FlatMapNodeName1) | ||
.flatMap { k => List(k, k) }.name(FlatMapNodeName2) | ||
.write(IdentitySink) | ||
} | ||
} | ||
|
||
"options propagate backwards" in { | ||
val fmReducers2 = 1000 | ||
|
||
/** | ||
* Here FlatMapNodeName1 is closer to the summer node but doesn't have Reducers property | ||
* defined so it is picked from FlatMapNodeName2. | ||
*/ | ||
val options = Map( | ||
FlatMapNodeName1 -> Options().set(MonoidIsCommutative), | ||
FlatMapNodeName2 -> Options().set(Reducers(fmReducers2))) | ||
|
||
verify(options, fmReducers2) { (source, store) => | ||
source | ||
.flatMap(Some(_)) | ||
.sumByKey(store).name(SummerNodeName1) | ||
.flatMap { case (k, (optV, v)) => Some(k) }.name(FlatMapNodeName1) | ||
.flatMap { k => List(k, k) }.name(FlatMapNodeName2) | ||
.write(IdentitySink) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is T?