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

    https://github.com/apache/spark/pull/7753#discussion_r45925385
  
    --- Diff: 
core/src/test/scala/org/apache/spark/ui/memory/MemoryListenerSuite.scala ---
    @@ -0,0 +1,258 @@
    +/*
    + * 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.ui.memory
    +
    +import org.apache.spark._
    +import org.apache.spark.executor._
    +import org.apache.spark.scheduler._
    +import org.apache.spark.scheduler.cluster._
    +
    +class MemoryListenerSuite extends SparkFunSuite with LocalSparkContext {
    +  test("test HashMap size for MemoryListener") {
    +    val listener = new MemoryListener
    +    val execId1 = "exec-1"
    +    val execId2 = "exec-2"
    +
    +    (1 to 2).foreach { i =>
    +      
listener.onStageSubmitted(MemoryListenerSuite.createStageStartEvent(i))
    +      listener.onStageCompleted(MemoryListenerSuite.createStageEndEvent(i))
    +    }
    +    // stages are all completed, no activeStages now
    +    assert(listener.activeStagesToMem.isEmpty)
    +
    +    
listener.onExecutorMetricsUpdate(MemoryListenerSuite.createExecutorMetricsUpdateEvent(
    +      execId1, new ExecutorMetrics))
    +    // ExecutorMetrics is not related with Stages directly
    +    assert(listener.activeStagesToMem.isEmpty)
    +
    +    listener.onStageSubmitted(MemoryListenerSuite.createStageStartEvent(3))
    +    
listener.onExecutorMetricsUpdate(MemoryListenerSuite.createExecutorMetricsUpdateEvent(
    +      execId2, new ExecutorMetrics))
    +    // totally 2 executors updated their metrics
    +    assert(listener.activeExecutorIdToMem.size === 2)
    +    assert(listener.activeStagesToMem.size === 1)
    +    listener.onStageCompleted(MemoryListenerSuite.createStageEndEvent(3))
    +
    +    assert(listener.activeStagesToMem.isEmpty)
    +    assert(listener.completedStagesToMem.size === 3)
    +    assert(listener.activeExecutorIdToMem.size === 
listener.latestExecIdToExecMetrics.size)
    +    assert(listener.removedExecutorIdToMem.isEmpty)
    +  }
    +
    +  test("test first stage with no executor metrics update") {
    +    val listener = new MemoryListener
    +    val execId1 = "exec-1"
    +
    +    listener.onExecutorAdded(
    +      SparkListenerExecutorAdded(0L, execId1, new ExecutorInfo("host1", 1, 
Map.empty)))
    +
    +    // stage 1, no metrics update
    +    listener.onStageSubmitted(MemoryListenerSuite.createStageStartEvent(1))
    +    listener.onStageCompleted(MemoryListenerSuite.createStageEndEvent(1))
    +
    +    // stage 2, with one metrics update
    +    listener.onStageSubmitted(MemoryListenerSuite.createStageStartEvent(2))
    +    val execMetrics = MemoryListenerSuite.createExecutorMetrics("host-1", 
0L, 20, 10)
    +    
listener.onExecutorMetricsUpdate(MemoryListenerSuite.createExecutorMetricsUpdateEvent(
    +      execId1, execMetrics))
    +    listener.onStageCompleted(MemoryListenerSuite.createStageEndEvent(2))
    +
    +    val mapForStage1 = listener.completedStagesToMem.get((1, 0)).get
    +    // no metrics for stage 1 since no metrics update for stage 1
    +    assert(mapForStage1.get(execId1).get.transportInfo === None)
    +    val mapForStage2 = listener.completedStagesToMem.get((2, 0)).get
    +    assert(mapForStage2.size === 1)
    +    val memInfo = mapForStage2.get(execId1).get
    +    assert(memInfo.transportInfo.isDefined)
    +    val transMetrics = memInfo.transportInfo.get
    +    assert((20, 10, MemTime(20, 0), MemTime(10, 0)) === 
(transMetrics.onHeapSize,
    +      transMetrics.offHeapSize, transMetrics.peakOnHeapSizeTime, 
transMetrics.peakOffHeapSizeTime))
    --- End diff --
    
    or since you do a similar assert a lot, use a helper method which takes the 
4 expected values and a `transMetrics`, and does the 4 asserts.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to