Skip to content

Commit 81d670c

Browse files
committed
Adding unit test for straight to disk iterator methods.
1 parent d32992f commit 81d670c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.spark.storage
18+
19+
import org.scalatest.FunSuite
20+
import org.apache.spark.{LocalSparkContext, SparkContext}
21+
22+
class Expander(base:String, count:Int) extends Iterator[String] {
23+
var i = 0;
24+
def next() : String = {
25+
i += 1;
26+
return base + i.toString;
27+
}
28+
def hasNext() : Boolean = i < count;
29+
}
30+
31+
object Expander {
32+
def expand(s:String, i:Int) : Iterator[String] = {
33+
return new Expander(s,i)
34+
}
35+
}
36+
37+
class LargeIteratorSuite extends FunSuite with LocalSparkContext {
38+
39+
val clusterUrl = "local-cluster[1,1,512]"
40+
test("Flatmap iterator") {
41+
sc = new SparkContext(clusterUrl, "mem_test");
42+
val seeds = sc.parallelize( Array(
43+
"This is the first sentence that we will test:",
44+
"This is the second sentence that we will test:",
45+
"This is the third sentence that we will test:"
46+
) );
47+
val out = seeds.flatMap(Expander.expand(_,10000000));
48+
out.map(_ + "...").persist(StorageLevel.DISK_ONLY).saveAsTextFile("./test.out")
49+
}
50+
}

0 commit comments

Comments
 (0)