Skip to content

Commit d1a081e

Browse files
committed
reformat with new scalafmt
1 parent 3a2eb68 commit d1a081e

File tree

28 files changed

+265
-223
lines changed

28 files changed

+265
-223
lines changed

.scalafmt

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

.scalafmt.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
style = default
2+
maxColumn = 100

build.sbt

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
def latestScalafmt = "1.0.0-RC4"
2+
3+
commands += Command.args("scalafmt", "Run scalafmt cli.") {
4+
case (state, args) =>
5+
val Right(scalafmt) =
6+
org.scalafmt.bootstrap.ScalafmtBootstrap.fromVersion(latestScalafmt)
7+
scalafmt.main("--non-interactive" +: args.toArray)
8+
state
9+
}
110

211
lazy val commonSettings = Seq(
312
organization := "com.whisk",
@@ -6,11 +15,10 @@ lazy val commonSettings = Seq(
615
crossScalaVersions := Seq("2.12.2", "2.11.11", "2.10.6"),
716
scalacOptions ++= Seq("-feature", "-deprecation"),
817
fork in Test := true,
9-
licenses +=("MIT", url("http://opensource.org/licenses/MIT")),
18+
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
1019
sonatypeProfileName := "com.whisk",
11-
scalafmtConfig := Some(file(".scalafmt")),
1220
// TODO Remove once this workaround no longer needed (https://github.com/sbt/sbt/issues/2786):
13-
ivyScala := { ivyScala.value map {_.copy(overrideScalaVersion = sbtPlugin.value)} },
21+
ivyScala := { ivyScala.value map { _.copy(overrideScalaVersion = sbtPlugin.value) } },
1422
pomExtra in Global := {
1523
<url>https://github.com/whisklabs/docker-it-scala</url>
1624
<scm>
@@ -34,46 +42,44 @@ lazy val commonSettings = Seq(
3442
)
3543

3644
lazy val root =
37-
project.in(file("."))
45+
project
46+
.in(file("."))
3847
.settings(commonSettings: _*)
39-
.settings(
40-
publish := {},
41-
publishLocal := {},
42-
packagedArtifacts := Map.empty)
48+
.settings(publish := {}, publishLocal := {}, packagedArtifacts := Map.empty)
4349
.aggregate(core, testkitSpotifyImpl, testkitDockerJavaImpl, config, scalatest, specs2, samples)
4450

4551
lazy val core =
4652
project
4753
.settings(commonSettings: _*)
48-
.settings(
49-
name := "docker-testkit-core",
50-
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.22")
54+
.settings(name := "docker-testkit-core",
55+
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.22")
5156

5257
lazy val testkitSpotifyImpl =
53-
project.in(file("impl/spotify"))
58+
project
59+
.in(file("impl/spotify"))
5460
.settings(commonSettings: _*)
55-
.settings(
56-
name := "docker-testkit-impl-spotify",
57-
libraryDependencies ++=
58-
Seq("com.spotify" % "docker-client" % "8.8.0",
59-
"com.google.code.findbugs" % "jsr305" % "3.0.1"))
61+
.settings(name := "docker-testkit-impl-spotify",
62+
libraryDependencies ++=
63+
Seq("com.spotify" % "docker-client" % "8.8.0",
64+
"com.google.code.findbugs" % "jsr305" % "3.0.1"))
6065
.dependsOn(core)
6166

6267
lazy val testkitDockerJavaImpl =
63-
project.in(file("impl/docker-java"))
68+
project
69+
.in(file("impl/docker-java"))
6470
.settings(commonSettings: _*)
6571
.settings(
6672
name := "docker-testkit-impl-docker-java",
6773
libraryDependencies ++=
6874
Seq("com.github.docker-java" % "docker-java" % "3.0.12",
69-
"com.google.code.findbugs" % "jsr305" % "3.0.1"))
75+
"com.google.code.findbugs" % "jsr305" % "3.0.1")
76+
)
7077
.dependsOn(core)
7178

7279
lazy val samples =
7380
project
7481
.settings(commonSettings: _*)
75-
.settings(
76-
name := "docker-testkit-samples")
82+
.settings(name := "docker-testkit-samples")
7783
.dependsOn(core)
7884

7985
lazy val scalatest =
@@ -82,22 +88,22 @@ lazy val scalatest =
8288
.settings(
8389
name := "docker-testkit-scalatest",
8490
libraryDependencies ++=
85-
Seq(
86-
"org.scalatest" %% "scalatest" % "3.0.3",
87-
"ch.qos.logback" % "logback-classic" % "1.2.1" % "test",
88-
"org.postgresql" % "postgresql" % "9.4.1210" % "test"))
91+
Seq("org.scalatest" %% "scalatest" % "3.0.3",
92+
"ch.qos.logback" % "logback-classic" % "1.2.1" % "test",
93+
"org.postgresql" % "postgresql" % "9.4.1210" % "test")
94+
)
8995
.dependsOn(core, testkitSpotifyImpl % "test", testkitDockerJavaImpl % "test", samples % "test")
9096

9197
lazy val specs2 =
92-
project
98+
project
9399
.settings(commonSettings: _*)
94100
.settings(
95101
name := "docker-testkit-specs2",
96102
libraryDependencies ++=
97-
Seq(
98-
"org.specs2" %% "specs2-core" % "3.8.6",
99-
"ch.qos.logback" % "logback-classic" % "1.2.1" % "test",
100-
"org.postgresql" % "postgresql" % "9.4.1210" % "test"))
103+
Seq("org.specs2" %% "specs2-core" % "3.8.6",
104+
"ch.qos.logback" % "logback-classic" % "1.2.1" % "test",
105+
"org.postgresql" % "postgresql" % "9.4.1210" % "test")
106+
)
101107
.dependsOn(core, samples % "test", testkitDockerJavaImpl % "test")
102108

103109
lazy val config =
@@ -106,12 +112,10 @@ lazy val config =
106112
.settings(
107113
name := "docker-testkit-config",
108114
libraryDependencies ++=
109-
Seq(
110-
"com.iheart" %% "ficus" % "1.4.1",
111-
"org.scalatest" %% "scalatest" % "3.0.3" % "test"),
115+
Seq("com.iheart" %% "ficus" % "1.4.1", "org.scalatest" %% "scalatest" % "3.0.3" % "test"),
112116
publish := scalaVersion map {
113117
case x if x.startsWith("2.10") => {}
114-
case _ => publish.value
118+
case _ => publish.value
115119
}
116120
)
117121
.dependsOn(core, testkitDockerJavaImpl)

config/src/main/scala/com/whisk/docker/config/DockerTypesafeConfig.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ object DockerTypesafeConfig extends DockerKitDockerJava {
3636
// log line checker takes priority
3737
def toReadyChecker = {
3838
(`log-line`, `http-response-code`) match {
39-
case (None, None) => DockerReadyChecker.Always
39+
case (None, None) => DockerReadyChecker.Always
4040
case (None, Some(rr)) => httpResponseCodeReadyChecker(rr)
41-
case (Some(ll), _) => DockerReadyChecker.LogLineContains(ll)
41+
case (Some(ll), _) => DockerReadyChecker.LogLineContains(ll)
4242
}
4343
}
4444
}
@@ -60,13 +60,13 @@ object DockerTypesafeConfig extends DockerKitDockerJava {
6060
val readyChecker = `ready-checker`.fold[DockerReadyChecker](AlwaysReady) { _.toReadyChecker }
6161

6262
DockerContainer(
63-
image = `image-name`,
64-
name = `container-name`,
65-
command = command,
66-
bindPorts = bindPorts,
67-
env = `environmental-variables`,
68-
readyChecker = readyChecker,
69-
volumeMappings = `volume-maps`
63+
image = `image-name`,
64+
name = `container-name`,
65+
command = command,
66+
bindPorts = bindPorts,
67+
env = `environmental-variables`,
68+
readyChecker = readyChecker,
69+
volumeMappings = `volume-maps`
7070
)
7171
}
7272
}

