Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2931#discussion_r19587466
  
    --- Diff: 
streaming/src/test/scala/org/apache/spark/streaming/rdd/WriteAheadLogBackedBlockRDDSuite.scala
 ---
    @@ -0,0 +1,155 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You 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 org.apache.spark.streaming.rdd
    +
    +import java.io.File
    +
    +import scala.util.Random
    +
    +import com.google.common.io.Files
    +import org.apache.hadoop.conf.Configuration
    +import org.scalatest.{BeforeAndAfterAll, FunSuite}
    +
    +import org.apache.spark.{SparkConf, SparkContext}
    +import org.apache.spark.storage.{BlockId, BlockManager, StorageLevel, 
StreamBlockId}
    +import org.apache.spark.streaming.util.{WriteAheadLogFileSegment, 
WriteAheadLogWriter}
    +
    +class WriteAheadLogBackedBlockRDDSuite extends FunSuite with 
BeforeAndAfterAll {
    +  val conf = new SparkConf()
    +    .setMaster("local[2]")
    +    .setAppName(this.getClass.getSimpleName)
    +  val hadoopConf = new Configuration()
    +
    +  var sparkContext: SparkContext = null
    +  var blockManager: BlockManager = null
    +  var dir: File = null
    +
    +  override def beforeAll(): Unit = {
    +    sparkContext = new SparkContext(conf)
    +    blockManager = sparkContext.env.blockManager
    +    dir = Files.createTempDir()
    +  }
    +
    +  override def afterAll(): Unit = {
    +    // Copied from LocalSparkContext, simpler than to introduced test 
dependencies to core tests.
    +    sparkContext.stop()
    +    dir.delete()
    +    System.clearProperty("spark.driver.port")
    +  }
    +
    +  test("Read data available in block manager and write ahead log") {
    +    testRDD(5, 5)
    +  }
    +
    +  test("Read data available only in block manager, not in write ahead 
log") {
    +    testRDD(5, 0)
    +  }
    +
    +  test("Read data available only in write ahead log, not in block 
manager") {
    +    testRDD(0, 5)
    +  }
    +
    +  test("Read data available only in write ahead log, and test storing in 
block manager") {
    +    testRDD(0, 5, testStoreInBM = true)
    +  }
    +
    +  test("Read data with partially available in block manager, and rest in 
write ahead log") {
    +    testRDD(3, 2)
    +  }
    +
    +  /**
    +   * Test the WriteAheadLogBackedRDD, by writing some partitions of the 
data to block manager
    +   * and the rest to a write ahead log, and then reading reading it all 
back using the RDD.
    +   * It can also test if the partitions that were read from the log were 
again stored in
    +   * block manager.
    +   * @param numPartitionssInBM Number of partitions to write to the Block 
Manager
    +   * @param numPartitionsInWAL Number of partitions to write to the Write 
Ahead Log
    +   * @param testStoreInBM Test whether blocks read from log are stored 
back into block manager
    +   */
    +  private def testRDD(
    +      numPartitionssInBM: Int,
    +      numPartitionsInWAL: Int,
    +      testStoreInBM: Boolean = false
    +    ) {
    +    val numBlocks = numPartitionssInBM + numPartitionsInWAL
    +    val data = Seq.tabulate(numBlocks) { _ => Seq.fill(10) { 
scala.util.Random.nextString(50) } }
    --- End diff --
    
    Nice! Right!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to