Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10835#discussion_r50643545
  
    --- Diff: 
core/src/test/scala/org/apache/spark/InternalAccumulatorSuite.scala ---
    @@ -0,0 +1,321 @@
    +/*
    + * 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
    +
    +import scala.collection.mutable.ArrayBuffer
    +
    +import org.apache.spark.scheduler.AccumulableInfo
    +import org.apache.spark.storage.{BlockId, BlockStatus}
    +
    +
    +class InternalAccumulatorSuite extends SparkFunSuite with 
LocalSparkContext {
    +  import InternalAccumulator._
    +  import AccumulatorParam._
    +
    +  test("get param") {
    +    assert(getParam(EXECUTOR_DESERIALIZE_TIME) === LongAccumulatorParam)
    +    assert(getParam(EXECUTOR_RUN_TIME) === LongAccumulatorParam)
    +    assert(getParam(RESULT_SIZE) === LongAccumulatorParam)
    +    assert(getParam(JVM_GC_TIME) === LongAccumulatorParam)
    +    assert(getParam(RESULT_SERIALIZATION_TIME) === LongAccumulatorParam)
    +    assert(getParam(MEMORY_BYTES_SPILLED) === LongAccumulatorParam)
    +    assert(getParam(DISK_BYTES_SPILLED) === LongAccumulatorParam)
    +    assert(getParam(PEAK_EXECUTION_MEMORY) === LongAccumulatorParam)
    +    assert(getParam(UPDATED_BLOCK_STATUSES) === 
UpdatedBlockStatusesAccumulatorParam)
    +    assert(getParam(TEST_ACCUM) === LongAccumulatorParam)
    +    // shuffle read
    +    assert(getParam(shuffleRead.REMOTE_BLOCKS_FETCHED) === 
IntAccumulatorParam)
    +    assert(getParam(shuffleRead.LOCAL_BLOCKS_FETCHED) === 
IntAccumulatorParam)
    +    assert(getParam(shuffleRead.REMOTE_BYTES_READ) === 
LongAccumulatorParam)
    +    assert(getParam(shuffleRead.LOCAL_BYTES_READ) === LongAccumulatorParam)
    +    assert(getParam(shuffleRead.FETCH_WAIT_TIME) === LongAccumulatorParam)
    +    assert(getParam(shuffleRead.RECORDS_READ) === LongAccumulatorParam)
    +    // shuffle write
    +    assert(getParam(shuffleWrite.BYTES_WRITTEN) === LongAccumulatorParam)
    +    assert(getParam(shuffleWrite.RECORDS_WRITTEN) === LongAccumulatorParam)
    +    assert(getParam(shuffleWrite.WRITE_TIME) === LongAccumulatorParam)
    +    // input
    +    assert(getParam(input.READ_METHOD) === StringAccumulatorParam)
    +    assert(getParam(input.RECORDS_READ) === LongAccumulatorParam)
    +    assert(getParam(input.BYTES_READ) === LongAccumulatorParam)
    +    // output
    +    assert(getParam(output.WRITE_METHOD) === StringAccumulatorParam)
    +    assert(getParam(output.RECORDS_WRITTEN) === LongAccumulatorParam)
    +    assert(getParam(output.BYTES_WRITTEN) === LongAccumulatorParam)
    +    // default to Long
    +    assert(getParam(METRICS_PREFIX + "anything") === LongAccumulatorParam)
    +    intercept[AssertionError] {
    +      getParam("something that does not start with the right prefix")
    +    }
    +  }
    +
    +  test("create by name") {
    +    val executorRunTime = create(EXECUTOR_RUN_TIME)
    +    val updatedBlockStatuses = create(UPDATED_BLOCK_STATUSES)
    +    val shuffleRemoteBlocksRead = create(shuffleRead.REMOTE_BLOCKS_FETCHED)
    +    val inputReadMethod = create(input.READ_METHOD)
    +    assert(executorRunTime.name === Some(EXECUTOR_RUN_TIME))
    +    assert(updatedBlockStatuses.name === Some(UPDATED_BLOCK_STATUSES))
    +    assert(shuffleRemoteBlocksRead.name === 
Some(shuffleRead.REMOTE_BLOCKS_FETCHED))
    +    assert(inputReadMethod.name === Some(input.READ_METHOD))
    +    assert(executorRunTime.value.isInstanceOf[Long])
    +    assert(updatedBlockStatuses.value.isInstanceOf[Seq[_]])
    +    // We cannot assert the type of the value directly since the type 
parameter is erased.
    +    // Instead, try casting a `Seq` of expected type and see if it fails 
in run time.
    +    updatedBlockStatuses.setValueAny(Seq.empty[(BlockId, BlockStatus)])
    +    assert(shuffleRemoteBlocksRead.value.isInstanceOf[Int])
    +    assert(inputReadMethod.value.isInstanceOf[String])
    +    // default to Long
    +    val anything = create(METRICS_PREFIX + "anything")
    +    assert(anything.value.isInstanceOf[Long])
    +  }
    +
    +  test("create") {
    +    val accums = create()
    +    val shuffleReadAccums = createShuffleReadAccums()
    +    val shuffleWriteAccums = createShuffleWriteAccums()
    +    val inputAccums = createInputAccums()
    +    val outputAccums = createOutputAccums()
    +    // assert they're all internal
    +    assert(accums.forall(_.isInternal))
    +    assert(shuffleReadAccums.forall(_.isInternal))
    +    assert(shuffleWriteAccums.forall(_.isInternal))
    +    assert(inputAccums.forall(_.isInternal))
    +    assert(outputAccums.forall(_.isInternal))
    +    // assert they all have names
    +    assert(accums.forall(_.name.isDefined))
    +    assert(shuffleReadAccums.forall(_.name.isDefined))
    +    assert(shuffleWriteAccums.forall(_.name.isDefined))
    +    assert(inputAccums.forall(_.name.isDefined))
    +    assert(outputAccums.forall(_.name.isDefined))
    +    // assert `accums` is a strict superset of the others
    +    val accumNames = accums.map(_.name.get).toSet
    +    val shuffleReadAccumNames = shuffleReadAccums.map(_.name.get).toSet
    +    val shuffleWriteAccumNames = shuffleWriteAccums.map(_.name.get).toSet
    +    val inputAccumNames = inputAccums.map(_.name.get).toSet
    +    val outputAccumNames = outputAccums.map(_.name.get).toSet
    +    assert(shuffleReadAccumNames.subsetOf(accumNames))
    +    assert(shuffleWriteAccumNames.subsetOf(accumNames))
    +    assert(inputAccumNames.subsetOf(accumNames))
    +    assert(outputAccumNames.subsetOf(accumNames))
    +  }
    +
    +  test("naming") {
    +    val accums = create()
    +    val shuffleReadAccums = createShuffleReadAccums()
    +    val shuffleWriteAccums = createShuffleWriteAccums()
    +    val inputAccums = createInputAccums()
    +    val outputAccums = createOutputAccums()
    +    // assert that prefixes are properly namespaced
    +    assert(SHUFFLE_READ_METRICS_PREFIX.startsWith(METRICS_PREFIX))
    +    assert(SHUFFLE_WRITE_METRICS_PREFIX.startsWith(METRICS_PREFIX))
    +    assert(INPUT_METRICS_PREFIX.startsWith(METRICS_PREFIX))
    +    assert(OUTPUT_METRICS_PREFIX.startsWith(METRICS_PREFIX))
    +    assert(accums.forall(_.name.get.startsWith(METRICS_PREFIX)))
    +    // assert they all start with the expected prefixes
    +    
assert(shuffleReadAccums.forall(_.name.get.startsWith(SHUFFLE_READ_METRICS_PREFIX)))
    +    
assert(shuffleWriteAccums.forall(_.name.get.startsWith(SHUFFLE_WRITE_METRICS_PREFIX)))
    +    assert(inputAccums.forall(_.name.get.startsWith(INPUT_METRICS_PREFIX)))
    +    
assert(outputAccums.forall(_.name.get.startsWith(OUTPUT_METRICS_PREFIX)))
    +  }
    +
    +  test("internal accumulators in TaskContext") {
    +    sc = new SparkContext("local", "test")
    --- End diff --
    
    This test doesn't use `SparkContext`?


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to