Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement streaming via Reactive Streams API:
- Add a streaming type parameter to Action which is either NoStream or Streaming[+T] with an element type T. - Return the proper streaming types for collection-valued queries. - Remove `synchronized` blocks for synchronous action contexts. Enforcing a happens-before relationship through volatile reads and writes should be enough. - Add dependencies for Reactive Streams to the build. - Add TestNG and related dependencies required for running the Reactive Streams TCK to the build. Tests in ActionTest.testStreaming and reactive-streams-tests.
- Loading branch information
Showing
26 changed files
with
738 additions
and
203 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > | ||
|
||
<suite name="ReactiveStreams" verbose="0" > | ||
<test name="ReactiveStreams"> | ||
<classes> | ||
<class name="scala.slick.test.stream.JdbcPublisherTest"/> | ||
<class name="scala.slick.test.stream.HeapPublisherTest"/> | ||
</classes> | ||
</test> | ||
|
||
<listeners> | ||
<listener class-name="scala.slick.test.stream.TestNGConsoleListener" /> | ||
</listeners> | ||
</suite> |
15 changes: 15 additions & 0 deletions
15
reactive-streams-tests/src/test/scala/scala/slick/test/stream/HeapPublisherTest.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,15 @@ | ||
package scala.slick.test.stream | ||
|
||
import org.testng.annotations.{AfterClass, BeforeClass} | ||
|
||
import scala.slick.memory.MemoryDriver | ||
|
||
class HeapPublisherTest extends RelationalPublisherTest[MemoryDriver](MemoryDriver) { | ||
import driver.api._ | ||
|
||
@BeforeClass def setUpDB: Unit = | ||
db = Database() | ||
|
||
@AfterClass def tearDownDB: Unit = | ||
db.close() | ||
} |
15 changes: 15 additions & 0 deletions
15
reactive-streams-tests/src/test/scala/scala/slick/test/stream/JdbcPublisherTest.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,15 @@ | ||
package scala.slick.test.stream | ||
|
||
import org.testng.annotations.{AfterClass, BeforeClass} | ||
|
||
import scala.slick.driver.{H2Driver, JdbcProfile} | ||
|
||
class JdbcPublisherTest extends RelationalPublisherTest[JdbcProfile](H2Driver) { | ||
import driver.api._ | ||
|
||
@BeforeClass def setUpDB: Unit = | ||
db = Database.forURL("jdbc:h2:mem:DatabasePublisherTest", driver = "org.h2.Driver") | ||
|
||
@AfterClass def tearDownDB: Unit = | ||
db.close() | ||
} |
42 changes: 42 additions & 0 deletions
42
reactive-streams-tests/src/test/scala/scala/slick/test/stream/RelationalPublisherTest.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,42 @@ | ||
package scala.slick.test.stream | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
import org.reactivestreams._ | ||
import org.reactivestreams.tck._ | ||
import org.testng.annotations.{AfterClass, BeforeClass} | ||
|
||
import scala.slick.profile.RelationalProfile | ||
|
||
abstract class RelationalPublisherTest[P <: RelationalProfile](val driver: P) extends PublisherVerification[Int](new TestEnvironment(300L), 1000L) { | ||
import driver.api._ | ||
|
||
var db: Database = _ | ||
val entityNum = new AtomicInteger() | ||
|
||
def createPublisher(elements: Long) = { | ||
val tableName = "data_" + elements + "_" + entityNum.incrementAndGet() | ||
class Data(tag: Tag) extends Table[Int](tag, tableName) { | ||
def id = column[Int]("id") | ||
def * = id | ||
} | ||
val data = TableQuery[Data] | ||
val a = data.schema.create >> (data ++= Range.apply(0, elements.toInt)) >> data.sortBy(_.id).map(_.id).result | ||
db.stream(a.withPinnedSession) | ||
} | ||
|
||
def createErrorStatePublisher = { | ||
val p = createPublisher(0) | ||
p.subscribe(new Subscriber[Int] { | ||
def onSubscribe(s: Subscription): Unit = s.cancel | ||
def onComplete(): Unit = () | ||
def onError(t: Throwable): Unit = () | ||
def onNext(t: Int): Unit = () | ||
}) | ||
p | ||
} | ||
|
||
override def maxElementsFromPublisher = 73L | ||
|
||
override def boundedDepthOfOnNextAndRequestRecursion = 1 | ||
} |
38 changes: 38 additions & 0 deletions
38
reactive-streams-tests/src/test/scala/scala/slick/test/stream/TestNGConsoleListener.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,38 @@ | ||
package scala.slick.test.stream | ||
|
||
import org.testng.{ITestResult, TestListenerAdapter} | ||
|
||
import scala.slick.util.GlobalConfig | ||
|
||
class TestNGConsoleListener extends TestListenerAdapter { | ||
val (normal, yellow, blue, cyan, red) = | ||
if(GlobalConfig.ansiDump) ("\u001B[0m", "\u001B[33m", "\u001B[34m", "\u001B[36m", "\u001B[31m") | ||
else ("", "", "", "", "") | ||
|
||
override def onTestFailure(tr: ITestResult): Unit = { | ||
printError(tr, tr.getThrowable, "failed", red) | ||
} | ||
|
||
override def onTestSuccess(tr: ITestResult): Unit = { | ||
printError(tr, null, "succeeded", cyan) | ||
} | ||
|
||
override def onTestSkipped(tr: ITestResult): Unit = { | ||
printError(tr, null, "skipped", blue) | ||
} | ||
|
||
def printError(tr: ITestResult, t: Throwable, msg: String, highlight: String): Unit = { | ||
val cln = tr.getTestClass.getName | ||
val sep = cln.lastIndexOf('.') | ||
val cln2 = if(sep == -1) (yellow + cln) else cln.substring(0, sep+1) + yellow + cln.substring(sep+1) | ||
val mn = tr.getMethod.getMethodName | ||
val param = tr.getParameters.map(_.toString).mkString(",") | ||
val param2 = if(param == "") "" else s"[$yellow$param$normal]" | ||
print(s"Test $cln2$normal.$highlight$mn$normal$param2 $msg") | ||
if(t eq null) println() | ||
else { | ||
print(": ") | ||
t.printStackTrace(System.out) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.