Skip to content

Commit 96ce5a3

Browse files
authored
support scala 2.12 (#129)
* support scala 2.12 * make some adjustments to the 2.12 compiler wrangling * run scalafmt * also scalafmtSbt because that's not included in scalafmtAll * add github action step to run tests on 2.12 * sort gha scala versions * satisfy our desire for order
1 parent 5491e2d commit 96ce5a3

File tree

12 files changed

+35
-17
lines changed

12 files changed

+35
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
fail-fast: false
3232
matrix:
3333
java: ['adopt@1.11']
34-
scala: ['2.13.13', '3.3.3']
34+
scala: ['2.12.18', '2.13.13', '3.3.3']
3535
steps:
3636
- name: Checkout current branch
3737
uses: actions/checkout@v2.3.4

benchmarks/src/main/scala/com/devsisters/shardcake/Client.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.devsisters.shardcake
22

3-
import com.devsisters.shardcake.Config
43
import com.devsisters.shardcake.Server.Message.Ping
54
import com.devsisters.shardcake.Server.PingPongEntity
6-
import zio._
5+
import zio.{ Config => _, _ }
76

87
object Client {
98
// self host should not be `localhost` to avoid optimization

benchmarks/src/main/scala/com/devsisters/shardcake/Server.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.devsisters.shardcake
22

3-
import com.devsisters.shardcake.Config
43
import com.devsisters.shardcake.interfaces.Storage
5-
import zio._
4+
import zio.{ Config => _, _ }
65
import zio.stream.ZStream
76

87
import java.util.concurrent.ForkJoinPool

build.sbt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
val scala212 = "2.12.18"
12
val scala213 = "2.13.13"
23
val scala3 = "3.3.3"
3-
val allScala = Seq(scala213, scala3)
4+
val allScala = Seq(scala212, scala213, scala3)
45

56
val zioVersion = "2.1.1"
67
val zioGrpcVersion = "0.6.2"
@@ -14,6 +15,7 @@ val redis4catsVersion = "1.5.2"
1415
val redissonVersion = "3.27.1"
1516
val scalaKryoVersion = "1.0.2"
1617
val testContainersVersion = "0.41.3"
18+
val scalaCompatVersion = "2.12.0"
1719

1820
inThisBuild(
1921
List(
@@ -69,8 +71,9 @@ lazy val core = project
6971
.settings(
7072
libraryDependencies ++=
7173
Seq(
72-
"dev.zio" %% "zio" % zioVersion,
73-
"dev.zio" %% "zio-streams" % zioVersion
74+
"dev.zio" %% "zio" % zioVersion,
75+
"dev.zio" %% "zio-streams" % zioVersion,
76+
"org.scala-lang.modules" %% "scala-collection-compat" % scalaCompatVersion
7477
)
7578
)
7679

core/src/main/scala/com/devsisters/shardcake/PodAddress.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.devsisters.shardcake
22

3+
import scala.collection.compat._
4+
35
case class PodAddress(host: String, port: Int) {
46
override def toString: String = s"$host:$port"
57
}

entities/src/main/scala/com/devsisters/shardcake/Sharding.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class Sharding private (
242242
(shardManager.notifyUnhealthyPod(pod) *>
243243
// just in case we missed the update from the pubsub, refresh assignments
244244
shardManager.getAssignments
245-
.flatMap(updateAssignments(_, fromShardManager = true))).forkDaemon
245+
.flatMap[Any, Throwable, Unit](updateAssignments(_, fromShardManager = true))).forkDaemon
246246
)
247247
}
248248

@@ -337,7 +337,8 @@ class Sharding private (
337337
}
338338

339339
def sendStream(entityId: String)(messages: ZStream[Any, Throwable, Msg]): Task[Unit] = {
340-
val send = ReplyChannel.single[Unit].flatMap(sendStreamGeneric(entityId, messages, None, _))
340+
val send =
341+
ReplyChannel.single[Unit].flatMap[Any, Throwable, Unit](sendStreamGeneric(entityId, messages, None, _))
341342
timeout.fold(send)(t => send.timeout(t).unit)
342343
}
343344

entities/src/main/scala/com/devsisters/shardcake/internal/ReplyChannel.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ private[shardcake] object ReplyChannel {
3131
def fail(cause: Cause[Throwable]): UIO[Unit] = promise.failCause(cause).unit
3232
def replySingle(a: A): UIO[Unit] = promise.succeed(Some(a)).unit
3333
def replyStream(stream: ZStream[Any, Throwable, A]): UIO[Unit] =
34-
stream.runHead.flatMap(promise.succeed(_)).catchAllCause(fail).fork.unit
35-
val output: Task[Option[A]] = promise.await.onError(fail)
34+
stream.runHead
35+
.flatMap(promise.succeed(_).unit)
36+
.catchAllCause[Any, Nothing, Unit](fail)
37+
.fork
38+
.unit
39+
40+
val output: Task[Option[A]] = promise.await.onError(fail)
3641
}
3742

3843
def single[A]: UIO[FromPromise[A]] =

entities/src/test/scala/com/devsisters/shardcake/ShardingSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ object ShardingSpec extends ZIOSpecDefault {
111111
_ <- Sharding.registerSingleton("singleton", p.succeed(()) *> ZIO.never)
112112
_ <- Sharding.registerScoped
113113
res <- p.await
114-
} yield assertTrue(res == ())
114+
} yield assertTrue(() == res)
115115
}
116116
},
117117
test("Send stream") {

examples/src/main/scala/example/complex/GuildApp.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import example.complex.GuildBehavior.GuildMessage.{ Join, Terminate }
77
import example.complex.GuildBehavior._
88
import zio.{ Config => _, _ }
99

10+
import scala.collection.compat._
11+
1012
object GuildApp extends ZIOAppDefault {
1113
val config: ZLayer[Any, SecurityException, Config] =
1214
ZLayer(

manager/src/main/scala/com/devsisters/shardcake/ShardManager.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import zio._
99
import zio.stream.ZStream
1010

1111
import scala.annotation.tailrec
12+
import scala.collection.compat._
1213

1314
/**
1415
* A component in charge of assigning and unassigning shards to/from pods
@@ -106,7 +107,7 @@ class ShardManager(
106107
.ping(pod)
107108
.timeout(config.pingTimeout)
108109
.someOrFailException
109-
.fold(_ => Set(pod), _ => Set.empty)
110+
.fold(_ => Set(pod), _ => Set.empty[PodAddress])
110111
)
111112
.map(_.flatten)
112113
shardsToRemove =
@@ -128,7 +129,7 @@ class ShardManager(
128129
)
129130
}
130131
.map(_.unzip)
131-
.map { case (pods, shards) => (pods.flatten.toSet, shards.flatten.toSet) }
132+
.map { case (pods, shards) => (pods.flatten[PodAddress].toSet, shards.flatten[ShardId].toSet) }
132133
(failedUnassignedPods, failedUnassignedShards) = failed
133134
// remove assignments of shards that couldn't be unassigned, as well as faulty pods
134135
filteredAssignments = (readyAssignments -- failedUnassignedPods).map { case (pod, shards) =>
@@ -147,7 +148,7 @@ class ShardManager(
147148
eventsHub.publish(ShardingEvent.ShardsAssigned(pod, shards)).as(Set.empty)
148149
)
149150
}
150-
.map(_.flatten.toSet)
151+
.map(_.flatten[PodAddress].toSet)
151152
failedPods = failedPingedPods ++ failedUnassignedPods ++ failedAssignedPods
152153
// check if failing pods are still up
153154
_ <- ZIO.foreachDiscard(failedPods)(notifyUnhealthyPod).forkDaemon
@@ -316,7 +317,9 @@ object ShardManager {
316317
): (Map[PodAddress, Set[ShardId]], Map[PodAddress, Set[ShardId]]) = {
317318
val (_, assignments) = shardsToRebalance.foldLeft((state.shardsPerPod, List.empty[(ShardId, PodAddress)])) {
318319
case ((shardsPerPod, assignments), shard) =>
319-
val unassignedPods = assignments.flatMap { case (shard, _) => state.shards.get(shard).flatten }.toSet
320+
val unassignedPods = assignments.flatMap { case (shard, _) =>
321+
state.shards.get(shard).flatten[PodAddress]
322+
}.toSet
320323
// find pod with least amount of shards
321324
shardsPerPod
322325
// keep only pods with the max version

storage-redis/src/main/scala/com/devsisters/shardcake/StorageRedis.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import zio.stream.ZStream
88
import zio.stream.interop.fs2z._
99
import zio.{ Task, ZIO, ZLayer }
1010

11+
import scala.collection.compat._
12+
1113
object StorageRedis {
1214
type fs2Stream[A] = fs2.Stream[Task, A]
1315
type Redis = RedisCommands[Task, String, String] with PubSubCommands[fs2Stream, String, String]

storage-redisson/src/main/scala/com/devsisters/shardcake/StorageRedis.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import org.redisson.client.codec.StringCodec
99
import zio.stream.ZStream
1010
import zio.{ Queue, Task, Unsafe, ZIO, ZLayer }
1111

12+
import scala.collection.compat._
13+
1214
object StorageRedis {
1315

1416
/**

0 commit comments

Comments
 (0)