Skip to content

Commit 6138c65

Browse files
committed
Add backward compatibility test
1 parent 8678981 commit 6138c65

File tree

5 files changed

+101
-30
lines changed

5 files changed

+101
-30
lines changed

build.sbt

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@ val emptyDoc = Compile / packageDoc / mappings := Seq(
22
(ThisBuild / baseDirectory).value / "README.md" -> "README.md"
33
)
44

5+
def resourcePrepare(extra: Def.Initialize[Task[String]]) =
6+
resourceGenerators += Def.task {
7+
val f = managedResourceDirectories.value.head / "application.conf"
8+
val host = java.net.InetAddress.getLocalHost.getHostAddress
9+
IO.write(
10+
f,
11+
s"""com.sandinh.couchbase {
12+
| connectionString="couchbase://$host"
13+
| user="cb"
14+
| password="cb_password"
15+
|}
16+
|${extra.value}
17+
|""".stripMargin
18+
)
19+
Seq(f)
20+
}
21+
22+
// util project to test couchbase-scala backward compatibility
23+
lazy val `compat-test` = project
24+
.settings(
25+
skipPublish,
26+
scalaVersion := scala213,
27+
resolvers += Resolver.sonatypeRepo("public"),
28+
libraryDependencies ++= Seq(
29+
"com.sandinh" %% "couchbase-scala" % "9.1.0+2-c1c4b4d4-SNAPSHOT",
30+
),
31+
inConfig(Compile)(resourcePrepare(Def.task(""))),
32+
)
33+
534
lazy val `couchbase-scala` = projectMatrix
635
.in(file("core"))
736
.configAxis(config13, Seq(scala212, scala213))
@@ -15,6 +44,15 @@ lazy val `couchbase-scala` = projectMatrix
1544
"com.google.inject" % "guice" % "5.0.1" % Test,
1645
) ++ specs2("-core").value,
1746
emptyDoc,
47+
inConfig(Test)(resourcePrepare(Def.task {
48+
val cp = (`compat-test` / Runtime / fullClasspath).value
49+
.map(_.data.getAbsolutePath)
50+
.mkString(":")
51+
s"""compat-test.classpath="$cp""""
52+
})),
53+
Test / test := (Test / test)
54+
.dependsOn(`compat-test` / Compile / compile)
55+
.value,
1856
)
1957

2058
lazy val `couchbase-play` = projectMatrix
@@ -51,6 +89,7 @@ lazy val `couchbase-play` = projectMatrix
5189
"ch.qos.logback" % "logback-classic" % "1.2.7" % Test,
5290
),
5391
emptyDoc,
92+
inConfig(Test)(resourcePrepare(Def.task(""))),
5493
)
5594

5695
// only aggregating project
@@ -85,15 +124,7 @@ inThisBuild(
85124
)
86125
)
87126

88-
inThisBuild(
89-
// In Test code: com.sandinh.couchbase.GuiceSpecBase.setup
90-
// We use Guice's injectMembers that inject value for the GuiceSpecBase's private var `_cb`
91-
// using reflection which is deny by default in java 16+
92-
addOpensForTest() ++ Seq(
93-
Test / fork := true,
94-
Test / javaOptions += {
95-
val host = java.net.InetAddress.getLocalHost.getHostAddress
96-
s"-Dcom.sandinh.couchbase.connectionString=$host"
97-
},
98-
)
99-
)
127+
// In Test code: com.sandinh.couchbase.GuiceSpecBase.setup
128+
// We use Guice's injectMembers that inject value for the GuiceSpecBase's private var `_cb`
129+
// using reflection which is deny by default in java 16+
130+
inThisBuild(addOpensForTest())
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.sandinh.couchbase
2+
import com.couchbase.client.java.document.JsonLongDocument
3+
import com.sandinh.couchbase.Implicits.DocNotExistFuture
4+
import com.typesafe.config.ConfigFactory
5+
6+
import scala.concurrent.Await
7+
import scala.concurrent.ExecutionContext.Implicits.global
8+
import scala.concurrent.duration._
9+
10+
object Main {
11+
def main(args: Array[String]): Unit = {
12+
val cluster = new CBCluster(ConfigFactory.load())
13+
val bucket = cluster.openBucketSync("fodi")
14+
15+
val f = args match {
16+
case Array("set", "counter", key, value) =>
17+
bucket.counter(key, 0, value.toLong)
18+
case Array("get", "counter", key) =>
19+
bucket
20+
.get[JsonLongDocument](key)
21+
.map(_.content.longValue)
22+
.recoverNotExist(0L)
23+
case _ => ???
24+
}
25+
26+
val v = Await.result(f, 5.seconds)
27+
print(v)
28+
}
29+
}

core/src/test/resources/application.conf

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.sandinh.couchbase
2+
3+
import com.typesafe.config.Config
4+
import javax.inject.Inject
5+
import scala.util.Random
6+
import scala.sys.process._
7+
8+
class BackwardCompatSpec extends GuiceSpecBase {
9+
@Inject private var conf: Config = _
10+
private lazy val cp = conf.getString("compat-test.classpath")
11+
12+
private def run(args: String) =
13+
s"java -cp $cp com.sandinh.couchbase.Main $args".!!.trim
14+
private def rndKv() =
15+
("compat" + Random.nextLong(), Random.nextLong().abs + 1)
16+
17+
"counter" should {
18+
"backward compat: new set, old get" in {
19+
val (k, v) = rndKv()
20+
cb.bk1.counter(k, 0, v).map(_.content) must beEqualTo(v).await
21+
run(s"get counter $k") === v.toString
22+
}
23+
"backward compat: old set, new get" in {
24+
val (k, v) = rndKv()
25+
run(s"set counter $k $v") === v.toString
26+
cb.bk1.getCounter(k) must beEqualTo(v).await
27+
}
28+
}
29+
}

play/src/test/resources/application.conf

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)