Skip to content

Commit

Permalink
Various scala-2.13.0-M5 fixes
Browse files Browse the repository at this point in the history
fix akka-actor-tests compile errors

some tests still fail though

Fix test failures in akka-actor-test

Manually work arround missing implicit Factory[Nothing, Seq[Nothing]]

see scala/scala-collection-compat#137

akka-remote scalafix changes

Fix shutdownAll compile error

test:akka-remote scalafix changes

akka-multi-node-testkit scalafix

Fix akka-remote-tests multi-jvm compile errors

akka-stream-tests/test:scalafix

Fix test:akka-stream-tests

Crude implementation of ByteString.map

scalafix akka-actor-typed, akka-actor-typed-tests

akka-actor-typed-tests compile and succeed

scalafix akka-camel

scalafix akka-cluster

akka-cluster compile & test

scalafix akka-cluster-metrics

Fix akka-cluster-metrics

scalafix akka-cluster-tools

akka-cluster-tools compile and test

scalafix akka-distributed-data

akka-distributed-data fixes

scalafix akka-persistence

scalafix akka-cluster-sharding

fix akka-cluster-sharding

scalafix akka-contrib

Fix akka-cluster-sharding-typed test

scalafix akka-docs

Use scala-stm 0.9 (released for M5)

akka-docs

Remove dependency on collections-compat

Cherry-pick the relevant constructs to our own
private utils

Shorten 'scala.collections.immutable' by importing it

Duplicate 'immutable' imports

Use 'foreach' on futures

Replace MapLike with regular Map

Internal API markers

Simplify ccompat by moving PackageShared into object

Since we don't currently need to differentiate between 2.11 and

Avoid relying on 'union' (and ++) being left-biased

Fix akka-actor/doc by removing -Ywarn-unused

Make more things more private

Copyright headers

Use 'unsorted' to go from SortedSet to Set

Duplicate import

Use onComplete rather than failed.foreach

Clarify why we partly duplicate scala-collection-compat
  • Loading branch information
raboof committed Jan 11, 2019
1 parent 3bff646 commit d274e03
Show file tree
Hide file tree
Showing 141 changed files with 596 additions and 468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import akka.japi.*;
import org.junit.ClassRule;
import org.scalatest.junit.JUnitSuite;
import scala.Function1;
import scala.concurrent.Await;
import scala.concurrent.Future;
import scala.concurrent.Promise;
Expand All @@ -26,6 +27,7 @@
import static akka.japi.Util.classTag;

import akka.testkit.AkkaSpec;
import scala.util.Try;

