Skip to content

Commit

Permalink
refactor(saga/test): replace deprecated method during upgrade to Kotl…
Browse files Browse the repository at this point in the history
…in 1.5.32 (#6102)

While upgrading Kotlin 1.5.32, encounter below error in clouddriver-saga and clouddriver-saga-test module:
```
> Task :clouddriver-saga:compileKotlin FAILED
e: /clouddriver/clouddriver-saga/src/main/kotlin/com/netflix/spinnaker/clouddriver/saga/flow/SagaFlowIterator.kt: (185, 8): Using 'min(): T?' is an error. Use minOrNull instead.
e: /clouddriver/clouddriver-saga/src/main/kotlin/com/netflix/spinnaker/clouddriver/saga/models/Saga.kt: (62, 63): Using 'max(): T?' is an error. Use maxOrNull instead.
```

```
> Task :clouddriver-saga-test:compileKotlin FAILED
'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
e: /clouddriver/clouddriver-saga-test/src/main/kotlin/com/netflix/spinnaker/clouddriver/saga/TestingSagaRepository.kt: (38, 78): Using 'max(): T?' is an error. Use maxOrNull instead.
```
To fix this error, replaced the deprecated method.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
j-sandy and mergify[bot] authored Nov 16, 2023
1 parent 01718c3 commit 44124e2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestingSagaRepository : SagaRepository {
override fun save(saga: Saga, additionalEvents: List<SagaEvent>) {
sagas.putIfAbsent(createId(saga), saga)

val currentSequence = saga.getEvents().map { it.getMetadata().sequence }.max() ?: 0
val currentSequence = saga.getEvents().map { it.getMetadata().sequence }.maxOrNull() ?: 0
val originatingVersion = saga.getVersion()

saga.getPendingEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class SagaFlowIterator(

index = listOf(SagaCommandCompletedEventSeeker(), SagaCommandEventSeeker())
.mapNotNull { it.invoke(index, steps, saga)?.coerceAtLeast(0) }
.min()
.minOrNull()
?: index

if (index != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Saga(
fun isCompensating(): Boolean = events.filterIsInstance<SagaRollbackStarted>().isNotEmpty()

fun getVersion(): Long {
return events.map { it.getMetadata().originatingVersion }.max()?.let { it + 1 } ?: 0
return events.map { it.getMetadata().originatingVersion }.maxOrNull()?.let { it + 1 } ?: 0
}

fun addEvent(event: SagaEvent) {
Expand Down

0 comments on commit 44124e2

Please sign in to comment.