Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
fail-fast: false
matrix:
java: [11, 17, 21]
scala: [2.13.18, 3.3.7]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -27,4 +28,4 @@ jobs:
java-version: ${{ matrix.java }}
- uses: sbt/setup-sbt@v1
- name: Build and Test
run: sbt test
run: sbt ++${{ matrix.scala }} test
20 changes: 16 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ lazy val common =
coreProject("common")
.settings(
description := "Common Libraries and Utilities",
libraryDependencies ++= Seq(slf4j_api, logback, slf4j_log4j12, scala_xml, scala_parser, scalamock)
libraryDependencies ++= Seq(slf4j_api, logback, slf4j_log4j12, scala_xml, scala_parser, scalamock, mockito_scalatest(scalaVersion.value)),
Test / unmanagedSourceDirectories += {
(Test / sourceDirectory).value / ("scala-" + scalaBinaryVersion.value)
}
)

lazy val actor =
coreProject("actor")
.dependsOn(common)
.settings(
description := "Simple Actor",
Test / parallelExecution := false
Test / parallelExecution := false,
Test / unmanagedSourceDirectories += {
(Test / sourceDirectory).value / ("scala-" + scalaBinaryVersion.value)
}
)

lazy val markdown =
Expand Down Expand Up @@ -102,7 +108,10 @@ lazy val util =
htmlparser,
xerces,
json4s_native,
)
),
Test / unmanagedSourceDirectories += {
(Test / sourceDirectory).value / ("scala-" + scalaBinaryVersion.value)
}
)

// Web Projects
Expand All @@ -115,7 +124,10 @@ lazy val testkit =
.dependsOn(util)
.settings(
description := "Testkit for Webkit Library",
libraryDependencies ++= Seq(commons_httpclient, servlet_api, json4s_native, json4s_xml)
libraryDependencies ++= Seq(commons_httpclient, servlet_api, json4s_native, json4s_xml),
Test / unmanagedSourceDirectories += {
(Test / sourceDirectory).value / ("scala-" + scalaBinaryVersion.value)
}
)

lazy val webkit =
Expand Down
84 changes: 84 additions & 0 deletions core/actor/src/test/scala-3/net/liftweb/actor/ActorSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2011 WorldWide Conferencing, LLC
*
* Licensed 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 net.liftweb
package actor

import org.specs2.mutable.Specification
import scala.concurrent.duration._
import common._


/**
* Systems under specification for Lift Actor.
*/
class ActorSpec extends Specification {
"Actor Specification".title
sequential

"A Scala Actor" should {
"support common features" in commonFeatures(new MyScalaActor)
}

private def commonFeatures(actor: LiftActor) = {
sequential

"allow setting and getting of a value" in {
val a = actor
a ! Set(33)
a !? Get()
Thread.sleep(100)
(a.!?(50, Get())) must beEqualTo(Full(Answer(33)))
}

"allow setting and getting of a value with subclass of Get()" in {
val a = actor
a ! Set(33)
a ! new FunnyGet()
Thread.sleep(100)
(a.!?(50L, new FunnyGet())) must beEqualTo(Full(Answer(33)))
}

"allow adding of a value" in {
val a = actor
a ! Set(33)
(a !< Add(44)).get(500) must beEqualTo(Full(Answer(77)))
}

"allow subtracting of a value" in {
val a = actor
a ! Set(33)
(a !< Sub(11)).get(500) must beEqualTo(Full(Answer(22)))
}

"properly timeout" in {
val a = actor
Thread.sleep(100)
(a !< Set(33)).get(50) must beEqualTo(Empty)
}
}

}


case class Add(num: Int)
case class Sub(num: Int)
case class Set(num: Int)

case class Get()
class FunnyGet() extends Get()

case class Answer(num: Int)
145 changes: 145 additions & 0 deletions core/actor/src/test/scala-3/net/liftweb/actor/LAFutureSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package net.liftweb.actor

import net.liftweb.common.{Box, Failure, Full}
import org.specs2.mutable.Specification
import java.util.concurrent.atomic.AtomicBoolean

class LAFutureSpec extends Specification {
sequential
val timeout = 20000L
LAScheduler

"LAFuture" should {
val futureSpecScheduler = new LAScheduler {
override def execute(f: ()=>Unit): Unit = f()
}

"map to failing future if transforming function throws an Exception" in {
val future = LAFuture(() => 1, futureSpecScheduler)
def tranformThrowingException(input: Int) = {
throw new Exception("fail")
}

val transformedFuture = future.map(tranformThrowingException)

var notifiedAboutFailure: Boolean = false
transformedFuture.onFail { _ =>
notifiedAboutFailure = true
}

transformedFuture.get(timeout)
notifiedAboutFailure must beTrue
}

"flatMap to failing future if transforming function throws an Exception" in {
val future = LAFuture(() => 1, futureSpecScheduler)
def tranformThrowingException(input: Int): LAFuture[Int] = {
throw new Exception("fail")
}

val transformedFuture = future.flatMap(tranformThrowingException)

var notifiedAboutFailure: Boolean = false
transformedFuture.onFail { _ =>
notifiedAboutFailure = true
}

transformedFuture.get(timeout)
notifiedAboutFailure must beTrue
}

"return original Failure after timeout" in {
val future = new LAFuture()
val givenFailure = Failure("fooFailure")
LAScheduler.execute { () =>
Thread.sleep(500)
future.fail(givenFailure)
}

val result = future.get(timeout)

result must beEqualTo(givenFailure)
}

"when collecting results with LAFuture.collect" in {
"collect one future result" in {
val givenOneResult = 123
val one = LAFuture(() => givenOneResult)
LAFuture.collect(one).get(timeout) must beEqualTo(List(givenOneResult))
}

"collect more future results in correct order" in {
val givenOneResult = 123
val givenTwoResult = 234
val one = LAFuture(() => givenOneResult)
val two = LAFuture(() => givenTwoResult)
LAFuture.collect(one, two).get(timeout) must beEqualTo(List(givenOneResult, givenTwoResult))
}

"collect empty list immediately" in {
val collectResult = LAFuture.collect(Nil: _*)
collectResult.isSatisfied must beTrue
collectResult.get(timeout) must beEqualTo(Nil)
}

"report a failed LAFuture as a failure for the overall future" in {
val one: LAFuture[Int] = new LAFuture
val two: LAFuture[Int] = LAFuture(() => 5)

one.fail(Failure("boom boom boom!"))

val collectResult = LAFuture.collect(one, two)
collectResult.get(timeout) must beEqualTo(Failure("boom boom boom!"))
}
}

"when collecting Boxed results with collectAll" in {
"collectAll collects an EmptyBox immediately" in {
val one: LAFuture[Box[Int]] = LAFuture(() => { Failure("whoops"): Box[Int] })
val two: LAFuture[Box[Int]] = LAFuture(() => { Thread.sleep(10000); Full(1) })

val collectResult = LAFuture.collectAll(one, two)
collectResult.get(5000) must beEqualTo(Failure("whoops"))
}

"collectAll collects a set of Fulls" in {
val one: LAFuture[Box[Int]] = LAFuture(() => Full(1): Box[Int])
val two: LAFuture[Box[Int]] = LAFuture(() => Full(2): Box[Int])
val three: LAFuture[Box[Int]] = LAFuture(() => Full(3): Box[Int])

val collectResult = LAFuture.collectAll(one, two, three)
collectResult.get(timeout) should beLike {
case Full(Full(results)) =>
results should contain(allOf(1, 2, 3))
}
}

"collectAll reports a failed LAFuture as a failure for the overall future" in {
val one: LAFuture[Box[Int]] = new LAFuture
val two: LAFuture[Box[Int]] = LAFuture(() => Full(5): Box[Int])

one.fail(Failure("boom boom boom!"))

val collectResult = LAFuture.collectAll(one, two)
collectResult.get(timeout) must beEqualTo(Failure("boom boom boom!"))
}

"collectAll empty list immediately" in {
val collectResult = LAFuture.collectAll(Nil : _*)
collectResult.isSatisfied must beTrue
collectResult.get(timeout) must beEqualTo(Nil)
}

"report a failed LAFuture as a failure for the overall future" in {
val one: LAFuture[Box[Int]] = new LAFuture
val two: LAFuture[Box[Int]] = LAFuture(() => Full(5): Box[Int])

one.fail(Failure("boom boom boom!"))

val collectResult = LAFuture.collectAll(one, two)
collectResult.get(timeout) must beEqualTo(Failure("boom boom boom!"))
}
}
}

}
Loading