-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
core/src/test/scala/org/apache/spark/network/netty/BlockClientFactorySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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.network.netty | ||
|
||
import scala.concurrent.{Await, future} | ||
import scala.concurrent.duration._ | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
import org.scalatest.{BeforeAndAfterAll, FunSuite} | ||
|
||
import org.apache.spark.SparkConf | ||
|
||
|
||
class BlockClientFactorySuite extends FunSuite with BeforeAndAfterAll { | ||
|
||
private val conf = new SparkConf | ||
private var server1: BlockServer = _ | ||
private var server2: BlockServer = _ | ||
|
||
override def beforeAll() { | ||
server1 = new BlockServer(new NettyConfig(conf), null) | ||
server2 = new BlockServer(new NettyConfig(conf), null) | ||
} | ||
|
||
override def afterAll() { | ||
if (server1 != null) { | ||
server1.stop() | ||
} | ||
if (server2 != null) { | ||
server2.stop() | ||
} | ||
} | ||
|
||
test("BlockClients created are active and reused") { | ||
val factory = new BlockClientFactory(conf) | ||
val c1 = factory.createClient(server1.hostName, server1.port) | ||
val c2 = factory.createClient(server1.hostName, server1.port) | ||
val c3 = factory.createClient(server2.hostName, server2.port) | ||
assert(c1.isActive) | ||
assert(c3.isActive) | ||
assert(c1 === c2) | ||
assert(c1 !== c3) | ||
factory.stop() | ||
} | ||
|
||
test("never return inactive clients") { | ||
val factory = new BlockClientFactory(conf) | ||
val c1 = factory.createClient(server1.hostName, server1.port) | ||
c1.close() | ||
|
||
// Block until c1 is no longer active | ||
val f = future { | ||
while (c1.isActive) { | ||
Thread.sleep(10) | ||
} | ||
} | ||
Await.result(f, 3 seconds) | ||
assert(!c1.isActive) | ||
|
||
// Create c2, which should be different from c1 | ||
val c2 = factory.createClient(server1.hostName, server1.port) | ||
assert(c1 !== c2) | ||
factory.stop() | ||
} | ||
|
||
test("BlockClients are close when BlockClientFactory is stopped") { | ||
val factory = new BlockClientFactory(conf) | ||
val c1 = factory.createClient(server1.hostName, server1.port) | ||
val c2 = factory.createClient(server2.hostName, server2.port) | ||
assert(c1.isActive) | ||
assert(c2.isActive) | ||
factory.stop() | ||
assert(!c1.isActive) | ||
assert(!c2.isActive) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters