Skip to content

Commit 02e6b1f

Browse files
committed
Merge branch 'master' into simplify-fds-impls
2 parents 36a7dc4 + cfa680a commit 02e6b1f

16 files changed

Lines changed: 100 additions & 65 deletions

File tree

.scalafmt.conf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ newlines.topLevelStatementBlankLines = [
66
{ blanks: { after: 0 } }
77
]
88

9-
fileOverride {
10-
"glob:**/*.sbt" {
11-
runner.dialect = sbt1
12-
align.preset = most
13-
}
14-
"glob:**/project/*.scala" {
15-
align.preset = most
16-
}
17-
}
18-
199
rewrite {
20-
rules = [Imports]
10+
rules = [Imports, AvoidInfix, RedundantParens, RemoveSemicolons]
2111
scala3.convertToNewSyntax = true
2212
scala3.newSyntax.control = false
13+
scala3.newSyntax.deprecated = true
2314

2415
imports {
2516
groups = [["javax?\\..*"], ["scala\\..*"], [".*"], ["com\\.kevel\\..*"]]
2617
sort = ascii
2718
selectors = fold
2819
}
2920
}
21+
22+
fileOverride {
23+
"glob:**/*.sbt" {
24+
align.preset = most
25+
}
26+
"glob:**/project/*.scala" {
27+
align.preset = most
28+
}
29+
}

modules/aws/src/main/scala/com/kevel/apso/aws/S3Bucket.scala

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class S3Bucket(
4242
private[this] lazy val maxErrorRetry = Try(config.getInt(configPrefix + ".max-error-retry"))
4343

4444
@transient private[this] lazy val defaultExecutor = {
45-
val maxPoolSize = 100;
45+
val maxPoolSize = 100
4646
val threadCount = new AtomicInteger(0)
4747
// NOTE: This is the default thread pool used by the `TransferManager`. I had to replicate it here
4848
// to make sure that threads are daemonized. This could be problematic, e.g. shutting down the
@@ -55,14 +55,14 @@ class S3Bucket(
5555
60,
5656
TimeUnit.SECONDS,
5757
new LinkedBlockingQueue(1_000),
58-
(runnable) => {
58+
runnable => {
5959
val thread = new Thread(runnable)
6060
thread.setName(s"apso-transfer-manager-${threadCount.getAndIncrement()}")
6161
thread.setDaemon(true)
6262
thread
6363
}
6464
)
65-
executor.allowCoreThreadTimeOut(true);
65+
executor.allowCoreThreadTimeOut(true)
6666
executor
6767
}
6868

@@ -82,7 +82,7 @@ class S3Bucket(
8282

8383
val s3 = client.build()
8484
if (!bucketExists(s3))
85-
s3.createBucket({
85+
s3.createBucket {
8686
val requestBuilder = CreateBucketRequest
8787
.builder()
8888
.bucket(bucketName)
@@ -97,7 +97,7 @@ class S3Bucket(
9797
)
9898
.build()
9999
else requestBuilder.build()
100-
}).join()
100+
}.join()
101101
s3
102102
}
103103

@@ -351,7 +351,10 @@ class S3Bucket(
351351

352352
s3Client
353353
.putObject(
354-
b => { b.bucket(bucketName).key(sanitizeKey(key) + "/"); () },
354+
b => {
355+
b.bucket(bucketName).key(sanitizeKey(key) + "/")
356+
()
357+
},
355358
AsyncRequestBody.fromInputStream(emptyContent, 0, defaultExecutor)
356359
)
357360
.join()
@@ -417,9 +420,11 @@ class S3Bucket(
417420
case ex: S3Exception =>
418421
ex.statusCode() match {
419422
case 404 =>
420-
logger.error("The specified file does not exist", ex); true // no need to retry
423+
logger.error("The specified file does not exist", ex)
424+
true // no need to retry
421425
case 403 =>
422-
logger.error("No permission to access the file", ex); true // no need to retry
426+
logger.error("No permission to access the file", ex)
427+
true // no need to retry
423428
case _ =>
424429
logger.warn(
425430
s"""|S3 service error: ${ex.getMessage}. Extended request id: ${ex.requestId}
@@ -429,22 +434,27 @@ class S3Bucket(
429434
false
430435
}
431436
case ex: SdkClientException =>
432-
log(!ex.retryable, s"Client Exception: ${ex.getMessage}", ex); !ex.retryable
437+
log(!ex.retryable, s"Client Exception: ${ex.getMessage}", ex)
438+
!ex.retryable
433439

434440
case ex: SdkException =>
435-
log(!ex.retryable, s"SDK Exception: ${ex.getMessage}", ex); !ex.retryable
441+
log(!ex.retryable, s"SDK Exception: ${ex.getMessage}", ex)
442+
!ex.retryable
436443

437444
case ex: CompletionException =>
438445
logger.warn("Completion Exception", ex)
439446
handler(ex.getCause)
440447

441448
case ex: Exception =>
442-
logger.warn("An error occurred", ex); false
449+
logger.warn("An error occurred", ex)
450+
false
443451
}
444452

445453
private[this] def retry[T](f: => T, tries: Int = 3, sleepTime: Int = 5000): Option[T] =
446-
if (tries == 0) { logger.error("Max retries reached. Aborting S3 operation"); None }
447-
else
454+
if (tries == 0) {
455+
logger.error("Max retries reached. Aborting S3 operation")
456+
None
457+
} else
448458
Try(f) match {
449459
case Success(res) => Some(res)
450460
case Failure(e) if !handler(e) =>

modules/caching/src/main/scala-2/com/kevel/apso/caching/SyncEvidence.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import scala.concurrent.Future
99
* @tparam A
1010
* the tagged type.
1111
*/
12-
private[caching] trait SyncEvidence[A]
12+
class SyncEvidence[A] private[caching] ()
1313

14-
private[caching] object SyncEvidence extends LowPrioritySyncEvidence {
15-
implicit def ev1[A]: SyncEvidence[Future[A]] = new SyncEvidence[Future[A]] {}
16-
implicit def ev2[A]: SyncEvidence[Future[A]] = new SyncEvidence[Future[A]] {}
14+
object SyncEvidence extends LowPrioritySyncEvidence {
15+
implicit def ev1[A]: SyncEvidence[Future[A]] = new SyncEvidence[Future[A]]
16+
implicit def ev2[A]: SyncEvidence[Future[A]] = new SyncEvidence[Future[A]]
1717
}
1818

19-
private[caching] trait LowPrioritySyncEvidence {
20-
implicit def ev[A]: SyncEvidence[A] = new SyncEvidence[A] {}
19+
trait LowPrioritySyncEvidence {
20+
implicit def ev[A]: SyncEvidence[A] = new SyncEvidence[A]
2121
}

modules/caching/src/main/scala-3/com/kevel/apso/caching/SyncEvidence.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package com.kevel.apso.caching
33
import scala.concurrent.Future
44
import scala.util.NotGiven
55

6-
/** An evidence that an `A` is not a `Future[_]`.
6+
/** An evidence that an `A` is not a `Future[?]`. This class and respective companion object are public since they are
7+
* required by public methods, but they should not be used explicitly in user code.
78
*
89
* @tparam A
910
* the tagged type.
1011
*/
11-
private[caching] trait SyncEvidence[A]
12+
class SyncEvidence[A] private[caching] ()
1213

13-
private[caching] object SyncEvidence {
14-
implicit def ev[A](implicit notFuture: NotGiven[A <:< Future[_]]): SyncEvidence[A] = new SyncEvidence[A] {}
14+
object SyncEvidence {
15+
given [A](using NotGiven[A <:< Future[?]]): SyncEvidence[A] = SyncEvidence[A]
1516
}

modules/circe/src/main/scala/com/kevel/apso/circe/ExtraJsonProtocol.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ trait ExtraTimeJsonProtocol {
2626
implicit val finiteDurationEncoder: Encoder[FiniteDuration] =
2727
Encoder.forProduct1("milliseconds")(_.toMillis)
2828
implicit val finiteDurationDecoder: Decoder[FiniteDuration] =
29-
Decoder[Long].emapPrettyTry(v => tryToParseDuration(v.toString)) or
30-
Decoder[String].emapPrettyTry(v => tryToParseDuration(v)) or
31-
Decoder.forProduct1[FiniteDuration, Long]("milliseconds")(_.millis) or
32-
Decoder.forProduct1[FiniteDuration, Long]("seconds")(_.seconds) or
33-
Decoder.forProduct1[FiniteDuration, Long]("minutes")(_.minutes) or
34-
Decoder.forProduct1[FiniteDuration, Long]("hours")(_.hours) or
35-
Decoder.forProduct1[FiniteDuration, Long]("days")(_.days)
29+
Decoder[Long]
30+
.emapPrettyTry(v => tryToParseDuration(v.toString))
31+
.or(Decoder[String].emapPrettyTry(v => tryToParseDuration(v)))
32+
.or(Decoder.forProduct1[FiniteDuration, Long]("milliseconds")(_.millis))
33+
.or(Decoder.forProduct1[FiniteDuration, Long]("seconds")(_.seconds))
34+
.or(Decoder.forProduct1[FiniteDuration, Long]("minutes")(_.minutes))
35+
.or(Decoder.forProduct1[FiniteDuration, Long]("hours")(_.hours))
36+
.or(Decoder.forProduct1[FiniteDuration, Long]("days")(_.days))
3637

3738
implicit val intervalEncoder: Encoder[Interval] =
3839
Encoder.forProduct2("startMillis", "endMillis")(int => (int.getStartMillis, int.getEndMillis))

modules/circe/src/main/scala/com/kevel/apso/circe/Implicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object Implicits {
2929
val (prefix, nextJson) = prefixesAndJsons.dequeue()
3030

3131
nextJson.asObject.foreach(jsonObject =>
32-
jsonObject.toIterable.foreach({ case (k, v) =>
32+
jsonObject.toIterable.foreach { case (k, v) =>
3333
if (!(ignoreNull && v.isNull)) {
3434
val kk = if (prefix.nonEmpty) s"$prefix$separator$k" else k
3535
if (v.isObject) {
@@ -38,7 +38,7 @@ object Implicits {
3838
builder += onLeaf(kk, v)
3939
}
4040
}
41-
})
41+
}
4242
)
4343
}
4444
builder.result()

modules/collections/src/main/scala/com/kevel/apso/collection/DeboxMap.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ import scala.specialized as spec
2929
* @param v
3030
* the number of values
3131
*/
32-
class InvalidSizes(k: Int, v: Int) extends Exception("%s, %s" format (k, v))
32+
class InvalidSizes(k: Int, v: Int) extends Exception("%s, %s".format(k, v))
3333

3434
/** Exception thrown when a `DeboxMap` factory is called requiring an invalid preallocated size.
3535
* @param n
3636
* the requested size
3737
*/
38-
class MapOverflow(n: Int) extends Exception("size %s exceeds max" format n)
38+
class MapOverflow(n: Int) extends Exception("size %s exceeds max".format(n))
3939

4040
/** Exception thrown when trying to access a non-existent key in a `DeboxMap`.
4141
* @param k
4242
* the non-existent key
4343
*/
44-
class NotFound(k: String) extends Exception("key %s was not found" format k)
44+
class NotFound(k: String) extends Exception("key %s was not found".format(k))
4545

4646
/** Object containing factory methods for `DeboxMaps`.
4747
*/

modules/core/src/main/scala/com/kevel/apso/Retry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Retry {
1616
case 0 =>
1717
f
1818
case _ =>
19-
f recoverWith {
19+
f.recoverWith {
2020
case NonFatal(
2121
_
2222
) => // it would be indifferent to use a Throwable here because Futures don't catch Fatal exceptions

modules/core/src/test/scala/com/kevel/apso/ImplicitsSpec.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@ class ImplicitsSpec extends Specification with ScalaCheck {
1313

1414
class MockRandom(elems: Double*) extends Random {
1515
private[this] var nextElems = elems.toList
16-
override def nextInt() = { val e = nextElems.head.toInt; nextElems = nextElems.tail; e }
17-
override def nextInt(n: Int) = { val e = nextElems.head.toInt % n; nextElems = nextElems.tail; e }
18-
override def nextDouble() = { val e = nextElems.head; nextElems = nextElems.tail; e }
16+
override def nextInt() = {
17+
val e = nextElems.head.toInt
18+
nextElems = nextElems.tail
19+
e
20+
}
21+
override def nextInt(n: Int) = {
22+
val e = nextElems.head.toInt % n
23+
nextElems = nextElems.tail
24+
e
25+
}
26+
override def nextDouble() = {
27+
val e = nextElems.head
28+
nextElems = nextElems.tail
29+
e
30+
}
1931
}
2032

2133
def centralMoment(n: Int, xs: Iterable[Double]) = {

modules/gcp/src/main/scala/com/kevel/apso/gcp/GCSBucket.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ final class GCSBucket(
219219
case ex: StorageException =>
220220
ex.getCode match {
221221
case 404 =>
222-
logger.error("The specified file does not exist", ex); true // no need to retry
222+
logger.error("The specified file does not exist", ex)
223+
true // no need to retry
223224
case 403 =>
224-
logger.error("No permission to access the file", ex); true // no need to retry
225+
logger.error("No permission to access the file", ex)
226+
true // no need to retry
225227
case _ =>
226228
logger.warn(
227229
s"""|GCS service error: ${ex.getMessage}.
@@ -232,12 +234,15 @@ final class GCSBucket(
232234
}
233235

234236
case ex: BaseServiceException =>
235-
logger.warn("An error occurred", ex); ex.isRetryable
237+
logger.warn("An error occurred", ex)
238+
ex.isRetryable
236239
}
237240

238241
private[this] def retry[T](f: => T, tries: Int = 3, sleepTime: Int = 5000): Option[T] =
239-
if (tries == 0) { logger.error("Max retries reached. Aborting GCS operation"); None }
240-
else
242+
if (tries == 0) {
243+
logger.error("Max retries reached. Aborting GCS operation")
244+
None
245+
} else
241246
Try(f) match {
242247
case Success(res) => Some(res)
243248
case Failure(e) if !handler(e) =>

0 commit comments

Comments
 (0)