Skip to content

Commit

Permalink
Make WrappedMutableMapBase extend Serializable (typelevel#2784)
Browse files Browse the repository at this point in the history
We are running into Spark `Task not serializable` issues when a closure
that executes on a Spark executor node involves a `Map` that is created
via running `foldMap` on a `List`. This commit makes the
`WrappedMutableMap` hierarchy extend `Serializable` and chex that the
cerealization works (this test failed before extending `Serializable`).
  • Loading branch information
ceedubs authored and rossabaker committed May 26, 2019
1 parent 5d9fb7f commit 8822980
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package compat

import scala.collection.mutable

abstract private[kernel] class WrappedMutableMapBase[K, V](m: mutable.Map[K, V]) extends Map[K, V] {
abstract private[kernel] class WrappedMutableMapBase[K, V](m: mutable.Map[K, V]) extends Map[K, V] with Serializable {
def +[V2 >: V](kv: (K, V2)): Map[K, V2] = m.toMap + kv
def -(key: K): Map[K, V] = m.toMap - key
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package compat

import scala.collection.mutable

abstract private[kernel] class WrappedMutableMapBase[K, V](m: mutable.Map[K, V]) extends Map[K, V] {
abstract private[kernel] class WrappedMutableMapBase[K, V](m: mutable.Map[K, V]) extends Map[K, V] with Serializable {
def updated[V2 >: V](key: K, value: V2): Map[K, V2] = m.toMap + ((key, value))
def remove(key: K): Map[K, V] = m.toMap - key
}
6 changes: 6 additions & 0 deletions tests/src/test/scala/cats/tests/MapSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import cats.laws.discipline.{
}
import cats.laws.discipline.arbitrary._
import cats.arrow.Compose
import cats.kernel.instances.StaticMethods.wrapMutableMap

class MapSuite extends CatsSuite {
implicit val iso = SemigroupalTests.Isomorphisms.invariant[Map[Int, ?]]
Expand Down Expand Up @@ -38,4 +39,9 @@ class MapSuite extends CatsSuite {
map.show should ===(implicitly[Show[Map[Int, String]]].show(map))
}
}

{
val m = wrapMutableMap(scala.collection.mutable.Map(1 -> "one", 2 -> "two"))
checkAll("WrappedMutableMap", SerializableTests.serializable(m))
}
}

0 comments on commit 8822980

Please sign in to comment.