public class JavaFutureTests extends JUnitSuite {

Expand Down Expand Up @@ -59,9 +61,9 @@ public void mustBeAbleToExecuteAnOnResultCallback() throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
Promise<String> cf = Futures.promise();
Future<String> f = cf.future();
f.onSuccess(new OnSuccess<String>() {
public void onSuccess(String result) {
if (result.equals("foo"))
f.onComplete(new OnComplete<String>() {
public void onComplete(Throwable t, String r) {
if ("foo".equals(r))
latch.countDown();
}
}, system.dispatcher());
Expand All @@ -76,8 +78,9 @@ public void mustBeAbleToExecuteAnOnExceptionCallback() throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
Promise<String> cf = Futures.promise();
Future<String> f = cf.future();
f.onFailure(new OnFailure() {
public void onFailure(Throwable t) {
f.onComplete(new OnComplete<String>() {
public void onComplete(Throwable t, String r) {
// 'null instanceof ...' is always false
if (t instanceof NullPointerException)
latch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import language.postfixOps
import java.io.Closeable
import java.util.concurrent._
import atomic.{ AtomicReference, AtomicInteger }
import scala.concurrent.{ future, Await, ExecutionContext }
import scala.concurrent.{ Future, Await, ExecutionContext }
import scala.concurrent.duration._
import java.util.concurrent.ThreadLocalRandom
import scala.util.Try
Expand Down Expand Up @@ -378,7 +378,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
import driver._
import system.dispatcher
val counter = new AtomicInteger
val terminated = future {
val terminated = Future {
var rounds = 0
while (Try(sched.scheduleOnce(Duration.Zero)(())(localEC)).isSuccess) {
Thread.sleep(1)
Expand Down Expand Up @@ -511,7 +511,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
withScheduler() { (sched, driver)
import system.dispatcher
val counter = new AtomicInteger
future { Thread.sleep(5); driver.close(); sched.close() }
Future { Thread.sleep(5); driver.close(); sched.close() }
val headroom = 200
var overrun = headroom
val cap = 1000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package akka.dispatch

import java.util.concurrent.{ ExecutorService, Executor, Executors }
import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.{ BatchingExecutor => _, Batchable => _, _ }
import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, ExecutionContextExecutorService }
import scala.concurrent.{ Await, blocking, Promise, Future }
import scala.concurrent.duration._
import akka.testkit.{ TestLatch, AkkaSpec, DefaultTimeout }
import akka.util.SerializedSuspendableExecutionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package akka.io

import akka.testkit.{ TestProbe, AkkaSpec }
import akka.testkit.SocketUtil._
import akka.testkit.SocketUtil.temporaryServerAddresses
import Tcp._

class CapacityLimitSpec extends AkkaSpec("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import akka.io.Inet.SocketOption
import akka.actor._
import akka.testkit.{ AkkaSpec, EventFilter, SocketUtil, TestActorRef, TestProbe }
import akka.util.{ ByteString, Helpers }
import akka.testkit.SocketUtil._
import akka.testkit.SocketUtil.temporaryServerAddress
import java.util.Random
import java.net.SocketTimeoutException
import java.nio.file.Files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import scala.collection.immutable
import akka.testkit.{ AkkaSpec, TestProbe }
import akka.actor.ActorRef
import akka.io.Inet.SocketOption
import akka.testkit.SocketUtil._
import akka.testkit.SocketUtil.temporaryServerAddress
import Tcp._
import akka.actor.ActorSystem
import akka.dispatch.ExecutionContexts
import scala.collection.immutable

trait TcpIntegrationSpecSupport { _: AkkaSpec

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.net.InetSocketAddress
import akka.testkit.{ TestProbe, ImplicitSender, AkkaSpec }
import akka.util.ByteString
import akka.actor.ActorRef
import akka.testkit.SocketUtil._
import akka.testkit.SocketUtil.temporaryServerAddresses

class UdpConnectedIntegrationSpec extends AkkaSpec("""
akka.loglevel = INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import akka.util.ByteString
import akka.actor.ActorRef
import akka.io.Udp._
import akka.io.Inet._
import akka.testkit.SocketUtil._
import akka.testkit.SocketUtil.temporaryServerAddresses
import java.net.DatagramSocket

class UdpIntegrationSpec extends AkkaSpec("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
val doneLatch = new TestLatch(connectionCount)

val counter = new AtomicInteger
var replies = Map.empty[Int, Int].withDefaultValue(0)
var replies: Map[Int, Int] = Map.empty.withDefaultValue(0)

val actor = system.actorOf(RoundRobinPool(connectionCount).props(routeeProps = Props(new Actor {
lazy val id = counter.getAndIncrement()
Expand All @@ -65,7 +65,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {

for (_ 1 to iterationCount; _ 1 to connectionCount) {
val id = Await.result((actor ? "hit").mapTo[Int], timeout.duration)
replies = replies + (id (replies(id) + 1))
replies += (id (replies(id) + 1))
}

counter.get should ===(connectionCount)
Expand Down Expand Up @@ -123,7 +123,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
val iterationCount = 10
val doneLatch = new TestLatch(connectionCount)

var replies = Map.empty[String, Int].withDefaultValue(0)
var replies: Map[String, Int] = Map.empty.withDefaultValue(0)

val paths = (1 to connectionCount) map { n
val ref = system.actorOf(Props(new Actor {
Expand All @@ -139,7 +139,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {

for (_ 1 to iterationCount; _ 1 to connectionCount) {
val id = Await.result((actor ? "hit").mapTo[String], timeout.duration)
replies = replies + (id (replies(id) + 1))
replies += (id (replies(id) + 1))
}

actor ! akka.routing.Broadcast("end")
Expand All @@ -154,7 +154,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
val connectionCount = 10
val iterationCount = 10

var replies = Map.empty[String, Int].withDefaultValue(0)
var replies: Map[String, Int] = Map.empty.withDefaultValue(0)

val actor = system.actorOf(Props(new Actor {
var n = 0
Expand Down Expand Up @@ -185,7 +185,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {

for (_ 1 to iterationCount; _ 1 to connectionCount) {
val id = Await.result((actor ? "hit").mapTo[String], timeout.duration)
replies = replies + (id (replies(id) + 1))
replies += (id (replies(id) + 1))
}

watch(actor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class BoundedBlockingQueueSpec
}

mustBlockFor(100 milliseconds, f)
events should containInSequence(offer("a"), awaitNotFull, signalNotFull, getSize, awaitNotFull)
events.toList should containInSequence(offer("a"), awaitNotFull, signalNotFull, getSize, awaitNotFull)
events shouldNot contain(offer("b"))
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ class BoundedBlockingQueueSpec

// `f` should still block since the queue is still empty
mustBlockFor(100 milliseconds, f)
events should containInSequence(getSize, awaitNotEmpty, signalNotEmpty, getSize, awaitNotEmpty)
events.toList should containInSequence(getSize, awaitNotEmpty, signalNotEmpty, getSize, awaitNotEmpty)
events shouldNot contain(poll)
}
}
Expand Down Expand Up @@ -297,7 +297,7 @@ class BoundedBlockingQueueSpec

// `f` should still block since the queue is still empty
mustBlockFor(100 milliseconds, f)
events should containInSequence(getSize, awaitNotFull, signalNotFull, getSize, awaitNotFull)
events.toList should containInSequence(getSize, awaitNotFull, signalNotFull, getSize, awaitNotFull)
events shouldNot contain(offer("World"))
}
}
Expand Down Expand Up @@ -706,12 +706,12 @@ trait QueueSetupHelper {

import akka.util.QueueTestEvents._

case class TestContext(queue: BoundedBlockingQueue[String], events: mutable.MutableList[QueueEvent], notEmpty: TestCondition, notFull: TestCondition, lock: ReentrantLock, backingQueue: util.Queue[String])
case class TestContext(queue: BoundedBlockingQueue[String], events: mutable.Buffer[QueueEvent], notEmpty: TestCondition, notFull: TestCondition, lock: ReentrantLock, backingQueue: util.Queue[String])

/**
* Backing queue that records all poll and offer calls in `events`
*/
class TestBackingQueue(events: mutable.MutableList[QueueEvent])
class TestBackingQueue(events: mutable.Buffer[QueueEvent])
extends util.LinkedList[String] {

override def poll(): String = {
Expand All @@ -733,7 +733,7 @@ trait QueueSetupHelper {
/**
* Reentrant lock condition that records when the condition is signaled or `await`ed.
*/
class TestCondition(events: mutable.MutableList[QueueEvent], condition: Condition, signalEvent: QueueEvent, awaitEvent: QueueEvent)
class TestCondition(events: mutable.Buffer[QueueEvent], condition: Condition, signalEvent: QueueEvent, awaitEvent: QueueEvent)
extends Condition {

case class Manual(waitTime: Long = 0, waitingThread: Option[Thread] = None)
Expand Down Expand Up @@ -798,7 +798,7 @@ trait QueueSetupHelper {
}

def newBoundedBlockingQueue(maxCapacity: Int): TestContext = {
val events: mutable.MutableList[QueueEvent] = new mutable.MutableList()
val events: mutable.Buffer[QueueEvent] = new mutable.ArrayBuffer()

val realLock = new ReentrantLock(false)
val wrappedNotEmpty = new TestCondition(events, realLock.newCondition(), signalNotEmpty, awaitNotEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,16 @@ class ByteStringSpec extends WordSpec with Matchers with Checkers {

"serialize correctly" when {
"parsing regular ByteString1C as compat" in {
val oldSerd = "aced000573720021616b6b612e7574696c2e42797465537472696e672442797465537472696e67314336e9eed0afcfe4a40200015b000562797465737400025b427872001b616b6b612e7574696c2e436f6d7061637442797465537472696e67fa2925150f93468f0200007870757200025b42acf317f8060854e002000078700000000a74657374737472696e67"
val oldSerd =
if (util.Properties.versionNumberString.startsWith("2.11") || util.Properties.versionNumberString.startsWith("2.12"))
"aced000573720021616b6b612e7574696c2e42797465537472696e672442797465537472696e67314336e9eed0afcfe4a40200015b000562797465737400025b427872001b616b6b612e7574696c2e436f6d7061637442797465537472696e67fa2925150f93468f0200007870757200025b42acf317f8060854e002000078700000000a74657374737472696e67"
else
// The data is the same, but the class hierarchy changed in 2.13:
"aced000573720021616b6b612e7574696c2e42797465537472696e672442797465537472696e67314336e9eed0afcfe4a40200015b000562797465737400025b427872001b616b6b612e7574696c2e436f6d7061637442797465537472696e676c083a30328adea002000078720014616b6b612e7574696c2e42797465537472696e678efa6cf8286d3c930200007870757200025b42acf317f8060854e002000078700000000a74657374737472696e67"
val bs = ByteString("teststring", "UTF8")
val str = hexFromSer(bs)

require(oldSerd == str)
str should be(oldSerd)
}

"given all types of ByteString" in {
Expand Down
16 changes: 8 additions & 8 deletions akka-actor-tests/src/test/scala/akka/util/LineNumberSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.util.Properties

class LineNumberSpec extends AkkaSpec {

private val isScala212 = Properties.versionNumberString.startsWith("2.12")
private val isScala211 = Properties.versionNumberString.startsWith("2.11")

"LineNumbers" when {

Expand All @@ -24,11 +24,11 @@ class LineNumberSpec extends AkkaSpec {

"work for larger functions" in {
val result = LineNumbers(twoline)
if (isScala212)
// because how scala 2.12 does the same as Java Lambdas
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 15, 15))
else
if (isScala211)
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 15, 17))
else
// because how scala 2.12+ does the same as Java Lambdas
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 15, 15))
}

"work for partial functions" in {
Expand All @@ -37,11 +37,11 @@ class LineNumberSpec extends AkkaSpec {

"work for `def`" in {
val result = LineNumbers(method("foo"))
if (isScala212)
if (isScala211)
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 25, 27))
else
// because how scala 2.12 does the same as Java Lambdas
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 26, 27))
else
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 25, 27))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit(
private def nextName(prefix: String = "a"): String = s"$prefix-${nameCounter.next()}"

// FIXME eventfilter support in typed testkit
import scaladsl.adapter._
import akka.actor.typed.scaladsl.adapter._

implicit val untypedSystem = system.toUntyped

Expand Down Expand Up @@ -748,7 +748,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit(
val beh = supervise[String](setup(context
supervise[String](setup { context
probe.ref ! Started
scaladsl.Behaviors.empty[String]
Behaviors.empty[String]
}).onFailure[RuntimeException](strategy)
)).onFailure[Exception](strategy)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ object ReceptionistApiSpec {
// to work
val registered: Future[Receptionist.Registered] =
system.receptionist ? (Receptionist.Register(key, service, _))
registered.onSuccess {
registered.foreach {
case key.Registered(ref)
// ref is the right type here
ref ! "woho"
case _ ()
}

// one-off ask outside of actor, should be uncommon but not rare
val found: Future[Receptionist.Listing] =
system.receptionist ? (Receptionist.Find(key, _))
found.onSuccess {
found.foreach {
case key.Listing(instances)
instances.foreach(_ ! "woho")
case _ ()
}

Behaviors.setup[Any] { context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package akka.actor.typed
package scaladsl

import akka.actor.ExtendedActorSystem
import akka.actor.typed.internal.adapter.{ PropsAdapter => _, _ }
import akka.actor.typed.internal.adapter.{ PropsAdapter _, _ }
import akka.annotation.InternalApi

/**
Expand Down
4 changes: 4 additions & 0 deletions akka-actor/src/main/mima-filters/2.5.18.backwards.excludes
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.pattern.BackoffOption
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.pattern.HandleBackoff.finalStopMessageReceived")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.pattern.HandleBackoff.finalStopMessageReceived_=")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.pattern.HandleBackoff.finalStopMessage")

# Scala 2.13.0-M5
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.actor.dungeon.ChildrenContainer#ChildrenIterable.this")
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.actor.dungeon.ChildrenContainer#ChildRestartsIterable.this")
6 changes: 5 additions & 1 deletion akka-actor/src/main/mima-filters/2.5.19.backwards.excludes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ ProblemFilters.exclude[MissingClassProblem]("akka.io.dns.internal.AsyncDnsResolv
ProblemFilters.exclude[MissingClassProblem]("akka.io.dns.internal.AsyncDnsResolver$SrvType$")
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.io.dns.internal.AsyncDnsCache.put")
ProblemFilters.exclude[MissingClassProblem]("akka.io.dns.internal.AsyncDnsResolver$Ipv6Type$")
ProblemFilters.exclude[MissingClassProblem]("akka.io.dns.internal.AsyncDnsResolver$Ipv4Type$")
ProblemFilters.exclude[MissingClassProblem]("akka.io.dns.internal.AsyncDnsResolver$Ipv4Type$")

# Changes related to adding Scala 2.13.0-M5 support
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.actor.dungeon.ChildrenContainer#ChildrenIterable.this")
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.actor.dungeon.ChildrenContainer#ChildRestartsIterable.this")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.util
Expand Down
2 changes: 1 addition & 1 deletion akka-actor/src/main/scala-2.12/akka/compat/Future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package akka.compat
import akka.annotation.InternalApi
import scala.concurrent.{ ExecutionContext, Future SFuture }
import scala.collection.immutable
import scala.collection.compat._
import akka.util.ccompat._

/**
* INTERNAL API
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.util
Expand Down
Loading

0 comments on commit d274e03

Please sign in to comment.