Skip to content

Commit

Permalink
Merge pull request #40 from tikurahul/benchmark-1
Browse files Browse the repository at this point in the history
Use buffered streams
  • Loading branch information
liutikas authored Dec 21, 2023
2 parents 8e694d8 + db72cc7 commit 6fe38b8
Show file tree
Hide file tree
Showing 11 changed files with 4,358 additions and 7,961 deletions.
7 changes: 1 addition & 6 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
api(libs.kotlin.stdlib)
implementation(libs.retrofit.core)
implementation(libs.retrofit.converter.gson)
implementation(libs.google.gson)
}

testing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ class FileHandleInputStream(private val file: File) : InputStream() {
return inputStream.read()
}

override fun read(byteArray: ByteArray): Int {
return inputStream.read(byteArray)
}

override fun read(byteArray: ByteArray, offset: Int, length: Int): Int {
return inputStream.read(byteArray, offset, length)
}

override fun readAllBytes(): ByteArray {
return inputStream.readAllBytes()
}

override fun readNBytes(length: Int): ByteArray {
return inputStream.readNBytes(length)
}

override fun readNBytes(byteArray: ByteArray, offset: Int, length: Int): Int {
return inputStream.readNBytes(byteArray, offset, length)
}

override fun close() {
super.close()
try {
Expand Down
6 changes: 4 additions & 2 deletions gcpbuildcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ dependencies {
// Bundle core library directly as we only get to publish one jar per plugin in Gradle Plugin Portal
bundleInside(project(":core"))
implementation(libs.google.cloud.storage)
implementation(libs.google.protobuf.java)
implementation(libs.retrofit.core)
implementation(libs.retrofit.converter.gson)
implementation(libs.google.gson)
}

gradlePlugin {
Expand All @@ -52,12 +54,12 @@ version = "1.0.0-beta05"

testing {
suites {
// Configure the built-in test suite
// Configure built-in test suite.
val test by getting(JvmTestSuite::class) {
useJUnit()
}

// Create a new test suite
// Create a new functional test suite.
val functionalTest by registering(JvmTestSuite::class) {
useJUnit()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ internal class GcpStorageService(

override fun validateConfiguration() {
if (storageOptions?.service?.get(bucketName, Storage.BucketGetOption.fields()) == null) {
throw Exception("""
throw Exception(
"""
Bucket $bucketName under project $projectId cannot be found or it is not accessible using the provided
credentials.
""".trimIndent()
Expand Down Expand Up @@ -117,6 +118,7 @@ internal class GcpStorageService(
private const val STORAGE_FULL_CONTROL = "https://www.googleapis.com/auth/devstorage.full_control"

private const val BLOB_SIZE_THRESHOLD = 50 * 1024 * 1024L
private const val BUFFER_SIZE = 32 * 1024 * 1024

private fun load(storage: StorageOptions?, blobId: BlobId, sizeThreshold: Long): InputStream? {
if (storage == null) return null
Expand All @@ -128,9 +130,12 @@ internal class GcpStorageService(
} else if (blob.size > sizeThreshold) {
val path = FileHandleInputStream.create()
blob.downloadTo(path)
// Always return a buffered stream
path.handleInputStream()
.buffered(bufferSize = BUFFER_SIZE)
} else {
blob.getContent().inputStream()
.buffered(bufferSize = BUFFER_SIZE)
}
} catch (storageException: StorageException) {
logger.debug("Unable to load Blob ($blobId)", storageException)
Expand Down Expand Up @@ -247,6 +252,7 @@ internal class GcpStorageService(
is ApplicationDefaultGcpCredentials -> {
defaultApplicationGcpCredentials(scopes, messageOnAuthenticationFailure, forceClearCache = false)
}

is ExportedKeyGcpCredentials -> {
val contents = gcpCredentials.credentials.invoke()
if (contents.isBlank()) throw GradleException("Credentials are empty.")
Expand All @@ -262,15 +268,16 @@ internal class GcpStorageService(
// in case the credentials have expired
credentials.refreshIfExpired()
} catch (e: Exception) {
throw GradleException("""
throw GradleException(
"""
"Your GCP Credentials have expired.
Please regenerate credentials and try again.
""".trimIndent()
)
}
val tokenService = TokenInfoService.tokenService()
val tokenInfoResponse = tokenService.tokenInfo(credentials.accessToken.tokenValue).execute()
if(!tokenInfoResponse.isSuccessful) {
if (!tokenInfoResponse.isSuccessful) {
throw GradleException(tokenInfoResponse.errorBody().toString())
}
credentials
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
gradle-publish = "1.1.0"
kotlin = "1.9.22"
amazon-bom = "2.20.18"
google-cloud-storage = "2.9.3"
google-cloud-storage = "2.30.1"
s3-mock = "2.11.0"
retrofit = "2.9.0"
gson = "2.10.1"
protobuf = "3.25.1"

[libraries]
kotlin-bom = { group = "org.jetbrains.kotlin", name = "kotlin-bom", version.ref = "kotlin" }
Expand All @@ -15,6 +17,8 @@ amazon-sso = { group = "software.amazon.awssdk", name = "sso", version.ref = "am
amazon-sts = { group = "software.amazon.awssdk", name = "sts", version.ref = "amazon-bom" }
adobe-s3-mock = { group = "com.adobe.testing", name = "s3mock", version.ref = "s3-mock" }
google-cloud-storage = { group = "com.google.cloud", name = "google-cloud-storage", version.ref = "google-cloud-storage" }
google-gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
google-protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
retrofit-core = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }

Expand Down
Loading

0 comments on commit 6fe38b8

Please sign in to comment.