From 1944d6620c413af2b0e66fe959d2ad4b0a6b8c2b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 9 May 2019 22:50:15 +0100 Subject: [PATCH] [reactives3client] objectHead response okay then return Some --- .../s3thorp/awssdk/CatsIOS3Client.scala | 7 +-- .../s3thorp/awssdk/ReactiveS3Client.scala | 1 + .../awssdk/S3CatsIOClientProvider.scala | 9 ++++ .../awssdk/UnderlyingS3AsyncClient.scala | 11 +++++ .../s3thorp/awssdk/ReactiveS3ClientTest.scala | 45 +++++++++++++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/main/scala/net/kemitix/s3thorp/awssdk/S3CatsIOClientProvider.scala create mode 100644 src/main/scala/net/kemitix/s3thorp/awssdk/UnderlyingS3AsyncClient.scala create mode 100644 src/test/scala/net/kemitix/s3thorp/awssdk/ReactiveS3ClientTest.scala diff --git a/src/main/scala/net/kemitix/s3thorp/awssdk/CatsIOS3Client.scala b/src/main/scala/net/kemitix/s3thorp/awssdk/CatsIOS3Client.scala index 953401a..46ca247 100644 --- a/src/main/scala/net/kemitix/s3thorp/awssdk/CatsIOS3Client.scala +++ b/src/main/scala/net/kemitix/s3thorp/awssdk/CatsIOS3Client.scala @@ -1,12 +1,9 @@ package net.kemitix.s3thorp.awssdk -import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient -import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient} -trait CatsIOS3Client { - - def s3Client = S3CatsIOClient(S3AsyncClient(JavaS3AsyncClient.create)) +trait CatsIOS3Client extends S3CatsIOClientProvider { + def s3Client = S3CatsIOClient(underlying) } diff --git a/src/main/scala/net/kemitix/s3thorp/awssdk/ReactiveS3Client.scala b/src/main/scala/net/kemitix/s3thorp/awssdk/ReactiveS3Client.scala index 6c4be9d..e98d6f4 100644 --- a/src/main/scala/net/kemitix/s3thorp/awssdk/ReactiveS3Client.scala +++ b/src/main/scala/net/kemitix/s3thorp/awssdk/ReactiveS3Client.scala @@ -22,6 +22,7 @@ private class ReactiveS3Client _ <- putStrLn(s" -- ${response.eTag()} : ${response.lastModified()}") } yield Some((response.eTag(), response.lastModified())) } catch { + //FIXME: this isn't catching the exception case _: NoSuchKeyException => IO(None) } } diff --git a/src/main/scala/net/kemitix/s3thorp/awssdk/S3CatsIOClientProvider.scala b/src/main/scala/net/kemitix/s3thorp/awssdk/S3CatsIOClientProvider.scala new file mode 100644 index 0000000..dd73dc1 --- /dev/null +++ b/src/main/scala/net/kemitix/s3thorp/awssdk/S3CatsIOClientProvider.scala @@ -0,0 +1,9 @@ +package net.kemitix.s3thorp.awssdk + +import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient + +trait S3CatsIOClientProvider extends UnderlyingS3AsyncClient { + + def s3Client: S3CatsIOClient + +} diff --git a/src/main/scala/net/kemitix/s3thorp/awssdk/UnderlyingS3AsyncClient.scala b/src/main/scala/net/kemitix/s3thorp/awssdk/UnderlyingS3AsyncClient.scala new file mode 100644 index 0000000..cb67314 --- /dev/null +++ b/src/main/scala/net/kemitix/s3thorp/awssdk/UnderlyingS3AsyncClient.scala @@ -0,0 +1,11 @@ +package net.kemitix.s3thorp.awssdk + +import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient +import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient +import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient} + +trait UnderlyingS3AsyncClient extends S3CatsIOClient{ + + override val underlying: S3AsyncClient = S3AsyncClient(JavaS3AsyncClient.create) + +} diff --git a/src/test/scala/net/kemitix/s3thorp/awssdk/ReactiveS3ClientTest.scala b/src/test/scala/net/kemitix/s3thorp/awssdk/ReactiveS3ClientTest.scala new file mode 100644 index 0000000..c470b9d --- /dev/null +++ b/src/test/scala/net/kemitix/s3thorp/awssdk/ReactiveS3ClientTest.scala @@ -0,0 +1,45 @@ +package net.kemitix.s3thorp.awssdk + +import java.time.Instant + +import cats.effect.IO +import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient +import org.scalatest.FunSpec +import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, HeadObjectResponse} + +class ReactiveS3ClientTest extends FunSpec { + + describe("testObjectHead") { + def invoke(self: S3Client) = { + self.objectHead("bucket", "remoteKey").unsafeRunSync() + } + + describe("when response is okay") { + val expectedHash = "hash" + val expectedLastModified = Instant.now + new ReactiveS3Client { self: S3Client => { + it("should return Some(expected values)") { + val result: Option[(String, Instant)] = invoke(self) + assertResult(Some((expectedHash, expectedLastModified)))(result) + } + } + override def s3Client: S3CatsIOClient = new S3CatsIOClient with UnderlyingS3AsyncClient { + override def headObject(headObjectRequest: HeadObjectRequest): IO[HeadObjectResponse] = + IO(HeadObjectResponse.builder(). + eTag(expectedHash). + lastModified(expectedLastModified). + build()) + } + } + + } +// describe("when throws NoSuchKeyException") { +// new ReactiveS3Client with S3CatsIOClientProvider { self => +// it("should return None") { +// assertResult(None)(result) +// } +// } +// } + } + +}