Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

라이브러리 버전 업데이트 #49

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object AndroidX {
}

object Kotlin {
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:1.8.10"
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:1.8.22"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed

}

object Javax {
Expand All @@ -53,14 +53,15 @@ object Retrofit {
const val base = "com.squareup.retrofit2:retrofit:2.9.0"
const val rxjava = "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
const val kotlinx = "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
const val okhttp = "com.squareup.okhttp3:okhttp:4.9.1"
const val okhttpLogger = "com.squareup.okhttp3:logging-interceptor:4.9.1"
const val okhttp = "com.squareup.okhttp3:okhttp:4.12.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed

const val okhttpLogger = "com.squareup.okhttp3:logging-interceptor:4.12.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed

}

object Glide {
const val base = "com.github.bumptech.glide:glide:4.11.0"
const val okhttp = "com.github.bumptech.glide:okhttp3-integration:4.11.0"
const val compiler = "com.github.bumptech.glide:compiler:4.11.0"
const val base = "com.github.bumptech.glide:glide:4.16.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed

const val okhttp = "com.github.bumptech.glide:okhttp3-integration:4.16.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed

// const val compiler = "com.github.bumptech.glide:compiler:4.15.1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:spacing-between-declarations-with-comments reported by reviewdog 🐶
Declarations and declarations with comments should have an empty space between.

const val compiler = "com.github.bumptech.glide:ksp:4.16.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:property-naming reported by reviewdog 🐶
Property name should use the screaming snake case notation when the value can not be changed

const val compose = "com.github.bumptech.glide:compose:1.0.0-beta01"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.hmju.core.models.base.JSendObj
import io.reactivex.rxjava3.core.Single
import okhttp3.ResponseBody
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.QueryMap

Expand Down Expand Up @@ -37,19 +38,34 @@ internal interface ApiService {
@GET("/api/v1/memo/aos")
fun fetchAndroid(): Single<ResponseBody>

@GET("/api/v1/til/auth/jwt/test")
@GET("/api/v1/til/auth/jwt/test/{delay}")
fun fetchJwtTest(
@Query("time_delay") delay: Int = 0
@Path("delay") delay: Int = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): Single<JSendObj<JwtTokenTestEntity>>

@GET("/api/v1/til/auth/jwt/test1")
@GET("/api/v1/til/auth/jwt/test1/{delay}")
fun fetchJwtTest1(
@Query("time_delay") delay: Int = 0
@Path("delay") delay: Int = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): Single<JSendObj<JwtTokenTestEntity>>

@GET("/api/v1/til/auth/jwt/test2")
@GET("/api/v1/til/auth/jwt/test2/{delay}")
fun fetchJwtTest2(
@Query("time_delay") delay: Int = 0
@Path("delay") delay: Int = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): Single<JSendObj<JwtTokenTestEntity>>

@GET("/api/v1/til/auth/jwt/test/{delay}")
suspend fun fetchJwtTestCo(
@Path("delay") delay: Int = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): ApiResponse<JSendObj<JwtTokenTestEntity>>

@GET("/api/v1/til/auth/jwt/test1/{delay}")
suspend fun fetchJwtTest1Co(
@Path("delay") delay: Int = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): ApiResponse<JSendObj<JwtTokenTestEntity>>

@GET("/api/v1/til/auth/jwt/test2/{delay}")
suspend fun fetchJwtTest2Co(
@Path("delay") delay: Int = 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): ApiResponse<JSendObj<JwtTokenTestEntity>>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶
Unexpected blank line(s) before "}"

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.kotlin.addTo
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -102,7 +105,8 @@ internal class NetworkV2FragmentViewModel @Inject constructor(
Flowable.interval(0, 333L, TimeUnit.MILLISECONDS)
.takeUntil { System.currentTimeMillis() >= endTimeMs }
.doOnNext {
startJwtRequest(it).subscribe().addTo(compositeDisposable)
startJwtRequestCo(it)
// startJwtRequest(it).subscribe().addTo(compositeDisposable)
}
// .flatMap { startJwtRequest(it).toFlowable() }
.doOnNext {
Expand Down Expand Up @@ -134,6 +138,18 @@ internal class NetworkV2FragmentViewModel @Inject constructor(
}
}

private fun startJwtRequestCo(percent: Long) {
viewModelScope.launch(Dispatchers.IO) {
val startNs = System.nanoTime()
val work1 = async { apiService.fetchJwtTestCo(300) }
val work2 = async { apiService.fetchJwtTest1Co(1000) }
val work3 = async { apiService.fetchJwtTest2Co(200) }
awaitAll(work1, work2, work3)
val tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs)
Timber.d("작업 완료 ${tookMs}ms ${Thread.currentThread()}")
}
}

fun startRequest() {
Single.mergeDelayError(
reqTest1(),
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = "TIL"
rootProject.name = "til"

include(
":app",
Expand Down
2 changes: 2 additions & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ dependencies {
androidTestImplementation(Retrofit.rxjava)
androidTestImplementation(Retrofit.kotlinx)
androidTestImplementation(Retrofit.okhttpLogger)
testImplementation("com.google.code.gson:gson:2.10.1")
testImplementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")

/**
* Unit Test
Expand Down
68 changes: 66 additions & 2 deletions test/src/test/java/com/hmju/test/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.hmju.test

import org.junit.Test

import com.google.gson.GsonBuilder
import com.google.gson.annotations.SerializedName
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import org.junit.Assert.*
import org.junit.Test
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

/**
* Example local unit test, which will execute on the development machine (host).
Expand All @@ -14,4 +25,57 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}

data class Response(
@SerializedName("time")
val date: Date
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

)

@Serializable
data class ResponseV2(
@SerialName("time")
val time: Instant = Clock.System.now()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

) {
fun getDate(): Date {
return Date(time.toEpochMilliseconds())
}
}

@Test
fun differ_gson_kotlinx() {
assert(getGsonTime() == getKotlinxTime())
}

private fun getGsonTime(): Long {
val str = """
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:string-template-indent reported by reviewdog 🐶
Expected newline before multiline string template

{
"time": "2024-04-02T12:14:52.395Z"
}
""".trimIndent()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:string-template-indent reported by reviewdog 🐶
Unexpected indent of raw string literal

val gson = GsonBuilder()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

.setDateFormat("yyyy-MM-dd HH:mm:ss")
.create()
val res = gson.fromJson(str, Response::class.java)
val sdf = SimpleDateFormat("yyyy년 MM월 dd일 HH:mm:ss", Locale.getDefault())
println("Gson ${sdf.format(res.date)}")
return res.date.time
}

@OptIn(ExperimentalSerializationApi::class)
private fun getKotlinxTime(): Long {
val str = """
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:string-template-indent reported by reviewdog 🐶
Expected newline before multiline string template

{
"time": "2024-04-02T12:14:52.395Z"
}
""".trimIndent()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:string-template-indent reported by reviewdog 🐶
Unexpected indent of raw string literal

val json = Json {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

isLenient = true // Json 큰따옴표 느슨하게 체크.
ignoreUnknownKeys = true // Field 값이 없는 경우 무시
coerceInputValues = true // "null" 이 들어간경우 default Argument 값으로 대체
}
val res = json.decodeFromString<ResponseV2>(str)
val sdf = SimpleDateFormat("yyyy년 MM월 dd일 HH:mm:ss", Locale.getDefault())
println("Kotlinx ${sdf.format(res.getDate())}")
return res.getDate().time
}
}
Loading