Skip to content

Add fake-gcs-server #1028

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.stream.connectors.googlecloud.storage

import com.dimafeng.testcontainers.GenericContainer
import org.testcontainers.containers.wait.strategy.Wait

import java.time.Duration

class FakeGCSContainer(bucketsToCreate: List[String], location: Option[String]) extends GenericContainer(
"fsouza/fake-gcs-server:1.52",
exposedPorts = List(4443),
waitStrategy = Some(Wait.forHttp("/storage/v1/b").forPort(4443).withStartupTimeout(Duration.ofSeconds(10))),
command = List(
"-scheme", "http"
) ++ location.map(List("-location", _)).getOrElse(Nil)
) {
def getHostAddress: String =
s"http://${container.getHost}:${container.getMappedPort(4443)}"

override def start(): Unit = {
super.start()
if (bucketsToCreate.nonEmpty) {
container.execInContainer("mkdir", "data")
bucketsToCreate.foreach { bucket =>
container.execInContainer(s"mkdir", s"/data/$bucket")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.stream.connectors.googlecloud.storage

import com.dimafeng.testcontainers.ForAllTestContainer
import org.apache.pekko
import org.apache.pekko.stream.connectors.google.auth.NoCredentials
import org.apache.pekko.stream.connectors.google.{ GoogleSettings, RequestSettings, RetrySettings }
import org.apache.pekko.testkit.TestKitBase
import org.scalatest.Suite

import java.time.Duration
import java.time.temporal.ChronoUnit
import java.util.Optional

trait FakeGCSServerTest extends ForAllTestContainer with TestKitBase { self: Suite =>
override lazy val container: FakeGCSContainer =
new FakeGCSContainer(List("connectors", "pekko-connectors-rewrite"), Some("europe-west1"))

lazy val googleSettings =
GoogleSettings.create(
"test-project",
NoCredentials("", ""),
RequestSettings.create(
Optional.empty(),
Optional.empty(),
prettyPrint = false,
15728640, // 15 MiB
RetrySettings.create(
6,
Duration.of(1, ChronoUnit.SECONDS),
Duration.of(1, ChronoUnit.MINUTES),
0.2d
),
Optional.empty()
)
)

lazy val gCSSettings =
GCSSettings(container.getHostAddress, GCSSettings().basePath)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.stream.connectors.googlecloud.storage.impl

import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.connectors.google.GoogleSettings
import org.apache.pekko.stream.connectors.googlecloud.storage.scaladsl.GCStorage
import org.apache.pekko.stream.connectors.googlecloud.storage.{ FakeGCSServerTest, GCSSettings, GCStorageSettings }

class FakeGCStorageStreamIntegrationSpec extends GCStorageStreamIntegrationSpec with FakeGCSServerTest {
override def settings: GoogleSettings = googleSettings
override def gcsSettings: GCSSettings = gCSSettings

override implicit def system: ActorSystem = actorSystem

override def bucket = "connectors"
override def rewriteBucket = "pekko-connectors-rewrite"
override def projectId = settings.projectId

}
Loading