Skip to content

Commit

Permalink
- fix ktlint error
Browse files Browse the repository at this point in the history
  • Loading branch information
ykhfree committed Jan 3, 2025
1 parent f3e9e5a commit 484d4d8
Show file tree
Hide file tree
Showing 26 changed files with 52 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class ReqShieldConfiguration<T>(
val globalUnLockFunction: (suspend (String) -> Boolean)? = null,
val isLocalLock: Boolean = true,
val lockTimeoutMillis: Long = DEFAULT_LOCK_TIMEOUT_MILLIS,
val decisionForUpdate: Int = DEFAULT_DECISION_FOR_UPDATE, // %
val decisionForUpdate: Int = DEFAULT_DECISION_FOR_UPDATE,
val keyLock: KeyLock =
if (isLocalLock) {
KeyLocalLock(lockTimeoutMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class ReqShieldConfiguration<T>(
val isLocalLock: Boolean = true,
val lockTimeoutMillis: Long = DEFAULT_LOCK_TIMEOUT_MILLIS,
val scheduler: Scheduler = Schedulers.boundedElastic(),
val decisionForUpdate: Int = DEFAULT_DECISION_FOR_UPDATE, // %
val decisionForUpdate: Int = DEFAULT_DECISION_FOR_UPDATE,
val keyLock: KeyLock =
if (isLocalLock) {
KeyLocalLock(lockTimeoutMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ val ProceedingJoinPoint.coroutineContinuation: Continuation<Any?>
val ProceedingJoinPoint.coroutineArgs: Array<Any?>
get() = this.args.sliceArray(0 until this.args.size - 1)

suspend fun ProceedingJoinPoint.proceedCoroutine(
args: Array<Any?> = this.coroutineArgs,
): Any? =
suspend fun ProceedingJoinPoint.proceedCoroutine(args: Array<Any?> = this.coroutineArgs): Any? =
suspendCoroutineUninterceptedOrReturn { continuation ->
this.proceed(args + continuation)
}

fun ProceedingJoinPoint.runCoroutine(
block: suspend () -> Any?,
): Any? =
fun ProceedingJoinPoint.runCoroutine(block: suspend () -> Any?): Any? =
block.startCoroutineUninterceptedOrReturn(this.coroutineContinuation)
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ data class ReqShieldConfiguration<T>(
val globalLockFunction: ((String, Long) -> Boolean)? = null,
val globalUnLockFunction: ((String) -> Boolean)? = null,
val isLocalLock: Boolean = true,
val lockTimeoutMillis: Long = DEFAULT_LOCK_TIMEOUT_MILLIS, // for local and global lock
val lockTimeoutMillis: Long = DEFAULT_LOCK_TIMEOUT_MILLIS,
val executor: ScheduledExecutorService =
Executors.newScheduledThreadPool(
Runtime.getRuntime().availableProcessors() * 10,
),
val decisionForUpdate: Int = DEFAULT_DECISION_FOR_UPDATE, // %
val decisionForUpdate: Int = DEFAULT_DECISION_FOR_UPDATE,
val keyLock: KeyLock =
if (isLocalLock) {
KeyLocalLock(lockTimeoutMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ReqShieldBeanConfiguration<T>(
ReqShield(
ReqShieldConfiguration(
setCacheFunction = {
key,
value,
timeToLiveMillis,
key,
value,
timeToLiveMillis,
->
redisTemplate.opsForValue().setIfAbsent(key, value, Duration.ofMillis(timeToLiveMillis)) ?: false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.linecorp.cse.reqshield.spring3.mvc.example.dto

data class Product(
val productId: String,
val productName: String
val productName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import com.linecorp.cse.reqshield.support.BaseReqShieldTest
import com.linecorp.cse.reqshield.support.model.Product
import com.linecorp.cse.reqshield.support.redis.AbstractRedisTest
import org.awaitility.Awaitility.await
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit.jupiter.SpringExtension
import java.time.Duration
import java.util.*
import java.util.UUID
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class SpringWebfluxApplication

fun main(args: Array<String>) {
runApplication<SpringWebfluxApplication>(*args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ReqShieldBeanConfiguration<T>(
ReqShield(
ReqShieldConfiguration(
setCacheFunction = {
key,
value,
timeToLiveMillis,
key,
value,
timeToLiveMillis,
->
reactiveRedisOperations.opsForValue().setIfAbsent(key, value, Duration.ofMillis(timeToLiveMillis)) ?: Mono.just(false)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.linecorp.cse.reqshield.spring3.webflux.example.dto

data class Product(
val productId: String,
val productName: String
val productName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class SpringWebfluxCoroutineApplication

fun main(args: Array<String>) {
runApplication<SpringWebfluxCoroutineApplication>(*args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class ReqShieldBeanConfiguration<T>(
ReqShield(
ReqShieldConfiguration(
setCacheFunction = {
key,
value,
timeToLiveMillis,
key,
value,
timeToLiveMillis,
->
reactiveRedisOperations.opsForValue().setAndAwait(
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.linecorp.cse.reqshield.spring3.webflux.kotlin.coroutine.example.dto

data class Product(
val productId: String,
val productName: String
val productName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class ReqShieldBeanConfiguration<T>(
ReqShield(
ReqShieldConfiguration(
setCacheFunction = {
key,
value,
timeToLiveMillis,
key,
value,
timeToLiveMillis,
->
redisTemplate.opsForValue().setIfAbsent(key, value, Duration.ofMillis(timeToLiveMillis)) ?: false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package com.linecorp.cse.reqshield.dto


data class Product(
val productId: String,
val productName: String
val productName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class SpringWebfluxApplication

fun main(args: Array<String>) {
runApplication<SpringWebfluxApplication>(*args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class ReqShieldBeanConfiguration<T>(
ReqShield(
ReqShieldConfiguration(
setCacheFunction = {
key,
value,
timeToLiveMillis,
key,
value,
timeToLiveMillis,
->
reactiveRedisOperations.opsForValue().setIfAbsent(key, value, Duration.ofMillis(timeToLiveMillis)) ?: Mono.just(false)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ package com.linecorp.cse.reqshield.spring.webflux.example.dto

data class Product(
val productId: String,
val productName: String
val productName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class ReqShieldBeanConfiguration<T>(
ReqShield(
ReqShieldConfiguration(
setCacheFunction = {
key,
value,
timeToLiveMillis,
key,
value,
timeToLiveMillis,
->
reactiveRedisOperations.opsForValue().setAndAwait(
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ private val log = LoggerFactory.getLogger(ClientException::class.java)
class ClientException(
val errorCode: ErrorCode,
override val message: String = errorCode.message,
originErrorMessage: String? = null
): RuntimeException(message) {

originErrorMessage: String? = null,
) : RuntimeException(message) {
init {
log.error("[Req-Shield] errorCode : {}, message : {}, originErrorMessage : {}", errorCode.code, message, originErrorMessage)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package com.linecorp.cse.reqshield.support.exception.code

enum class ErrorCode(
val code: String,
val message: String
val message: String,
) {
SUPPLIER_ERROR("1001", "An error occurred in the supplier function provided by client."),
GET_CACHE_ERROR("1002", "An error occurred in the get cache function provided by client."),
SET_CACHE_ERROR("1003", "An error occurred in the set cache function provided by client."),
DOES_NOT_EXIST_GLOBAL_LOCK_FUNCTION("1004", "If isLocalLock is false, globalLockFunction must be implemented."),
DOES_NOT_EXIST_GLOBAL_UNLOCK_FUNCTION("1005", "If isLocalLock is false, globalUnLockFunction must be implemented."),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package com.linecorp.cse.reqshield.support.utils

fun decideToUpdateCache(createdAt: Long, timeToLiveMillis: Long, decisionForUpdate: Int): Boolean {
fun decideToUpdateCache(
createdAt: Long,
timeToLiveMillis: Long,
decisionForUpdate: Int,
): Boolean {
val currentTime = System.currentTimeMillis()
val passedDuration = currentTime - createdAt

return passedDuration >= timeToLiveMillis * (decisionForUpdate / 100.0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ package com.linecorp.cse.reqshield.support.utils
import java.time.LocalDateTime
import java.time.ZoneId

fun nowToEpochTime() = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
fun nowToEpochTime() = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue

class CommonUtilsTest {

@Test
fun decideToUpdateCacheTest() {
val expireTime = Duration.ofMinutes(1).toMillis()
Expand All @@ -43,4 +42,4 @@ class CommonUtilsTest {
val decide = decideToUpdateCache(createdAt.toInstant().toEpochMilli(), expireTime, 80)
assertFalse(decide)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
package com.linecorp.cse.reqshield.support

interface BaseKeyLockTest {

val lockTimeoutMillis: Long
get() = 3000L

fun `test concurrency with one key`()

fun `test concurrency with two key`()

fun `test lock expiration`()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.springframework.test.context.ContextConfiguration
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers


@Testcontainers
@ContextConfiguration(initializers = [AbstractRedisTest.Companion.Initializer::class])
abstract class AbstractRedisTest {
Expand All @@ -32,7 +31,6 @@ abstract class AbstractRedisTest {
private val redisContainer = RedisContainer.instance

internal class Initializer : ApplicationContextInitializer<ConfigurableApplicationContext> {

override fun initialize(context: ConfigurableApplicationContext) {
val env = context.environment

Expand All @@ -45,4 +43,4 @@ abstract class AbstractRedisTest {
}
}
}
}
}

0 comments on commit 484d4d8

Please sign in to comment.