-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from loicmathieu/feat/spanner-emulator
Spanner emulator
- Loading branch information
Showing
4 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...n-tests/main/src/test/java/io/quarkiverse/googlecloudservices/it/SpannerResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.quarkiverse.googlecloudservices.it; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; | ||
|
||
import com.google.cloud.spanner.Spanner; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class SpannerResourceTest { | ||
private static final int GRPC_PORT = 9010; | ||
private static final int HTTP_PORT = 9020; | ||
|
||
private static GenericContainer<?> GCLOUD_CONTAINER; | ||
|
||
@Inject | ||
Spanner spanner; | ||
|
||
@BeforeAll | ||
public static void startGcloudContainer() { | ||
GCLOUD_CONTAINER = new GenericContainer<>("roryq/spanner-emulator") | ||
.withExposedPorts(GRPC_PORT) | ||
.withExposedPorts(HTTP_PORT) | ||
.withEnv("SPANNER_DATABASE_ID", "test-database") | ||
.withEnv("SPANNER_INSTANCE_ID", "test-instance") | ||
.withEnv("SPANNER_PROJECT_ID", "test-project") | ||
.waitingFor(new LogMessageWaitStrategy().withRegEx("(?s).*gRPC server listening.*$")); | ||
List<String> portBindings = new ArrayList<>(); | ||
portBindings.add("9010:9010"); | ||
portBindings.add("9020:9020"); | ||
GCLOUD_CONTAINER.setPortBindings(portBindings); | ||
GCLOUD_CONTAINER.start(); | ||
} | ||
|
||
@AfterAll | ||
public static void stopGcloudContainer() { | ||
if (GCLOUD_CONTAINER != null) { | ||
GCLOUD_CONTAINER.stop(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSpanner() throws ExecutionException, InterruptedException, TimeoutException { | ||
// create the table DDL | ||
spanner.getDatabaseAdminClient() | ||
.updateDatabaseDdl("test-instance", "test-database", | ||
Arrays.asList( | ||
"CREATE TABLE Singers ( SingerId INT64 NOT NULL, FirstName STRING(1024), LastName STRING(1024), SingerInfo BYTES(MAX) ) PRIMARY KEY (SingerId)"), | ||
null) | ||
.get(1, TimeUnit.SECONDS); | ||
|
||
given() | ||
.when().get("/spanner") | ||
.then() | ||
.statusCode(200); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...rc/main/java/io/quarkiverse/googlecloudservices/spanner/runtime/SpannerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkiverse.googlecloudservices.spanner.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot(name = "google.cloud.spanner", phase = ConfigPhase.RUN_TIME) | ||
public class SpannerConfiguration { | ||
/** | ||
* Enable emulator and set its host. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> emulatorHost; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters