-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- improve NettyFuture in when it comes to resolved Futures - add NettyFuture Spec
- Loading branch information
Showing
10 changed files
with
121 additions
and
33 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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
src/test/scala/com/github/andyglow/websocket/util/NettyFutureSpec.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,57 @@ | ||
package com.github.andyglow.websocket.util | ||
|
||
import io.netty.channel.nio.NioEventLoopGroup | ||
import io.netty.util.concurrent.EventExecutorGroup | ||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.OptionValues._ | ||
import org.scalatest.TryValues._ | ||
import org.scalatest.matchers.should.Matchers._ | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.duration._ | ||
import com.github.andyglow.websocket.testserver.PlatformDependent._ | ||
|
||
class NettyFutureSpec extends AnyWordSpec with BeforeAndAfterAll { | ||
|
||
private var executors: EventExecutorGroup = _ | ||
|
||
override def beforeAll(): Unit = { | ||
executors = new NioEventLoopGroup() | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
executors.shutdownGracefully().syncUninterruptibly() | ||
() | ||
} | ||
|
||
"NettyFuture" should { | ||
|
||
"handled resolved successful futures" in { | ||
val fut = NettyFuture(executors.submit(callable(() => "foo")).await()) | ||
fut.value.isDefined shouldBe true | ||
fut.value.value.isSuccess shouldBe true | ||
fut.value.value.get shouldBe "foo" | ||
} | ||
|
||
"handled un-resolved successful futures" in { | ||
val fut = NettyFuture(executors.submit(callable(() => "foo"))) | ||
val v = Await.result(fut, 1.second) | ||
v shouldBe "foo" | ||
} | ||
|
||
"handled resolved failed futures" in { | ||
val fut = NettyFuture(executors.submit(callable[String](() => throw new IllegalStateException("err"))).await()) | ||
fut.value.isDefined shouldBe true | ||
fut.value.value.isSuccess shouldBe false | ||
fut.value.value.failure.exception shouldBe a [IllegalStateException] | ||
fut.value.value.failure.exception.getMessage shouldBe "err" | ||
} | ||
|
||
"handled un-resolved failed futures" in { | ||
val fut = NettyFuture(executors.submit(callable[String](() => throw new IllegalStateException("err")))) | ||
val v = the [IllegalStateException] thrownBy { Await.result(fut, 1.second) } | ||
v.getMessage shouldBe "err" | ||
} | ||
} | ||
} |