spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srinathshankar <...@git.apache.org>
Subject [GitHub] spark pull request #15043: [SPARK-17491] Close serialization stream to fix w...
Date Thu, 15 Sep 2016 21:15:08 GMT
Github user srinathshankar commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15043#discussion_r79060355
  
    --- Diff: core/src/test/scala/org/apache/spark/storage/PartiallySerializedBlockSuite.scala
---
    @@ -0,0 +1,215 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.storage
    +
    +import java.nio.ByteBuffer
    +
    +import scala.reflect.ClassTag
    +
    +import org.mockito.Mockito
    +import org.mockito.Mockito.atLeastOnce
    +import org.mockito.invocation.InvocationOnMock
    +import org.mockito.stubbing.Answer
    +import org.scalatest.{BeforeAndAfterEach, PrivateMethodTester}
    +
    +import org.apache.spark.{SparkConf, SparkFunSuite, TaskContext, TaskContextImpl}
    +import org.apache.spark.memory.MemoryMode
    +import org.apache.spark.serializer.{JavaSerializer, SerializationStream, SerializerManager}
    +import org.apache.spark.storage.memory.{MemoryStore, PartiallySerializedBlock, RedirectableOutputStream}
    +import org.apache.spark.util.{ByteBufferInputStream, ByteBufferOutputStream}
    +import org.apache.spark.util.io.{ChunkedByteBuffer, ChunkedByteBufferOutputStream}
    +
    +class PartiallySerializedBlockSuite
    +    extends SparkFunSuite
    +    with BeforeAndAfterEach
    +    with PrivateMethodTester {
    +
    +  private val blockId = new TestBlockId("test")
    +  private val conf = new SparkConf()
    +  private val memoryStore = Mockito.mock(classOf[MemoryStore], Mockito.RETURNS_SMART_NULLS)
    +  private val serializerManager = new SerializerManager(new JavaSerializer(conf), conf)
    +
    +  private val getSerializationStream = PrivateMethod[SerializationStream]('serializationStream)
    +  private val getRedirectableOutputStream =
    +    PrivateMethod[RedirectableOutputStream]('redirectableOutputStream)
    +
    +  override protected def beforeEach(): Unit = {
    +    super.beforeEach()
    +    Mockito.reset(memoryStore)
    +  }
    +
    +  private def partiallyUnroll[T: ClassTag](
    +      iter: Iterator[T],
    +      numItemsToBuffer: Int): PartiallySerializedBlock[T] = {
    +
    +    val bbos: ChunkedByteBufferOutputStream = {
    +      val spy = Mockito.spy(new ChunkedByteBufferOutputStream(128, ByteBuffer.allocate))
    +      Mockito.doAnswer(new Answer[ChunkedByteBuffer] {
    +        override def answer(invocationOnMock: InvocationOnMock): ChunkedByteBuffer =
{
    +          Mockito.spy(invocationOnMock.callRealMethod().asInstanceOf[ChunkedByteBuffer])
    +        }
    +      }).when(spy).toChunkedByteBuffer
    +      spy
    +    }
    +
    +    val serializer = serializerManager.getSerializer(implicitly[ClassTag[T]]).newInstance()
    +    val redirectableOutputStream = Mockito.spy(new RedirectableOutputStream)
    +    redirectableOutputStream.setOutputStream(bbos)
    +    val serializationStream = Mockito.spy(serializer.serializeStream(redirectableOutputStream))
    +
    +    (1 to numItemsToBuffer).foreach { _ =>
    +      assert(iter.hasNext)
    +      serializationStream.writeObject[T](iter.next())
    +    }
    +
    +    val unrollMemory = bbos.size
    +    new PartiallySerializedBlock[T](
    +      memoryStore,
    +      serializerManager,
    +      blockId,
    +      serializationStream = serializationStream,
    +      redirectableOutputStream,
    +      unrollMemory = unrollMemory,
    +      memoryMode = MemoryMode.ON_HEAP,
    --- End diff --
    
    WHat happens if the memory mode is off_heap. Is that relevant ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message