config/src/test/scala/com/whisk/docker/config/test/DockerConfigSpec.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class DockerConfigSpec extends FlatSpec with Matchers with DockerKitConfig {
1010

1111
"Config-based configurations" should "produce same containers as code-based ones" in {
1212
val volumes = Seq(
13-
VolumeMapping(container = "/opt/data", host = "/opt/docker/data", rw = false),
14-
VolumeMapping(container = "/opt/log", host = "/opt/docker/log", rw = true)
13+
VolumeMapping(container = "/opt/data", host = "/opt/docker/data", rw = false),
14+
VolumeMapping(container = "/opt/log", host = "/opt/docker/log", rw = true)
1515
)
1616

1717
val cassandraExpected = DockerContainer("whisk/cassandra:2.1.8")
1818
.withPorts(9042 -> None)
1919
.withReadyChecker(
20-
DockerReadyChecker.LogLineContains("Starting listening for CQL clients on"))
20+
DockerReadyChecker.LogLineContains("Starting listening for CQL clients on"))
2121
.withVolumes(volumes)
2222

2323
configureDockerContainer("docker.cassandra") shouldBe cassandraExpected
@@ -26,7 +26,7 @@ class DockerConfigSpec extends FlatSpec with Matchers with DockerKitConfig {
2626
.withPorts((5432, None))
2727
.withEnv(s"POSTGRES_USER=nph", s"POSTGRES_PASSWORD=suitup")
2828
.withReadyChecker(
29-
DockerReadyChecker.LogLineContains("database system is ready to accept connections"))
29+
DockerReadyChecker.LogLineContains("database system is ready to accept connections"))
3030

3131
configureDockerContainer("docker.postgres") shouldBe postgresExpected
3232

@@ -40,10 +40,10 @@ class DockerConfigSpec extends FlatSpec with Matchers with DockerKitConfig {
4040
val elasticExpected = DockerContainer("elasticsearch:1.7.1")
4141
.withPorts(9200 -> None, 9300 -> None)
4242
.withReadyChecker(
43-
DockerReadyChecker
44-
.HttpResponseCode(9200, "/")
45-
.within(100.millis)
46-
.looped(20, 1250.millis))
43+
DockerReadyChecker
44+
.HttpResponseCode(9200, "/")
45+
.within(100.millis)
46+
.looped(20, 1250.millis))
4747

4848
configureDockerContainer("docker.elasticsearch") shouldBe elasticExpected
4949
}

