diff options
author | James Iry <jamesiry@gmail.com> | 2013-11-12 15:57:53 -0800 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-11-12 15:57:53 -0800 |
commit | 8bed4a8b2211f8c6d84ae66ec95e71d3485162a9 (patch) | |
tree | 22c96933c8b30cc49bca1eee39e449cd9d1be190 | |
parent | 5cef951d0d230cfecd1138a0cc18643052437100 (diff) | |
parent | 1ca329e7f9795ae8256f010b94742417db6d4a55 (diff) | |
download | scala-8bed4a8b2211f8c6d84ae66ec95e71d3485162a9.tar.gz scala-8bed4a8b2211f8c6d84ae66ec95e71d3485162a9.tar.bz2 scala-8bed4a8b2211f8c6d84ae66ec95e71d3485162a9.zip |
Merge pull request #3121 from rjfwhite/SI-7568
SI-7568 Adding Serializable to ResizableArrayAccess inner class
-rw-r--r-- | src/library/scala/collection/mutable/PriorityQueue.scala | 2 | ||||
-rw-r--r-- | test/junit/scala/collection/PriorityQueueTest.scala | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index 0220d33628..b949bec48a 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -43,7 +43,7 @@ class PriorityQueue[A](implicit val ord: Ordering[A]) { import ord._ - private class ResizableArrayAccess[A] extends AbstractSeq[A] with ResizableArray[A] { + private class ResizableArrayAccess[A] extends AbstractSeq[A] with ResizableArray[A] with Serializable { def p_size0 = size0 def p_size0_=(s: Int) = size0 = s def p_array = array diff --git a/test/junit/scala/collection/PriorityQueueTest.scala b/test/junit/scala/collection/PriorityQueueTest.scala new file mode 100644 index 0000000000..a14f1bf4c8 --- /dev/null +++ b/test/junit/scala/collection/PriorityQueueTest.scala @@ -0,0 +1,32 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.collection.mutable +import java.io.{ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream} + +@RunWith(classOf[JUnit4]) +/* Test for SI-7568 */ +class PriorityQueueTest { + val priorityQueue = new mutable.PriorityQueue[Int]() + val elements = List.fill(1000)(scala.util.Random.nextInt(Int.MaxValue)) + priorityQueue.enqueue(elements :_*) + + @Test + def canSerialize() { + val outputStream = new ByteArrayOutputStream() + new ObjectOutputStream(outputStream).writeObject(priorityQueue) + } + + @Test + def maintainsStateWhenDeserialized() { + val outputStream = new ByteArrayOutputStream() + new ObjectOutputStream(outputStream).writeObject(priorityQueue) + val bytes = outputStream.toByteArray + + val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] + assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) + } +} |