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

    https://github.com/apache/spark/pull/4588#discussion_r26960440
  
    --- Diff: core/src/test/scala/org/apache/spark/rpc/RpcEnvSuite.scala ---
    @@ -0,0 +1,526 @@
    +/*
    + * 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.rpc
    +
    +import java.util.concurrent.{TimeUnit, CountDownLatch, TimeoutException}
    +
    +import scala.collection.mutable
    +import scala.concurrent.Await
    +import scala.concurrent.duration._
    +import scala.language.postfixOps
    +
    +import org.scalatest.{BeforeAndAfterAll, FunSuite}
    +import org.scalatest.concurrent.Eventually._
    +
    +import org.apache.spark.{SparkException, SparkConf}
    +
    +/**
    + * Common tests for an RpcEnv implementation.
    + */
    +abstract class RpcEnvSuite extends FunSuite with BeforeAndAfterAll {
    +
    +  var env: RpcEnv = _
    +
    +  override def beforeAll(): Unit = {
    +    val conf = new SparkConf()
    +    env = createRpcEnv(conf, "local", 12345)
    +  }
    +
    +  override def afterAll(): Unit = {
    +    if(env != null) {
    +      env.shutdown()
    +    }
    +  }
    +
    +  def createRpcEnv(conf: SparkConf, name: String, port: Int): RpcEnv
    +
    +  test("send a message locally") {
    +    @volatile var message: String = null
    +    val rpcEndpointRef = env.setupEndpoint("send-locally", new RpcEndpoint 
{
    +      override val rpcEnv = env
    +
    +      override def receive = {
    +        case msg: String => message = msg
    +      }
    +    })
    +    rpcEndpointRef.send("hello")
    +    eventually(timeout(5 seconds), interval(10 millis)) {
    +      assert("hello" === message)
    +    }
    +  }
    +
    +  test("send a message remotely") {
    +    @volatile var message: String = null
    +    // Set up a RpcEndpoint using env
    +    env.setupEndpoint("send-remotely", new RpcEndpoint {
    +      override val rpcEnv = env
    +
    +      override def receive = {
    +        case msg: String => message = msg
    +      }
    +    })
    +
    +    val anotherEnv = createRpcEnv(new SparkConf(), "remote" ,13345)
    +    // Use anotherEnv to find out the RpcEndpointRef
    +    val rpcEndpointRef = anotherEnv.setupEndpointRef("local", env.address, 
"send-remotely")
    +    try {
    +      rpcEndpointRef.send("hello")
    +      eventually(timeout(5 seconds), interval(10 millis)) {
    +        assert("hello" === message)
    +      }
    +    } finally {
    +      anotherEnv.shutdown()
    +      anotherEnv.awaitTermination()
    +    }
    +  }
    +
    +  test("send a RpcEndpointRef") {
    +    val endpoint = new RpcEndpoint {
    +      override val rpcEnv = env
    +
    +      override def receiveAndReply(context: RpcCallContext) = {
    +        case "Hello" => context.reply(self)
    +        case "Echo" => context.reply("Echo")
    +      }
    +    }
    +    val rpcEndpointRef = env.setupEndpoint("send-ref", endpoint)
    +
    +    val newRpcEndpointRef = 
rpcEndpointRef.askWithReply[RpcEndpointRef]("Hello")
    +    val reply = newRpcEndpointRef.askWithReply[String]("Echo")
    +    assert("Echo" === reply)
    +  }
    +
    +  test("ask a message locally") {
    +    val rpcEndpointRef = env.setupEndpoint("ask-locally", new RpcEndpoint {
    +      override val rpcEnv = env
    +
    +      override def receiveAndReply(context: RpcCallContext) = {
    +        case msg: String => {
    +          context.reply(msg)
    +        }
    +      }
    +    })
    +    val reply = rpcEndpointRef.askWithReply[String]("hello")
    +    assert("hello" === reply)
    +  }
    +
    +  test("ask a message remotely") {
    +    env.setupEndpoint("ask-remotely", new RpcEndpoint {
    +      override val rpcEnv = env
    +
    +      override def receiveAndReply(context: RpcCallContext) = {
    +        case msg: String => {
    +          context.reply(msg)
    +        }
    +      }
    +    })
    +
    +    val anotherEnv = createRpcEnv(new SparkConf(), "remote", 13345)
    +    // Use anotherEnv to find out the RpcEndpointRef
    +    val rpcEndpointRef = anotherEnv.setupEndpointRef("local", env.address, 
"ask-remotely")
    +    try {
    +      val reply = rpcEndpointRef.askWithReply[String]("hello")
    +      assert("hello" === reply)
    +    } finally {
    +      anotherEnv.shutdown()
    +      anotherEnv.awaitTermination()
    +    }
    +  }
    +
    +  test("ask a message timeout") {
    +    env.setupEndpoint("ask-timeout", new RpcEndpoint {
    +      override val rpcEnv = env
    +
    +      override def receiveAndReply(context: RpcCallContext) = {
    +        case msg: String => {
    +          Thread.sleep(100)
    +          context.reply(msg)
    +        }
    +      }
    +    })
    +
    +    val conf = new SparkConf()
    +    conf.set("spark.akka.retry.wait", "0")
    +    conf.set("spark.akka.num.retries", "1")
    +    val anotherEnv = createRpcEnv(conf, "remote", 13345)
    +    // Use anotherEnv to find out the RpcEndpointRef
    +    val rpcEndpointRef = anotherEnv.setupEndpointRef("local", env.address, 
"ask-timeout")
    +    try {
    +      val e = intercept[Exception] {
    +        rpcEndpointRef.askWithReply[String]("hello", 1 millis)
    +      }
    +      assert(e.isInstanceOf[TimeoutException] || 
e.getCause.isInstanceOf[TimeoutException])
    +    } finally {
    +      anotherEnv.shutdown()
    +      anotherEnv.awaitTermination()
    +    }
    +  }
    +
    +  test("onStart and onStop") {
    +    val stopLatch = new CountDownLatch(1)
    +    val calledMethods = mutable.ArrayBuffer[String]()
    +
    +    val endpoint = new RpcEndpoint {
    +      override val rpcEnv = env
    +
    +      override def onStart(): Unit = {
    +        calledMethods += "start"
    +      }
    +
    +      override def receive = {
    +        case msg: String =>
    +      }
    +
    +      override def onStop(): Unit = {
    +        calledMethods += "stop"
    +        stopLatch.countDown()
    +      }
    +    }
    +    val rpcEndpointRef = env.setupEndpoint("start-stop-test", endpoint)
    +    rpcEndpointRef.send("message")
    --- End diff --
    
    What is this trying to test here?


---
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