Skip to content

Commit

Permalink
Add and update test cases (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjoon-hyun authored and wangyum committed Sep 4, 2018
1 parent 0d78113 commit d1dac1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,24 +412,24 @@ class KryoSerializerSuite extends SparkFunSuite with SharedSparkContext {
assert(!ser2.getAutoReset)
}

test("SPARK-25176: ClassCastException when writing a Map after previously " +
test("SPARK-25176 ClassCastException when writing a Map after previously " +
"reading a Map with different generic type") {
// This test copy from: https://github.com/EsotericSoftware/kryo/issues/384
import java.util
// This test uses the example in https://github.com/EsotericSoftware/kryo/issues/384
import java.util._
val ser = new KryoSerializer(new SparkConf).newInstance().asInstanceOf[KryoSerializerInstance]

class MapHolder {
private val mapOne = new util.HashMap[Int, String]
private val mapOne = new HashMap[Int, String]
private val mapTwo = this.mapOne
}

val serializedMapHolder = ser.serialize(new MapHolder)
ser.deserialize[MapHolder](serializedMapHolder)

val stringMap = new util.HashMap[Int, util.List[String]]
stringMap.put(1, new util.ArrayList[String])
val serializedMap = ser.serialize[util.Map[Int, util.List[String]]](stringMap)
ser.deserialize[util.HashMap[Int, util.List[String]]](serializedMap)
val stringMap = new HashMap[Int, List[String]]
stringMap.put(1, new ArrayList[String])
val serializedMap = ser.serialize[Map[Int, List[String]]](stringMap)
ser.deserialize[HashMap[Int, List[String]]](serializedMap)
}

private def testSerializerInstanceReuse(autoReset: Boolean, referenceTracking: Boolean): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.ml.regression

import scala.util.Random

import org.apache.spark.SparkFunSuite
import org.apache.spark.{SparkConf, SparkFunSuite}
import org.apache.spark.ml.classification.LogisticRegressionSuite._
import org.apache.spark.ml.feature.{Instance, OffsetInstance}
import org.apache.spark.ml.feature.{LabeledPoint, RFormula}
Expand All @@ -29,6 +29,7 @@ import org.apache.spark.ml.util.{DefaultReadWriteTest, MLTest, MLTestingUtils}
import org.apache.spark.ml.util.TestingUtils._
import org.apache.spark.mllib.random._
import org.apache.spark.mllib.util.MLlibTestSparkContext
import org.apache.spark.serializer.KryoSerializer
import org.apache.spark.sql.{DataFrame, Row}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.FloatType
Expand Down Expand Up @@ -1687,6 +1688,14 @@ class GeneralizedLinearRegressionSuite extends MLTest with DefaultReadWriteTest
assert(evalSummary.deviance === summary.deviance)
assert(evalSummary.aic === summary.aic)
}

test("SPARK-23131 Kryo raises StackOverflow during serializing GLR model") {
val conf = new SparkConf(false)
val ser = new KryoSerializer(conf).newInstance()
val trainer = new GeneralizedLinearRegression()
val model = trainer.fit(Seq(Instance(1.0, 1.0, Vectors.dense(1.0, 7.0))).toDF)
ser.serialize[GeneralizedLinearRegressionModel](model)
}
}

object GeneralizedLinearRegressionSuite {
Expand Down

0 comments on commit d1dac1e

Please sign in to comment.