Skip to content

Commit

Permalink
Modified test
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak committed Dec 18, 2015
1 parent d3fc82d commit 080e983
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 1 addition & 4 deletions mllib/src/main/scala/org/apache/spark/ml/param/params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,7 @@ final class ParamMap private[ml] (private val map: mutable.Map[Param[Any], Any])
// returns the instance of collections.Map, not mutable.Map.
// Otherwise, we get ClassCastException.
// Not using filterKeys also avoid SI-6654
val filtered = map.filter {
case (k, _) =>
k.parent == parent.uid
}
val filtered = map.filter { case (k, _) => k.parent == parent.uid }
new ParamMap(filtered)
}

Expand Down
21 changes: 19 additions & 2 deletions mllib/src/test/scala/org/apache/spark/ml/param/ParamsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.ml.param

import java.io.{ByteArrayOutputStream, NotSerializableException, ObjectOutputStream}

import org.apache.spark.SparkFunSuite
import org.apache.spark.ml.util.MyParams
import org.apache.spark.mllib.linalg.{Vector, Vectors}
Expand Down Expand Up @@ -367,8 +369,23 @@ class ParamsSuite extends SparkFunSuite {
assert(p.parent === params1.uid)
}

// Following assertion is to avoid SI-6654
assert(filteredParamMap.isInstanceOf[Serializable])
// At the previous implementation of ParamMap#filter,
// mutable.Map#filterKeys was used internally but
// the return type of the method is not serializable (see SI-6654).
// Now mutable.Map#filter is used instead of filterKeys and the return type is serializable.
// So let's ensure serializability.
val objOut = new ObjectOutputStream(new ByteArrayOutputStream())
try {
objOut.writeObject(filteredParamMap)
} catch {
case _: NotSerializableException =>
fail("The field of ParamMap 'map' may not be serializable. " +
"See SI-6654 and the implementation of ParamMap#filter")
case e: Exception =>
fail(s"Exception was thrown unexpectedly during the serializability test: ${e.getMessage}")
} finally {
objOut.close()
}
}
}

Expand Down

0 comments on commit 080e983

Please sign in to comment.