|  | 
| 18 | 18 | package org.apache.spark.streaming | 
| 19 | 19 | 
 | 
| 20 | 20 | import scala.collection.{immutable, mutable, Map} | 
|  | 21 | +import scala.reflect.ClassTag | 
| 21 | 22 | import scala.util.Random | 
| 22 | 23 | 
 | 
| 23 |  | -import org.apache.spark.SparkFunSuite | 
|  | 24 | +import org.apache.spark.{SparkConf, SparkFunSuite} | 
|  | 25 | +import org.apache.spark.serializer._ | 
| 24 | 26 | import org.apache.spark.streaming.util.{EmptyStateMap, OpenHashMapBasedStateMap, StateMap} | 
| 25 |  | -import org.apache.spark.util.Utils | 
| 26 | 27 | 
 | 
| 27 | 28 | class StateMapSuite extends SparkFunSuite { | 
| 28 | 29 | 
 | 
|  | 30 | +  private val conf = new SparkConf() | 
|  | 31 | + | 
| 29 | 32 |   test("EmptyStateMap") { | 
| 30 | 33 |     val map = new EmptyStateMap[Int, Int] | 
| 31 | 34 |     intercept[scala.NotImplementedError] { | 
| @@ -267,12 +270,17 @@ class StateMapSuite extends SparkFunSuite { | 
| 267 | 270 |     assertMap(stateMap, refMap.toMap, time, "Final state map does not match reference map") | 
| 268 | 271 |   } | 
| 269 | 272 | 
 | 
| 270 |  | -  private def testSerialization[MapType <: StateMap[Int, Int]]( | 
|  | 273 | +  private def testSerialization[MapType <: StateMap[Int, Int] : ClassTag]( | 
| 271 | 274 |     map: MapType, msg: String): MapType = { | 
| 272 |  | -    val deserMap = Utils.deserialize[MapType]( | 
| 273 |  | -      Utils.serialize(map), Thread.currentThread().getContextClassLoader) | 
| 274 |  | -    assertMap(deserMap, map, 1, msg) | 
| 275 |  | -    deserMap | 
|  | 275 | +    val deserMaps = Array(new JavaSerializer(conf), new KryoSerializer(conf)).map { | 
|  | 276 | +      (serializer: Serializer) => | 
|  | 277 | +        val serializerInstance = serializer.newInstance() | 
|  | 278 | +        val deserMap = serializerInstance.deserialize( | 
|  | 279 | +          serializerInstance.serialize(map), Thread.currentThread().getContextClassLoader) | 
|  | 280 | +        assertMap(deserMap, map, 1, msg) | 
|  | 281 | +        deserMap | 
|  | 282 | +    } | 
|  | 283 | +    deserMaps.head | 
| 276 | 284 |   } | 
| 277 | 285 | 
 | 
| 278 | 286 |   // Assert whether all the data and operations on a state map matches that of a reference state map | 
|  | 
0 commit comments