Skip to content

Commit

Permalink
fix S3 test (#14)
Browse files Browse the repository at this point in the history
* fix S3 test

* Update build.sbt

* scalafmt

* Update application.conf

* Update S3Test.java
  • Loading branch information
pjfanning committed Jul 23, 2023
1 parent 02ec3f5 commit 010ba68
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ThisBuild / organization := "com.github.pjfanning"
ThisBuild / crossScalaVersions := List("2.12.18", "2.13.11", "3.3.0")
ThisBuild / scalaVersion := "2.13.11"

ThisBuild / tlSonatypeUseLegacyHost := true
ThisBuild / tlSonatypeUseLegacyHost := true
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec(Zulu, "8"))
ThisBuild / githubWorkflowPublishTargetBranches := Seq(
RefPredicate.Equals(Ref.Branch("main")),
Expand Down Expand Up @@ -87,7 +87,7 @@ lazy val deps = {
"software.amazon.awssdk" % "sqs" % awsSDKVersion % "test" exclude ("software.amazon.awssdk", "netty-nio-client"),
"software.amazon.awssdk" % "sns" % awsSDKVersion % "test" exclude ("software.amazon.awssdk", "netty-nio-client"),
"software.amazon.awssdk" % "kinesis" % awsSDKVersion % "test" exclude ("software.amazon.awssdk", "netty-nio-client"),
"com.dimafeng" %% "testcontainers-scala" % "0.40.14" % "test",
"com.dimafeng" %% "testcontainers-scala" % "0.40.17" % "test",
"junit" % "junit" % "4.13.2" % "test",
"org.scalatest" %% "scalatest" % "3.2.16" % "it,test",
"org.scalatestplus" %% "junit-4-13" % "3.2.16.0" % "it,test",
Expand Down
35 changes: 17 additions & 18 deletions src/test/java/com/github/pjfanning/pekkohttpspi/s3/S3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;

Expand All @@ -59,15 +60,7 @@ public void testS3() throws Exception {
try {
pekkoClient = new PekkoHttpAsyncHttpService().createAsyncHttpClientFactory().build();

client =
S3AsyncClient.builder()
.serviceConfiguration(
S3Configuration.builder().checksumValidationEnabled(false).build())
.credentialsProvider(AnonymousCredentialsProvider.create())
.endpointOverride(new URI("http://localhost:" + s3mock.getMappedPort(9090)))
.region(Region.of("s3"))
.httpClient(pekkoClient)
.build();
client = getAsyncClient(pekkoClient);

createBucketAndAssert(client);
} finally {
Expand All @@ -89,15 +82,7 @@ public void testS3WithExistingActorSystem() throws Exception {
.withActorSystem(system)
.build();

client =
S3AsyncClient.builder()
.serviceConfiguration(
S3Configuration.builder().checksumValidationEnabled(false).build())
.credentialsProvider(AnonymousCredentialsProvider.create())
.endpointOverride(new URI("http://localhost:" + s3mock.getMappedPort(9090)))
.region(Region.of("s3"))
.httpClient(pekkoClient)
.build();
client = getAsyncClient(pekkoClient);

createBucketAndAssert(client);
} finally {
Expand Down Expand Up @@ -135,6 +120,20 @@ private void createBucketAndAssert(S3AsyncClient client) throws IOException {
assertEquals(fileContent, result.asUtf8String());
}

private S3AsyncClient getAsyncClient(SdkAsyncHttpClient pekkoClient) throws URISyntaxException {
return S3AsyncClient.builder()
.serviceConfiguration(
S3Configuration.builder()
.checksumValidationEnabled(false)
.pathStyleAccessEnabled(true)
.build())
.credentialsProvider(AnonymousCredentialsProvider.create())
.endpointOverride(new URI("http://localhost:" + s3mock.getMappedPort(9090)))
.region(Region.of("s3"))
.httpClient(pekkoClient)
.build();
}

String randomString(int len) {
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) sb.append(AB.charAt(rnd.nextInt(AB.length())));
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pekko.http.client.parsing.max-content-length = 150m
12 changes: 9 additions & 3 deletions src/test/scala/com/github/pjfanning/pekkohttpspi/s3/TestS3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class TestS3 extends BaseAwsClientTest[S3AsyncClient] {
result.response().contentLength() shouldEqual fileContent.getBytes().length
}

"multipart upload" ignore withClient { implicit client =>
"multipart upload" in withClient { implicit client =>
val bucketName = createBucket()
val randomFile = File.createTempFile("aws1", Random.alphanumeric.take(5).mkString)
val fileContent = Random.alphanumeric.take(1000).mkString
val fileContent = (0 to 1000000).mkString
val fileWriter = new FileWriter(randomFile)
fileWriter.write(fileContent)
fileWriter.flush()
Expand Down Expand Up @@ -137,7 +137,13 @@ class TestS3 extends BaseAwsClientTest[S3AsyncClient] {

val client = S3AsyncClient
.builder()
.serviceConfiguration(S3Configuration.builder().checksumValidationEnabled(false).build())
.serviceConfiguration(
S3Configuration
.builder()
.checksumValidationEnabled(false)
.pathStyleAccessEnabled(true)
.build()
)
.credentialsProvider(AnonymousCredentialsProvider.create)
.endpointOverride(endpoint)
.httpClient(pekkoClient)
Expand Down

0 comments on commit 010ba68

Please sign in to comment.