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

    https://github.com/apache/spark/pull/5685#discussion_r29404655
  
    --- Diff: 
core/src/test/scala/org/apache/spark/util/ClosureCleanerSuite2.scala ---
    @@ -0,0 +1,562 @@
    +/*
    + * 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.util
    +
    +import java.io.NotSerializableException
    +
    +import scala.collection.mutable
    +
    +import org.scalatest.{BeforeAndAfterAll, FunSuite, PrivateMethodTester}
    +
    +import org.apache.spark.{SparkContext, SparkException}
    +import org.apache.spark.serializer.SerializerInstance
    +
    +/**
    + * Another test suite for the closure cleaner that is finer-grained.
    + * For tests involving end-to-end Spark jobs, see {{ClosureCleanerSuite}}.
    + */
    +class ClosureCleanerSuite2 extends FunSuite with BeforeAndAfterAll with 
PrivateMethodTester {
    +
    +  // Start a SparkContext so that the closure serializer is accessible
    +  // We do not actually use this explicitly otherwise
    +  private var sc: SparkContext = null
    +  private var closureSerializer: SerializerInstance = null
    +
    +  override def beforeAll(): Unit = {
    +    sc = new SparkContext("local", "test")
    +    closureSerializer = sc.env.closureSerializer.newInstance()
    +  }
    +
    +  override def afterAll(): Unit = {
    +    sc.stop()
    +    sc = null
    +    closureSerializer = null
    +  }
    +
    +  // Some fields and methods to reference in inner closures later
    +  private val someSerializableValue = 1
    +  private val someNonSerializableValue = new NonSerializable
    +  private def someSerializableMethod() = 1
    +  private def someNonSerializableMethod() = new NonSerializable
    +
    +  /** Assert that the given closure is serializable (or not). */
    +  private def assertSerializable(closure: AnyRef, serializable: Boolean): 
Unit = {
    +    if (serializable) {
    +      closureSerializer.serialize(closure)
    +    } else {
    +      intercept[NotSerializableException] {
    +        closureSerializer.serialize(closure)
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Helper method for testing whether closure cleaning works as expected.
    +   * This cleans the given closure twice, with and without transitive 
cleaning.
    +   */
    +  private def testClean(
    --- End diff --
    
    Maybe these should be called `verifyCleaning` or something. Because they 
are really verifying behavior according to what you pass as 
`serializableBefore`/`serializableAfter`. Also it would be good to document 
those parameters... it's not super clear what they mean. 


---
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