core/src/main/scala/com/whisk/docker/DockerCommandExecutor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ case class ContainerPort(port: Int, protocol: PortProtocol.Value)
1010

1111
object ContainerPort {
1212
def parse(str: String) = {
13-
val Array(p, rest @ _ *) = str.split("/")
13+
val Array(p, rest @ _*) = str.split("/")
1414
val proto = rest.headOption
1515
.flatMap(pr => PortProtocol.values.find(_.toString.equalsIgnoreCase(pr)))
1616
.getOrElse(PortProtocol.TCP)

core/src/main/scala/com/whisk/docker/DockerContainerManager.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ object DockerContainerManager {
9797
.map(_.containers)
9898
.getOrElse(List.empty)
9999
.partition(
100-
_.dependencies.exists(containersWithLinksNotLinked.contains)
100+
_.dependencies.exists(containersWithLinksNotLinked.contains)
101101
)
102102

103103
buildDependencyGraph(
104-
ContainerDependencyGraph(
105-
containers = containersWithoutLinks ++ containersWithLinksAndLinked,
106-
dependants = Some(
107-
ContainerDependencyGraph(
108-
containers = containersWithLinksNotLinked ++ containersToBeMovedUpALevel,
109-
dependants = dependants.map(
110-
_.copy(containers = containersToBeLeftAtCurrentPosition))
111-
))
112-
)
104+
ContainerDependencyGraph(
105+
containers = containersWithoutLinks ++ containersWithLinksAndLinked,
106+
dependants = Some(
107+
ContainerDependencyGraph(
108+
containers = containersWithLinksNotLinked ++ containersToBeMovedUpALevel,
109+
dependants =
110+
dependants.map(_.copy(containers = containersToBeLeftAtCurrentPosition))
111+
))
112+
)
113113
)
114114
}
115115
}

core/src/main/scala/com/whisk/docker/DockerContainerState.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ class DockerContainerState(spec: DockerContainer) {
5858
private def runReadyCheck()(implicit docker: DockerCommandExecutor,
5959
ec: ExecutionContext): Future[Boolean] =
6060
_isReady.init(
61-
(for {
62-
r <- isRunning() if r
63-
b <- spec.readyChecker(this) if b
64-
} yield b) recoverWith {
65-
case _: NoSuchElementException =>
66-
log.error("Not ready: " + {
67-
spec.image
68-
})
69-
Future.successful(false)
70-
case e =>
71-
log.error(e.getMessage, e)
72-
Future.successful(false)
73-
}
61+
(for {
62+
r <- isRunning() if r
63+
b <- spec.readyChecker(this) if b
64+
} yield b) recoverWith {
65+
case _: NoSuchElementException =>
66+
log.error("Not ready: " + {
67+
spec.image
68+
})
69+
Future.successful(false)
70+
case e =>
71+
log.error(e.getMessage, e)
72+
Future.successful(false)
73+
}
7474
)
7575

7676
protected def getRunningContainer()(
@@ -81,13 +81,13 @@ class DockerContainerState(spec: DockerContainer) {
8181
def getName()(implicit docker: DockerCommandExecutor, ec: ExecutionContext): Future[String] =
8282
getRunningContainer.flatMap {
8383
case Some(res) => Future.successful(res.name)
84-
case None => Future.failed(new RuntimeException(s"Container ${spec.image} is not running"))
84+
case None => Future.failed(new RuntimeException(s"Container ${spec.image} is not running"))
8585
}
8686

8787
def getIpAddresses()(implicit docker: DockerCommandExecutor,
8888
ec: ExecutionContext): Future[Seq[String]] = getRunningContainer.flatMap {
8989
case Some(res) => Future.successful(res.ipAddresses)
90-
case None => Future.failed(new RuntimeException(s"Container ${spec.image} is not running"))
90+
case None => Future.failed(new RuntimeException(s"Container ${spec.image} is not running"))
9191
}
9292

9393
private val _ports = SinglePromise[Map[Int, Int]]
@@ -98,7 +98,7 @@ class DockerContainerState(spec: DockerContainer) {
9898
case None => Future.failed(new RuntimeException(s"Container ${spec.image} is not running"))
9999
case Some(c) =>
100100
val ports: Map[Int, Int] = c.ports.collect {
101-
case (exposedPort, Seq(binding, _ *)) =>
101+
case (exposedPort, Seq(binding, _*)) =>
102102
exposedPort.port -> binding.hostPort
103103
}
104104
Future.successful(ports)

core/src/main/scala/com/whisk/docker/DockerKit.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trait DockerKit {
2323
implicit lazy val dockerExecutionContext: ExecutionContext = {
2424
// using Math.max to prevent unexpected zero length of docker containers
2525
ExecutionContext.fromExecutor(
26-
Executors.newFixedThreadPool(Math.max(1, dockerContainers.length * 2)))
26+
Executors.newFixedThreadPool(Math.max(1, dockerContainers.length * 2)))
2727
}
2828
implicit lazy val dockerExecutor = dockerFactory.createExecutor()
2929

@@ -46,7 +46,7 @@ trait DockerKit {
4646
val future: Future[Boolean] =
4747
containerManager.initReadyAll(StartContainersTimeout).map(_.map(_._2).forall(identity))
4848
sys.addShutdownHook(
49-
Await.ready(containerManager.stopRmAll(), StopContainersTimeout)
49+
Await.ready(containerManager.stopRmAll(), StopContainersTimeout)
5050
)
5151
Await.result(future, StartContainersTimeout)
5252
} catch {

core/src/main/scala/com/whisk/docker/DockerReadyChecker.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ trait DockerReadyChecker {
3232
val p = Promise[Boolean]()
3333
aF.map {
3434
case true => p.trySuccess(true)
35-
case _ =>
35+
case _ =>
3636
}
3737
bF.map {
3838
case true => p.trySuccess(true)
39-
case _ =>
39+
case _ =>
4040
}
4141
p.future
4242
}
@@ -69,9 +69,9 @@ object RetryUtils {
6969
implicit ec: ExecutionContext): Future[T] = {
7070
val bail = Promise[T]()
7171
withDelay(deadline.toMillis)(
72-
bail
73-
.tryCompleteWith(Future.failed(new TimeoutException(s"timed out after $deadline")))
74-
.future)
72+
bail
73+
.tryCompleteWith(Future.failed(new TimeoutException(s"timed out after $deadline")))
74+
.future)
7575
Future.firstCompletedOf(future :: bail.future :: Nil)
7676
}
7777

@@ -85,7 +85,7 @@ object RetryUtils {
8585
Future.failed(e match {
8686
case _: NoSuchElementException =>
8787
new NoSuchElementException(
88-
s"Ready checker returned false after $attempts attempts, delayed $delay each")
88+
s"Ready checker returned false after $attempts attempts, delayed $delay each")
8989
case _ => e
9090
})
9191
case n =>
@@ -113,7 +113,7 @@ object DockerReadyChecker {
113113
extends DockerReadyChecker {
114114
override def apply(container: DockerContainerState)(implicit docker: DockerCommandExecutor,
115115
ec: ExecutionContext): Future[Boolean] = {
116-
container.getPorts().map(_ (port)).flatMap { p =>
116+
container.getPorts().map(_(port)).flatMap { p =>
117117
val url = new URL("http", host.getOrElse(docker.host), p, path)
118118
Future {
119119
val con = url.openConnection().asInstanceOf[HttpURLConnection]

0 commit comments

Comments
 (0)