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
18package org.apache.spark
19
20import org.scalatest.concurrent.Timeouts._
21import org.scalatest.time.{Millis, Span}
22
23class UnpersistSuite extends SparkFunSuite with LocalSparkContext {
24  test("unpersist RDD") {
25    sc = new SparkContext("local", "test")
26    val rdd = sc.makeRDD(Array(1, 2, 3, 4), 2).cache()
27    rdd.count
28    assert(sc.persistentRdds.isEmpty === false)
29    rdd.unpersist()
30    assert(sc.persistentRdds.isEmpty === true)
31
32    failAfter(Span(3000, Millis)) {
33      try {
34        while (! sc.getRDDStorageInfo.isEmpty) {
35          Thread.sleep(200)
36        }
37      } catch {
38        case _: Throwable => Thread.sleep(10)
39          // Do nothing. We might see exceptions because block manager
40          // is racing this thread to remove entries from the driver.
41      }
42    }
43    assert(sc.getRDDStorageInfo.isEmpty === true)
44  }
45}
46