@@ -21,7 +21,7 @@
com.google.cloud
google-cloud-bigtable-deps-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml
index be934dc8e6..6b7339d3db 100644
--- a/google-cloud-bigtable/pom.xml
+++ b/google-cloud-bigtable/pom.xml
@@ -2,7 +2,7 @@
4.0.0
google-cloud-bigtable
- 2.7.0
+ 2.7.1-SNAPSHOT
jar
Google Cloud Bigtable
https://github.com/googleapis/java-bigtable
@@ -12,11 +12,11 @@
com.google.cloud
google-cloud-bigtable-parent
- 2.7.0
+ 2.7.1-SNAPSHOT
- 2.7.0
+ 2.7.1-SNAPSHOT
google-cloud-bigtable
@@ -43,14 +43,14 @@
com.google.cloud
google-cloud-bigtable-deps-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
com.google.cloud
google-cloud-bigtable-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java
index 986ff6a835..19a80eabc5 100644
--- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java
@@ -20,6 +20,6 @@
@InternalApi("For internal use only")
public final class Version {
// {x-version-update-start:google-cloud-bigtable:current}
- public static String VERSION = "2.7.0";
+ public static String VERSION = "2.7.1-SNAPSHOT";
// {x-version-update-end}
}
diff --git a/grpc-google-cloud-bigtable-admin-v2/pom.xml b/grpc-google-cloud-bigtable-admin-v2/pom.xml
index ec3499f2e8..6a73cdd6a4 100644
--- a/grpc-google-cloud-bigtable-admin-v2/pom.xml
+++ b/grpc-google-cloud-bigtable-admin-v2/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-bigtable-admin-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
grpc-google-cloud-bigtable-admin-v2
GRPC library for grpc-google-cloud-bigtable-admin-v2
com.google.cloud
google-cloud-bigtable-parent
- 2.7.0
+ 2.7.1-SNAPSHOT
@@ -18,14 +18,14 @@
com.google.cloud
google-cloud-bigtable-deps-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
com.google.cloud
google-cloud-bigtable-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
diff --git a/grpc-google-cloud-bigtable-v2/pom.xml b/grpc-google-cloud-bigtable-v2/pom.xml
index de9fbccd64..eda126957f 100644
--- a/grpc-google-cloud-bigtable-v2/pom.xml
+++ b/grpc-google-cloud-bigtable-v2/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-bigtable-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
grpc-google-cloud-bigtable-v2
GRPC library for grpc-google-cloud-bigtable-v2
com.google.cloud
google-cloud-bigtable-parent
- 2.7.0
+ 2.7.1-SNAPSHOT
@@ -18,14 +18,14 @@
com.google.cloud
google-cloud-bigtable-deps-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
com.google.cloud
google-cloud-bigtable-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
diff --git a/pom.xml b/pom.xml
index fa3b1e8c93..d3e5fee8c6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
google-cloud-bigtable-parent
pom
- 2.7.0
+ 2.7.1-SNAPSHOT
Google Cloud Bigtable Parent
https://github.com/googleapis/java-bigtable
@@ -152,27 +152,27 @@
com.google.api.grpc
proto-google-cloud-bigtable-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
com.google.api.grpc
proto-google-cloud-bigtable-admin-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
com.google.api.grpc
grpc-google-cloud-bigtable-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
com.google.api.grpc
grpc-google-cloud-bigtable-admin-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
com.google.cloud
google-cloud-bigtable
- 2.7.0
+ 2.7.1-SNAPSHOT
diff --git a/proto-google-cloud-bigtable-admin-v2/pom.xml b/proto-google-cloud-bigtable-admin-v2/pom.xml
index 94152d9de0..fa77ac2f76 100644
--- a/proto-google-cloud-bigtable-admin-v2/pom.xml
+++ b/proto-google-cloud-bigtable-admin-v2/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-bigtable-admin-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
proto-google-cloud-bigtable-admin-v2
PROTO library for proto-google-cloud-bigtable-admin-v2
com.google.cloud
google-cloud-bigtable-parent
- 2.7.0
+ 2.7.1-SNAPSHOT
@@ -18,14 +18,14 @@
com.google.cloud
google-cloud-bigtable-deps-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
com.google.cloud
google-cloud-bigtable-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
diff --git a/proto-google-cloud-bigtable-v2/pom.xml b/proto-google-cloud-bigtable-v2/pom.xml
index 252dbedf8a..f7e0fd4a42 100644
--- a/proto-google-cloud-bigtable-v2/pom.xml
+++ b/proto-google-cloud-bigtable-v2/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-bigtable-v2
- 2.7.0
+ 2.7.1-SNAPSHOT
proto-google-cloud-bigtable-v2
PROTO library for proto-google-cloud-bigtable-v2
com.google.cloud
google-cloud-bigtable-parent
- 2.7.0
+ 2.7.1-SNAPSHOT
@@ -18,14 +18,14 @@
com.google.cloud
google-cloud-bigtable-deps-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
com.google.cloud
google-cloud-bigtable-bom
- 2.7.0
+ 2.7.1-SNAPSHOT
pom
import
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 2947938372..b7c0d7d127 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud
google-cloud-bigtable
- 2.7.0
+ 2.7.1-SNAPSHOT
diff --git a/versions.txt b/versions.txt
index 6bd15bdaf1..b27f1923ae 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,9 +1,9 @@
# Format:
# module:released-version:current-version
-google-cloud-bigtable:2.7.0:2.7.0
-grpc-google-cloud-bigtable-admin-v2:2.7.0:2.7.0
-grpc-google-cloud-bigtable-v2:2.7.0:2.7.0
-proto-google-cloud-bigtable-admin-v2:2.7.0:2.7.0
-proto-google-cloud-bigtable-v2:2.7.0:2.7.0
-google-cloud-bigtable-emulator:0.144.0:0.144.0
+google-cloud-bigtable:2.7.0:2.7.1-SNAPSHOT
+grpc-google-cloud-bigtable-admin-v2:2.7.0:2.7.1-SNAPSHOT
+grpc-google-cloud-bigtable-v2:2.7.0:2.7.1-SNAPSHOT
+proto-google-cloud-bigtable-admin-v2:2.7.0:2.7.1-SNAPSHOT
+proto-google-cloud-bigtable-v2:2.7.0:2.7.1-SNAPSHOT
+google-cloud-bigtable-emulator:0.144.0:0.144.1-SNAPSHOT
From 7daaa5a12bce0673d8eff18c4835679e51dcd91c Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Thu, 26 May 2022 00:20:28 +0200
Subject: [PATCH 2/8] chore(deps): update dependency
com.google.cloud:google-cloud-bigtable to v2.7.0 (#1262)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-bigtable](https://togithub.com/googleapis/java-bigtable) | `2.6.2` -> `2.7.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox. ⚠ **Warning**: custom changes will be lost.
---
This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigtable).
---
README.md | 6 +++---
samples/install-without-bom/pom.xml | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 5aeda8ccdf..adca7f0b22 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ If you are using Maven without BOM, add this to your dependencies:
com.google.cloud
google-cloud-bigtable
- 2.6.2
+ 2.7.0
```
@@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-bigtable'
If you are using Gradle without BOM, add this to your dependencies
```Groovy
-implementation 'com.google.cloud:google-cloud-bigtable:2.6.2'
+implementation 'com.google.cloud:google-cloud-bigtable:2.7.0'
```
If you are using SBT, add this to your dependencies
```Scala
-libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.6.2"
+libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "2.7.0"
```
## Authentication
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 0bda72b385..c1a210bcd2 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud
google-cloud-bigtable
- 2.6.2
+ 2.7.0
From 6304d88bb2cdcaf2daf96ebdc16f53ee79b8738d Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Thu, 26 May 2022 00:26:17 +0200
Subject: [PATCH 3/8] test(deps): update dependency
com.google.cloud:google-cloud-conformance-tests to v0.3.0 (#1263)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-conformance-tests](https://togithub.com/googleapis/java-shared-config) | `0.2.11` -> `0.3.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox. ⚠ **Warning**: custom changes will be lost.
---
This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigtable).
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d3e5fee8c6..a8f4cedfc9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -178,7 +178,7 @@
com.google.cloud
google-cloud-conformance-tests
- 0.2.11
+ 0.3.0
com.google.truth
From 6fdc2c1a33e140466734debed22d50a7be726d87 Mon Sep 17 00:00:00 2001
From: Igor Bernstein
Date: Thu, 26 May 2022 14:48:14 -0400
Subject: [PATCH 4/8] feat: split emulator into core without deps and a higher
level wrapper with grpc helpers (#1264)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Currently the emulator exists in a single artifact with optional deps. The reason for this is that bigtable-hbase needs the emulator w/o grpc. However this is causing issues in graalvm packaging in #1234. This PR makes this easier to manage: a -core artifact without dependencies that just wraps the golang binary that bigtable-hbase can use and a wrapper that has a hard dep on grpc & gax.
This is technically a breaking change but the emulator artifact is pre-GA an is marked with BetaApi
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
Fixes # ☕️
If you write sample code, please follow the [samples format](
https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
---
.repo-metadata.json | 2 +-
google-cloud-bigtable-bom/pom.xml | 5 +
google-cloud-bigtable-emulator-core/pom.xml | 75 ++++++
.../emulator/core/EmulatorController.java | 251 ++++++++++++++++++
google-cloud-bigtable-emulator/pom.xml | 28 +-
.../cloud/bigtable/emulator/v2/Emulator.java | 219 ++-------------
pom.xml | 1 +
versions.txt | 1 +
8 files changed, 366 insertions(+), 216 deletions(-)
create mode 100644 google-cloud-bigtable-emulator-core/pom.xml
create mode 100644 google-cloud-bigtable-emulator-core/src/main/java/com/google/cloud/bigtable/emulator/core/EmulatorController.java
diff --git a/.repo-metadata.json b/.repo-metadata.json
index 0fd6f4361b..e81a672baa 100644
--- a/.repo-metadata.json
+++ b/.repo-metadata.json
@@ -12,6 +12,6 @@
"codeowner_team": "@googleapis/api-bigtable",
"api_id": "bigtable.googleapis.com",
"library_type": "GAPIC_COMBO",
- "extra_versioned_modules": "google-cloud-bigtable-emulator",
+ "extra_versioned_modules": "google-cloud-bigtable-emulator,google-cloud-bigtable-emulator-core",
"excluded_poms": "google-cloud-bigtable-bom"
}
diff --git a/google-cloud-bigtable-bom/pom.xml b/google-cloud-bigtable-bom/pom.xml
index e9a8d0aafe..c1b3e40ed9 100644
--- a/google-cloud-bigtable-bom/pom.xml
+++ b/google-cloud-bigtable-bom/pom.xml
@@ -69,6 +69,11 @@
google-cloud-bigtable-emulator
0.144.1-SNAPSHOT
+
+ com.google.cloud
+ google-cloud-bigtable-emulator-core
+ 0.144.1-SNAPSHOT
+
com.google.api.grpc
grpc-google-cloud-bigtable-admin-v2
diff --git a/google-cloud-bigtable-emulator-core/pom.xml b/google-cloud-bigtable-emulator-core/pom.xml
new file mode 100644
index 0000000000..a93a4ec393
--- /dev/null
+++ b/google-cloud-bigtable-emulator-core/pom.xml
@@ -0,0 +1,75 @@
+
+
+ 4.0.0
+
+
+ google-cloud-bigtable-parent
+ com.google.cloud
+ 2.7.1-SNAPSHOT
+
+
+ google-cloud-bigtable-emulator-core
+ 0.144.1-SNAPSHOT
+
+
+ A Java wrapper for the Cloud Bigtable emulator.
+
+
+ https://github.com/googleapis/java-bigtable
+
+ scm:git:git@github.com:googleapis/java-bigtable.git
+ scm:git:git@github.com:googleapis/java-bigtable.git
+ https://github.com/googleapis/java-bigtable
+ HEAD
+
+
+
+ igorberstein
+ Igor Bernstein
+ igorbernstein@google.com
+ Google
+
+ Developer
+
+
+
+
+
+ 8
+ 8
+
+
+
+
+
+
+ com.google.cloud
+ google-cloud-gcloud-maven-plugin
+ 0.1.5
+
+
+
+ gen-sources
+ generate-resources
+
+ download
+
+
+
+ bigtable-darwin-arm
+ bigtable-darwin-x86_64
+ bigtable-linux-arm
+ bigtable-linux-x86
+ bigtable-linux-x86_64
+ bigtable-windows-x86
+ bigtable-windows-x86_64
+
+
+
+
+
+
+
+
diff --git a/google-cloud-bigtable-emulator-core/src/main/java/com/google/cloud/bigtable/emulator/core/EmulatorController.java b/google-cloud-bigtable-emulator-core/src/main/java/com/google/cloud/bigtable/emulator/core/EmulatorController.java
new file mode 100644
index 0000000000..9ac9245f22
--- /dev/null
+++ b/google-cloud-bigtable-emulator-core/src/main/java/com/google/cloud/bigtable/emulator/core/EmulatorController.java
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed 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
+ *
+ * https://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 com.google.cloud.bigtable.emulator.core;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.nio.file.Path;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.concurrent.TimeoutException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Wraps the Bigtable emulator in a java api.
+ *
+ * This class will use the golang binaries embedded in this jar to launch the emulator as an
+ * external process and redirect its output to a {@link Logger}.
+ */
+public class EmulatorController {
+ private static final Logger LOGGER = Logger.getLogger(EmulatorController.class.getName());
+
+ private final Path executable;
+ private Process process;
+ private boolean isStopped = true;
+ private Thread shutdownHook;
+
+ private int port;
+
+ public static EmulatorController createFromPath(Path path) {
+ return new EmulatorController(path);
+ }
+ /**
+ * Create a new instance of emulator. The emulator will use the bundled binaries in this jar.
+ * Please note that the emulator is created in a stopped state, please use {@link #start()} after
+ * creating it.
+ */
+ public static EmulatorController createBundled() throws IOException {
+ String resourcePath = getBundledResourcePath();
+
+ File tmpEmulator = File.createTempFile("cbtemulator", "");
+ tmpEmulator.deleteOnExit();
+
+ try (InputStream is = EmulatorController.class.getResourceAsStream(resourcePath);
+ FileOutputStream os = new FileOutputStream(tmpEmulator)) {
+
+ if (is == null) {
+ throw new FileNotFoundException(
+ "Failed to find the bundled emulator binary: " + resourcePath);
+ }
+
+ byte[] buff = new byte[2048];
+ int length;
+
+ while ((length = is.read(buff)) != -1) {
+ os.write(buff, 0, length);
+ }
+ }
+ tmpEmulator.setExecutable(true);
+
+ return new EmulatorController(tmpEmulator.toPath());
+ }
+
+ private EmulatorController(Path executable) {
+ this.executable = executable;
+ }
+
+ public synchronized boolean isRunning() {
+ return !isStopped;
+ }
+ /** Starts the emulator process and waits for it to be ready. */
+ public synchronized void start() throws IOException, TimeoutException, InterruptedException {
+ if (!isStopped) {
+ throw new IllegalStateException("Emulator is already started");
+ }
+ this.port = getAvailablePort();
+
+ // Try to align the localhost address across java & golang emulator
+ // This should fix issues on systems that default to ipv4 but the jvm is started with
+ // -Djava.net.preferIPv6Addresses=true
+ Optional localhostAddress = Optional.empty();
+ try {
+ localhostAddress = Optional.of(InetAddress.getByName(null).getHostAddress());
+ } catch (UnknownHostException e) {
+ }
+
+ // Workaround https://bugs.openjdk.java.net/browse/JDK-8068370
+ for (int attemptsLeft = 3; process == null; attemptsLeft--) {
+ try {
+ String cmd = executable.toString();
+ if (localhostAddress.isPresent()) {
+ cmd += String.format(" -host [%s]", localhostAddress.get());
+ }
+ cmd += String.format(" -port %d", port);
+ process = Runtime.getRuntime().exec(cmd);
+ } catch (IOException e) {
+ if (attemptsLeft > 0) {
+ Thread.sleep(1000);
+ continue;
+ }
+ throw e;
+ }
+ }
+ pipeStreamToLog(process.getInputStream(), Level.INFO);
+ pipeStreamToLog(process.getErrorStream(), Level.WARNING);
+ isStopped = false;
+
+ shutdownHook =
+ new Thread(
+ () -> {
+ if (!isStopped) {
+ isStopped = true;
+ process.destroy();
+ }
+ });
+
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+
+ waitForPort(port);
+ }
+
+ /** Stops the emulator process. */
+ public synchronized void stop() {
+ if (isStopped) {
+ throw new IllegalStateException("Emulator already stopped");
+ }
+
+ try {
+ Runtime.getRuntime().removeShutdownHook(shutdownHook);
+ shutdownHook = null;
+ } finally {
+ isStopped = true;
+ process.destroy();
+ }
+ }
+
+ public synchronized int getPort() {
+ if (isStopped) {
+ throw new IllegalStateException("Emulator is not running");
+ }
+ return port;
+ }
+ //
+
+ /** Gets the current platform, which will be used to select the appropriate emulator binary. */
+ private static String getBundledResourcePath() {
+ String unformattedOs = System.getProperty("os.name", "unknown").toLowerCase(Locale.ENGLISH);
+ String os;
+ String suffix = "";
+
+ if (unformattedOs.contains("mac") || unformattedOs.contains("darwin")) {
+ os = "darwin";
+ } else if (unformattedOs.contains("win")) {
+ os = "windows";
+ suffix = ".exe";
+ } else if (unformattedOs.contains("linux")) {
+ os = "linux";
+ } else {
+ throw new UnsupportedOperationException(
+ "Emulator is not supported on your platform: " + unformattedOs);
+ }
+
+ String unformattedArch = System.getProperty("os.arch");
+ String arch;
+
+ switch (unformattedArch) {
+ case "x86":
+ arch = "x86";
+ break;
+ case "x86_64":
+ case "amd64":
+ arch = "x86_64";
+ break;
+ case "aarch64":
+ arch = "arm";
+ break;
+ default:
+ throw new UnsupportedOperationException("Unsupported architecture: " + unformattedArch);
+ }
+
+ return String.format(
+ "/gcloud/bigtable-%s-%s/platform/bigtable-emulator/cbtemulator%s", os, arch, suffix);
+ }
+
+ /** Gets a random open port number. */
+ private static int getAvailablePort() {
+ try (ServerSocket serverSocket = new ServerSocket(0)) {
+ return serverSocket.getLocalPort();
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to find open port");
+ }
+ }
+
+ /** Waits for a port to open. It's used to wait for the emulator's gRPC server to be ready. */
+ private static void waitForPort(int port) throws InterruptedException, TimeoutException {
+ for (int i = 0; i < 100; i++) {
+ try (Socket ignored = new Socket("localhost", port)) {
+ return;
+ } catch (IOException e) {
+ Thread.sleep(200);
+ }
+ }
+
+ throw new TimeoutException("Timed out waiting for server to start");
+ }
+
+ /** Creates a thread that will pipe an {@link InputStream} to this class' Logger. */
+ private static void pipeStreamToLog(final InputStream stream, final Level level) {
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+
+ Thread thread =
+ new Thread(
+ () -> {
+ try {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ LOGGER.log(level, line);
+ }
+ } catch (IOException e) {
+ if (!"Stream closed".equals(e.getMessage())) {
+ LOGGER.log(Level.WARNING, "Failed to read process stream", e);
+ }
+ }
+ });
+ thread.setDaemon(true);
+ thread.start();
+ }
+ //
+}
diff --git a/google-cloud-bigtable-emulator/pom.xml b/google-cloud-bigtable-emulator/pom.xml
index 0da780bd8a..bccb3aeaf0 100644
--- a/google-cloud-bigtable-emulator/pom.xml
+++ b/google-cloud-bigtable-emulator/pom.xml
@@ -69,8 +69,8 @@
org.apache.maven.plugins
maven-dependency-plugin
-
- io.grpc:grpc-netty-shaded
+
+ com.google.api:gax-grpc
@@ -96,16 +96,28 @@
-
+
+ com.google.cloud
+ google-cloud-bigtable-emulator-core
+ 0.144.1-SNAPSHOT
+
+
com.google.api
api-common
+
+ com.google.guava
+ guava
+
io.grpc
grpc-api
-
- provided
+
+
+
+ com.google.api
+ gax-grpc
@@ -160,11 +172,5 @@
-
-
- io.grpc
- grpc-netty-shaded
- test
-
diff --git a/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java b/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java
index b43322831c..b30fad7ebb 100644
--- a/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java
+++ b/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java
@@ -16,29 +16,18 @@
package com.google.cloud.bigtable.emulator.v2;
import com.google.api.core.BetaApi;
+import com.google.cloud.bigtable.emulator.core.EmulatorController;
+import com.google.common.base.Preconditions;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
import java.nio.file.Path;
-import java.util.Locale;
-import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Wraps the Bigtable emulator in a java api.
+ * Wraps the Bigtable emulator in a java api and decorates it with grpc channel builders.
*
* This class will use the golang binaries embedded in this jar to launch the emulator as an
* external process and redirect its output to a {@link Logger}.
@@ -47,17 +36,12 @@
public class Emulator {
private static final Logger LOGGER = Logger.getLogger(Emulator.class.getName());
- private final Path executable;
- private Process process;
- private boolean isStopped = true;
- private Thread shutdownHook;
-
- private int port;
+ private final EmulatorController controller;
private ManagedChannel dataChannel;
private ManagedChannel adminChannel;
public static Emulator createFromPath(Path path) {
- return new Emulator(path);
+ return new Emulator(EmulatorController.createFromPath(path));
}
/**
* Create a new instance of emulator. The emulator will use the bundled binaries in this jar.
@@ -65,98 +49,23 @@ public static Emulator createFromPath(Path path) {
* creating it.
*/
public static Emulator createBundled() throws IOException {
- String resourcePath = getBundledResourcePath();
-
- File tmpEmulator = File.createTempFile("cbtemulator", "");
- tmpEmulator.deleteOnExit();
-
- try (InputStream is = Emulator.class.getResourceAsStream(resourcePath);
- FileOutputStream os = new FileOutputStream(tmpEmulator)) {
-
- if (is == null) {
- throw new FileNotFoundException(
- "Failed to find the bundled emulator binary: " + resourcePath);
- }
-
- byte[] buff = new byte[2048];
- int length;
-
- while ((length = is.read(buff)) != -1) {
- os.write(buff, 0, length);
- }
- }
- tmpEmulator.setExecutable(true);
-
- return new Emulator(tmpEmulator.toPath());
+ return new Emulator(EmulatorController.createBundled());
}
- private Emulator(Path executable) {
- this.executable = executable;
+ private Emulator(EmulatorController controller) {
+ this.controller = controller;
}
/** Starts the emulator process and waits for it to be ready. */
public synchronized void start() throws IOException, TimeoutException, InterruptedException {
- if (!isStopped) {
- throw new IllegalStateException("Emulator is already started");
- }
- this.port = getAvailablePort();
-
- // Try to align the localhost address across java & golang emulator
- // This should fix issues on systems that default to ipv4 but the jvm is started with
- // -Djava.net.preferIPv6Addresses=true
- Optional localhostAddress = Optional.empty();
- try {
- localhostAddress = Optional.of(InetAddress.getByName(null).getHostAddress());
- } catch (UnknownHostException e) {
- }
-
- // Workaround https://bugs.openjdk.java.net/browse/JDK-8068370
- for (int attemptsLeft = 3; process == null; attemptsLeft--) {
- try {
- String cmd = executable.toString();
- if (localhostAddress.isPresent()) {
- cmd += String.format(" -host [%s]", localhostAddress.get());
- }
- cmd += String.format(" -port %d", port);
- process = Runtime.getRuntime().exec(cmd);
- } catch (IOException e) {
- if (attemptsLeft > 0) {
- Thread.sleep(1000);
- continue;
- }
- throw e;
- }
- }
- pipeStreamToLog(process.getInputStream(), Level.INFO);
- pipeStreamToLog(process.getErrorStream(), Level.WARNING);
- isStopped = false;
-
- shutdownHook =
- new Thread() {
- @Override
- public void run() {
- if (!isStopped) {
- isStopped = true;
- process.destroy();
- }
- }
- };
-
- Runtime.getRuntime().addShutdownHook(shutdownHook);
-
- waitForPort(port);
+ controller.start();
}
/** Stops the emulator process. */
public synchronized void stop() {
- if (isStopped) {
- throw new IllegalStateException("Emulator already stopped");
- }
+ controller.stop();
try {
- Runtime.getRuntime().removeShutdownHook(shutdownHook);
- shutdownHook = null;
-
// Shutdown channels in parallel
if (dataChannel != null) {
dataChannel.shutdownNow();
@@ -177,27 +86,19 @@ public synchronized void stop() {
} catch (InterruptedException e) {
LOGGER.warning("Interrupted while waiting for client channels to close");
Thread.currentThread().interrupt();
- } finally {
- isStopped = true;
- process.destroy();
}
}
public synchronized int getPort() {
- if (isStopped) {
- throw new IllegalStateException("Emulator is not running");
- }
- return port;
+ return controller.getPort();
}
public synchronized ManagedChannel getDataChannel() {
- if (isStopped) {
- throw new IllegalStateException("Emulator is not running");
- }
+ Preconditions.checkState(controller.isRunning(), "Emulator is not running");
if (dataChannel == null) {
dataChannel =
- newChannelBuilder(port)
+ newChannelBuilder(controller.getPort())
.maxInboundMessageSize(256 * 1024 * 1024)
.keepAliveTimeout(10, TimeUnit.SECONDS)
.keepAliveTime(10, TimeUnit.SECONDS)
@@ -208,110 +109,20 @@ public synchronized ManagedChannel getDataChannel() {
}
public synchronized ManagedChannel getAdminChannel() {
- if (isStopped) {
- throw new IllegalStateException("Emulator is not running");
- }
+ Preconditions.checkState(controller.isRunning(), "Emulator is not running");
if (adminChannel == null) {
- adminChannel = newChannelBuilder(port).build();
+ adminChannel = newChannelBuilder(controller.getPort()).build();
}
return adminChannel;
}
-
//
- /** Gets the current platform, which will be used to select the appropriate emulator binary. */
- private static String getBundledResourcePath() {
- String unformattedOs = System.getProperty("os.name", "unknown").toLowerCase(Locale.ENGLISH);
- String os;
- String suffix = "";
-
- if (unformattedOs.contains("mac") || unformattedOs.contains("darwin")) {
- os = "darwin";
- } else if (unformattedOs.contains("win")) {
- os = "windows";
- suffix = ".exe";
- } else if (unformattedOs.contains("linux")) {
- os = "linux";
- } else {
- throw new UnsupportedOperationException(
- "Emulator is not supported on your platform: " + unformattedOs);
- }
-
- String unformattedArch = System.getProperty("os.arch");
- String arch;
-
- switch (unformattedArch) {
- case "x86":
- arch = "x86";
- break;
- case "x86_64":
- case "amd64":
- arch = "x86_64";
- break;
- case "aarch64":
- arch = "arm";
- break;
- default:
- throw new UnsupportedOperationException("Unsupported architecture: " + unformattedArch);
- }
-
- return String.format(
- "/gcloud/bigtable-%s-%s/platform/bigtable-emulator/cbtemulator%s", os, arch, suffix);
- }
-
- /** Gets a random open port number. */
- private static int getAvailablePort() {
- try (ServerSocket serverSocket = new ServerSocket(0)) {
- return serverSocket.getLocalPort();
- } catch (IOException e) {
- throw new RuntimeException("Failed to find open port");
- }
- }
-
- /** Waits for a port to open. It's used to wait for the emulator's gRPC server to be ready. */
- private static void waitForPort(int port) throws InterruptedException, TimeoutException {
- for (int i = 0; i < 100; i++) {
- try (Socket ignored = new Socket("localhost", port)) {
- return;
- } catch (IOException e) {
- Thread.sleep(200);
- }
- }
-
- throw new TimeoutException("Timed out waiting for server to start");
- }
-
/** Creates a {@link io.grpc.ManagedChannelBuilder} preconfigured for the emulator's port. */
private static ManagedChannelBuilder> newChannelBuilder(int port) {
// NOTE: usePlaintext is currently @ExperimentalAPI.
// See https://github.com/grpc/grpc-java/issues/1772 for discussion
return ManagedChannelBuilder.forAddress("localhost", port).usePlaintext();
}
-
- /** Creates a thread that will pipe an {@link java.io.InputStream} to this class' Logger. */
- private static void pipeStreamToLog(final InputStream stream, final Level level) {
- final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
-
- Thread thread =
- new Thread(
- new Runnable() {
- @Override
- public void run() {
- try {
- String line;
- while ((line = reader.readLine()) != null) {
- LOGGER.log(level, line);
- }
- } catch (IOException e) {
- if (!"Stream closed".equals(e.getMessage())) {
- LOGGER.log(Level.WARNING, "Failed to read process stream", e);
- }
- }
- }
- });
- thread.setDaemon(true);
- thread.start();
- }
//
}
diff --git a/pom.xml b/pom.xml
index a8f4cedfc9..6942e50725 100644
--- a/pom.xml
+++ b/pom.xml
@@ -355,6 +355,7 @@
grpc-google-cloud-bigtable-v2
proto-google-cloud-bigtable-admin-v2
proto-google-cloud-bigtable-v2
+ google-cloud-bigtable-emulator-core
google-cloud-bigtable-emulator
google-cloud-bigtable-bom
google-cloud-bigtable-deps-bom
diff --git a/versions.txt b/versions.txt
index b27f1923ae..94ce02e11e 100644
--- a/versions.txt
+++ b/versions.txt
@@ -7,3 +7,4 @@ grpc-google-cloud-bigtable-v2:2.7.0:2.7.1-SNAPSHOT
proto-google-cloud-bigtable-admin-v2:2.7.0:2.7.1-SNAPSHOT
proto-google-cloud-bigtable-v2:2.7.0:2.7.1-SNAPSHOT
google-cloud-bigtable-emulator:0.144.0:0.144.1-SNAPSHOT
+google-cloud-bigtable-emulator-core:2.7.0:2.7.1-SNAPSHOT
From 560a5018087c6cdc46e2c6150e6ed41075007177 Mon Sep 17 00:00:00 2001
From: Mridula <66699525+mpeddada1@users.noreply.github.com>
Date: Thu, 26 May 2022 16:47:27 -0400
Subject: [PATCH 5/8] fix(java): enable skipped tests for Native Image testing
(#1234)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* make gax-grpc a test scope dependency
* add resource config
* skip tests that use mockito
* fix dependency issue
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* add gax as main dependency; include supported architectures
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* fix dependency issue
* add documentation; rever unnecessary changes
* add documentation for exclusion
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* resolve conflicts
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* relocate gax-grpc dependency within pom.xml
* try making gax-grpc provided
* explicitly include netty native image configurations
* remove gax from used dep setting
* deps: update dependency com.google.cloud:google-cloud-shared-dependencies to v2.11.0 (#1253)
* feat: add build scripts for native image testing in Java 17 (#1440) (#1255)
Source-Link: https://github.com/googleapis/synthtool/commit/505ce5a7edb58bf6d9d4de10b4bb4e81000ae324
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:2567a120ce90fadb6201999b87d649d9f67459de28815ad239bce9ebfaa18a74
Co-authored-by: Owl Bot
* deps: update dependency com.google.cloud:google-cloud-shared-dependencies to v2.12.0 (#1256)
[](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-shared-dependencies](https://togithub.com/googleapis/java-shared-dependencies) | `2.11.0` -> `2.12.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) |
---
### Release Notes
googleapis/java-shared-dependencies
### [`v2.12.0`](https://togithub.com/googleapis/java-shared-dependencies/blob/HEAD/CHANGELOG.md#2120-httpsgithubcomgoogleapisjava-shared-dependenciescomparev2110v2120-2022-05-19)
[Compare Source](https://togithub.com/googleapis/java-shared-dependencies/compare/v2.11.0...v2.12.0)
##### Features
- add build scripts for native image testing in Java 17 ([#1440](https://togithub.com/googleapis/java-shared-dependencies/issues/1440)) ([#697](https://togithub.com/googleapis/java-shared-dependencies/issues/697)) ([f10ec4e](https://togithub.com/googleapis/java-shared-dependencies/commit/f10ec4e664d8fde868effe366b7182a5fad08dd0))
##### Dependencies
- update gax.version to v2.18.1 ([#695](https://togithub.com/googleapis/java-shared-dependencies/issues/695)) ([09bc61c](https://togithub.com/googleapis/java-shared-dependencies/commit/09bc61c9152a99bfe87554a07324f15ae6217d6e))
- update google.core.version to v2.7.1 ([#698](https://togithub.com/googleapis/java-shared-dependencies/issues/698)) ([43de259](https://togithub.com/googleapis/java-shared-dependencies/commit/43de2593f1a6e8fa5e34799364ab683246ddd449))
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
---
- [ ] If you want to rebase/retry this PR, click this checkbox.
---
This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigtable).
* build(fix): add in IT args for graalvm presubmit (#1258)
* build(fix): add in IT args for graalvm presubmit
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* Update owlbot.py
* it changes
* update graalvm config
* owlbot
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
* Update graalvm-native.cfg
Co-authored-by: Owl Bot
* remove netty configs
* fix pom.xml
Co-authored-by: Owl Bot
Co-authored-by: WhiteSource Renovate
Co-authored-by: gcf-owl-bot[bot] <78513119+gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: kolea2 <45548808+kolea2@users.noreply.github.com>
---
CONTRIBUTING.md | 9 +++++++-
google-cloud-bigtable-emulator/pom.xml | 1 +
.../resource-config.json | 21 +++++++++++++++++++
...t.java => ITBigtableEmulatorRuleTest.java} | 2 +-
... => BigtableInstanceAdminClientTests.java} | 7 ++++++-
...ava => BigtableTableAdminClientTests.java} | 7 ++++++-
...Test.java => BigtableDataClientTests.java} | 7 ++++++-
7 files changed, 49 insertions(+), 5 deletions(-)
create mode 100644 google-cloud-bigtable-emulator/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-bigtable-emulator/resource-config.json
rename google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/{BigtableEmulatorRuleTest.java => ITBigtableEmulatorRuleTest.java} (98%)
rename google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/{BigtableInstanceAdminClientTest.java => BigtableInstanceAdminClientTests.java} (99%)
rename google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/{BigtableTableAdminClientTest.java => BigtableTableAdminClientTests.java} (99%)
rename google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/{BigtableDataClientTest.java => BigtableDataClientTests.java} (98%)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5d05ad023a..bfda3e3022 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -68,4 +68,11 @@ mvn install -DskipUnitTests
# To skip all tests
mvn install -DskipTests
-```
\ No newline at end of file
+```
+
+
+## Native Image Testing
+Native Image testing is enabled for tests that follow a particular naming
+convention (`IT*` or `*ClientTest`). Unit tests that use Mockito or EasyMock
+have been excluded for the time being as they are not compatible with native
+image compilation.
\ No newline at end of file
diff --git a/google-cloud-bigtable-emulator/pom.xml b/google-cloud-bigtable-emulator/pom.xml
index bccb3aeaf0..cbf7c840c5 100644
--- a/google-cloud-bigtable-emulator/pom.xml
+++ b/google-cloud-bigtable-emulator/pom.xml
@@ -106,6 +106,7 @@
com.google.api
api-common
+
com.google.guava
guava
diff --git a/google-cloud-bigtable-emulator/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-bigtable-emulator/resource-config.json b/google-cloud-bigtable-emulator/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-bigtable-emulator/resource-config.json
new file mode 100644
index 0000000000..aa986d630d
--- /dev/null
+++ b/google-cloud-bigtable-emulator/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-bigtable-emulator/resource-config.json
@@ -0,0 +1,21 @@
+{
+ "resources":{
+ "includes":[
+ {
+ "pattern":"\\Qgcloud/bigtable-linux-x86_64/platform/bigtable-emulator/cbtemulator\\E"
+ },
+ {
+ "pattern":"\\Qgcloud/bigtable-darwin-x86_64/platform/bigtable-emulator/cbtemulator\\E"
+ },
+ {
+ "pattern":"\\Qgcloud/bigtable-linux-x86/platform/bigtable-emulator/cbtemulator\\E"
+ },
+ {
+ "pattern": "\\Qgcloud/bigtable-windows-x86_64/platform/bigtable-emulator/cbtemulator.exe\\E"
+ },
+ {
+ "pattern":"\\Qgcloud/bigtable-linux-arm/platform/bigtable-emulator/cbtemulator\\E"
+ }
+ ]},
+ "bundles":[]
+}
\ No newline at end of file
diff --git a/google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/BigtableEmulatorRuleTest.java b/google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/ITBigtableEmulatorRuleTest.java
similarity index 98%
rename from google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/BigtableEmulatorRuleTest.java
rename to google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/ITBigtableEmulatorRuleTest.java
index f0eb965299..00e2969f80 100644
--- a/google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/BigtableEmulatorRuleTest.java
+++ b/google-cloud-bigtable-emulator/src/test/java/com/google/cloud/bigtable/emulator/v2/ITBigtableEmulatorRuleTest.java
@@ -38,7 +38,7 @@
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
-public class BigtableEmulatorRuleTest {
+public class ITBigtableEmulatorRuleTest {
@Rule public BigtableEmulatorRule bigtableRule = BigtableEmulatorRule.create();
private BigtableTableAdminBlockingStub tableAdminStub;
private BigtableBlockingStub dataStub;
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java
similarity index 99%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java
index 8a21f95c1a..7e5d3a8b05 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java
@@ -81,7 +81,12 @@
import org.mockito.stubbing.Answer;
@RunWith(JUnit4.class)
-public class BigtableInstanceAdminClientTest {
+/**
+ * Tests for {@link BigtableTableAdminClient}. This test class uses Mockito so it has been
+ * explicitly excluded from Native Image testing by not following the naming convention of (IT* and
+ * *ClientTest).
+ */
+public class BigtableInstanceAdminClientTests {
@Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN);
private static final String PROJECT_ID = "my-project";
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java
similarity index 99%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java
index 6e6b445758..f3d2261869 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java
@@ -91,7 +91,12 @@
import org.threeten.bp.Instant;
@RunWith(JUnit4.class)
-public class BigtableTableAdminClientTest {
+/**
+ * Tests for {@link BigtableTableAdminClient}. This test class uses Mockito so it has been
+ * explicitly excluded from Native Image testing by not following the naming convention of (IT* and
+ * *ClientTest).
+ */
+public class BigtableTableAdminClientTests {
@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule();
private static final String PROJECT_ID = "my-project";
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java
similarity index 98%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java
index 940d632c12..34c9a29d71 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTests.java
@@ -56,7 +56,12 @@
import org.mockito.stubbing.Answer;
@RunWith(JUnit4.class)
-public class BigtableDataClientTest {
+/**
+ * Tests for {@link BigtableDataClient}. This test class uses Mockito so it has been explicitly
+ * excluded from Native Image testing by not following the naming convention of (IT* and
+ * *ClientTest).
+ */
+public class BigtableDataClientTests {
@Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN);
From a7b8358159416b15ff53fc30342f0c7bb4005d4b Mon Sep 17 00:00:00 2001
From: Igor Bernstein
Date: Thu, 26 May 2022 18:30:12 -0400
Subject: [PATCH 6/8] chore: fix version tag (#1266)
This was introduced in #1264
---
google-cloud-bigtable-emulator/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/google-cloud-bigtable-emulator/pom.xml b/google-cloud-bigtable-emulator/pom.xml
index cbf7c840c5..641754876b 100644
--- a/google-cloud-bigtable-emulator/pom.xml
+++ b/google-cloud-bigtable-emulator/pom.xml
@@ -99,7 +99,7 @@
com.google.cloud
google-cloud-bigtable-emulator-core
- 0.144.1-SNAPSHOT
+ 0.144.1-SNAPSHOT
From ae0d60d127950a9f42ed80d132a8cec8a339ed93 Mon Sep 17 00:00:00 2001
From: Igor Bernstein
Date: Fri, 27 May 2022 15:52:18 -0400
Subject: [PATCH 7/8] chore(test): deflake and refactor test fake service
helper (#1267)
There is a race condition when running unit tests in parallel that where they can pick the same port for a fake service. This PR adds a retry loop to let them resolve the race.
It also refactors the helper into a builder instead, avoiding the need for multiple constructors and empty args
---
.../v2/BigtableDataClientFactoryTest.java | 49 +++++------
.../bigtable/data/v2/FakeServiceBuilder.java | 88 +++++++++++++++++++
.../bigtable/data/v2/FakeServiceHelper.java | 75 ----------------
.../v2/stub/BigtableChannelPrimerTest.java | 15 ++--
.../EnhancedBigtableStubCloseRetryTest.java | 12 +--
.../stub/EnhancedBigtableStubCloseTest.java | 12 +--
.../v2/stub/EnhancedBigtableStubTest.java | 26 +++---
.../bigtable/data/v2/stub/HeadersTest.java | 21 +++--
.../metrics/HeaderTracerCallableTest.java | 64 +++++++-------
.../v2/stub/metrics/MetricsTracerTest.java | 12 +--
.../metrics/StatsHeadersCallableTest.java | 12 +--
11 files changed, 197 insertions(+), 189 deletions(-)
create mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceBuilder.java
delete mode 100644 google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceHelper.java
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java
index fd75bed956..67d4183b8b 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java
@@ -35,11 +35,9 @@
import com.google.cloud.bigtable.data.v2.internal.NameUtil;
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import io.grpc.Attributes;
-import io.grpc.BindableService;
-import io.grpc.ServerInterceptor;
+import io.grpc.Server;
import io.grpc.ServerTransportFilter;
import io.grpc.stub.StreamObserver;
import java.io.IOException;
@@ -68,7 +66,7 @@ public class BigtableDataClientFactoryTest {
private static final String DEFAULT_INSTANCE_ID = "fake-instance";
private static final String DEFAULT_APP_PROFILE_ID = "fake-app-profile";
- private FakeServiceHelper serviceHelper;
+ private Server server;
private FakeBigtableService service;
private TransportChannelProvider transportChannelProvider;
@@ -77,7 +75,6 @@ public class BigtableDataClientFactoryTest {
private WatchdogProvider watchdogProvider;
private ApiClock apiClock;
private BigtableDataSettings defaultSettings;
- private int port;
private final BlockingQueue setUpAttributes = new LinkedBlockingDeque<>();
private final BlockingQueue terminateAttributes = new LinkedBlockingDeque<>();
@@ -85,29 +82,25 @@ public class BigtableDataClientFactoryTest {
@Before
public void setUp() throws IOException {
service = new FakeBigtableService();
- ServerTransportFilter transportFilter =
- new ServerTransportFilter() {
- @Override
- public Attributes transportReady(Attributes transportAttrs) {
- setUpAttributes.add(transportAttrs);
- return super.transportReady(transportAttrs);
- }
-
- @Override
- public void transportTerminated(Attributes transportAttrs) {
- terminateAttributes.add(transportAttrs);
- }
- };
- serviceHelper =
- new FakeServiceHelper(
- ImmutableList.of(),
- transportFilter,
- ImmutableList.of(service));
- port = serviceHelper.getPort();
- serviceHelper.start();
+ server =
+ FakeServiceBuilder.create(service)
+ .addTransportFilter(
+ new ServerTransportFilter() {
+ @Override
+ public Attributes transportReady(Attributes transportAttrs) {
+ setUpAttributes.add(transportAttrs);
+ return super.transportReady(transportAttrs);
+ }
+
+ @Override
+ public void transportTerminated(Attributes transportAttrs) {
+ terminateAttributes.add(transportAttrs);
+ }
+ })
+ .start();
BigtableDataSettings.Builder builder =
- BigtableDataSettings.newBuilderForEmulator(port)
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(DEFAULT_PROJECT_ID)
.setInstanceId(DEFAULT_INSTANCE_ID)
.setAppProfileId(DEFAULT_APP_PROFILE_ID);
@@ -152,7 +145,7 @@ public void transportTerminated(Attributes transportAttrs) {
@After
public void tearDown() {
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
@@ -234,7 +227,7 @@ public void testCreateWithRefreshingChannel() throws Exception {
String[] tableIds = {"fake-table1", "fake-table2"};
int poolSize = 3;
BigtableDataSettings.Builder builder =
- BigtableDataSettings.newBuilderForEmulator(port)
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(DEFAULT_PROJECT_ID)
.setInstanceId(DEFAULT_INSTANCE_ID)
.setAppProfileId(DEFAULT_APP_PROFILE_ID)
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceBuilder.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceBuilder.java
new file mode 100644
index 0000000000..5edcca2f07
--- /dev/null
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceBuilder.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed 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
+ *
+ * https://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 com.google.cloud.bigtable.data.v2;
+
+import io.grpc.BindableService;
+import io.grpc.Server;
+import io.grpc.ServerBuilder;
+import io.grpc.ServerInterceptor;
+import io.grpc.ServerTransportFilter;
+import java.io.IOException;
+import java.net.BindException;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FakeServiceBuilder {
+ private final List interceptors = new ArrayList<>();
+ private final List services = new ArrayList<>();
+ private final List transportFilters = new ArrayList<>();
+
+ public static FakeServiceBuilder create(BindableService... services) {
+ return new FakeServiceBuilder(services);
+ }
+
+ private FakeServiceBuilder(BindableService[] services) {
+ for (BindableService service : services) {
+ this.addService(service);
+ }
+ }
+
+ public FakeServiceBuilder intercept(ServerInterceptor interceptor) {
+ interceptors.add(interceptor);
+ return this;
+ }
+
+ public FakeServiceBuilder addService(BindableService service) {
+ services.add(service);
+ return this;
+ }
+
+ public FakeServiceBuilder addTransportFilter(ServerTransportFilter transportFilter) {
+ transportFilters.add(transportFilter);
+ return this;
+ }
+
+ public Server start() throws IOException {
+ IOException lastError = null;
+
+ for (int i = 0; i < 10; i++) {
+ try {
+ return startWithoutRetries();
+ } catch (IOException e) {
+ lastError = e;
+ if (!(e.getCause() instanceof BindException)) {
+ break;
+ }
+ }
+ }
+
+ throw lastError;
+ }
+
+ private Server startWithoutRetries() throws IOException {
+ int port;
+ try (ServerSocket ss = new ServerSocket(0)) {
+ port = ss.getLocalPort();
+ }
+ ServerBuilder> builder = ServerBuilder.forPort(port);
+ interceptors.forEach(builder::intercept);
+ services.forEach(builder::addService);
+ transportFilters.forEach(builder::addTransportFilter);
+
+ return builder.build().start();
+ }
+}
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceHelper.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceHelper.java
deleted file mode 100644
index f0dd2f8809..0000000000
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/FakeServiceHelper.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2020 Google LLC
- *
- * Licensed 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
- *
- * https://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 com.google.cloud.bigtable.data.v2;
-
-import com.google.common.collect.ImmutableList;
-import io.grpc.BindableService;
-import io.grpc.Server;
-import io.grpc.ServerBuilder;
-import io.grpc.ServerInterceptor;
-import io.grpc.ServerTransportFilter;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.List;
-
-/** Utility class to setup a fake grpc server on a random port. */
-public class FakeServiceHelper {
- private final int port;
- private final Server server;
-
- public FakeServiceHelper(BindableService... services) throws IOException {
- this(ImmutableList.of(), null, ImmutableList.copyOf(services));
- }
-
- public FakeServiceHelper(ServerInterceptor interceptor, BindableService... services)
- throws IOException {
- this(ImmutableList.of(interceptor), null, ImmutableList.copyOf(services));
- }
-
- public FakeServiceHelper(
- List interceptors,
- ServerTransportFilter transportFilter,
- List services)
- throws IOException {
- try (ServerSocket ss = new ServerSocket(0)) {
- port = ss.getLocalPort();
- }
- ServerBuilder builder = ServerBuilder.forPort(port);
- for (ServerInterceptor interceptor : interceptors) {
- builder = builder.intercept(interceptor);
- }
-
- if (transportFilter != null) {
- builder = builder.addTransportFilter(transportFilter);
- }
- for (BindableService service : services) {
- builder = builder.addService(service);
- }
- server = builder.build();
- }
-
- public int getPort() {
- return port;
- }
-
- public void start() throws IOException {
- server.start();
- }
-
- public void shutdown() {
- server.shutdown();
- }
-}
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimerTest.java
index 3748a5adff..7195e4105f 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimerTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimerTest.java
@@ -25,11 +25,12 @@
import com.google.bigtable.v2.ReadRowsResponse;
import com.google.bigtable.v2.RowFilter;
import com.google.bigtable.v2.RowSet;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.common.collect.ImmutableList;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
+import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
@@ -60,15 +61,15 @@ public class BigtableChannelPrimerTest {
BigtableChannelPrimer primer;
ManagedChannel channel;
private LogHandler logHandler;
- private FakeServiceHelper serviceHelper;
+ private Server server;
@Before
public void setup() throws IOException {
fakeService = new FakeService();
metadataInterceptor = new MetadataInterceptor();
- serviceHelper = new FakeServiceHelper(metadataInterceptor, fakeService);
- serviceHelper.start();
+ server = FakeServiceBuilder.create(fakeService).intercept(metadataInterceptor).start();
+
primer =
BigtableChannelPrimer.create(
OAuth2Credentials.create(new AccessToken(TOKEN_VALUE, null)),
@@ -78,9 +79,7 @@ public void setup() throws IOException {
ImmutableList.of("table1", "table2"));
channel =
- ManagedChannelBuilder.forAddress("localhost", serviceHelper.getPort())
- .usePlaintext()
- .build();
+ ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();
logHandler = new LogHandler();
Logger.getLogger(BigtableChannelPrimer.class.toString()).addHandler(logHandler);
}
@@ -89,7 +88,7 @@ public void setup() throws IOException {
public void teardown() {
Logger.getLogger(BigtableChannelPrimer.class.toString()).removeHandler(logHandler);
channel.shutdown();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java
index 159879911a..66254fada7 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseRetryTest.java
@@ -23,9 +23,10 @@
import com.google.bigtable.v2.ReadRowsRequest;
import com.google.bigtable.v2.ReadRowsResponse;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;
+import io.grpc.Server;
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import java.util.List;
@@ -54,7 +55,7 @@ public class EnhancedBigtableStubCloseRetryTest {
private BlockingQueue requests;
private AtomicInteger numRequests;
- private FakeServiceHelper serviceHelper;
+ private Server server;
private EnhancedBigtableStub stub;
@Before
@@ -63,11 +64,10 @@ public void setUp() throws Exception {
requests = new ArrayBlockingQueue<>(10);
numRequests = new AtomicInteger();
- serviceHelper = new FakeServiceHelper(new FakeBigtable());
- serviceHelper.start();
+ server = FakeServiceBuilder.create(new FakeBigtable()).start();
BigtableDataSettings.Builder settingBuilder =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setCredentialsProvider(NoCredentialsProvider.create())
@@ -80,7 +80,7 @@ public void setUp() throws Exception {
public void tearDown() throws Exception {
testExecutor.shutdown();
stub.close();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java
index 6819739d47..597b109b0b 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubCloseTest.java
@@ -24,10 +24,11 @@
import com.google.bigtable.v2.ReadRowsRequest;
import com.google.bigtable.v2.ReadRowsResponse;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;
import com.google.common.util.concurrent.SettableFuture;
+import io.grpc.Server;
import io.grpc.stub.StreamObserver;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -48,7 +49,7 @@ public class EnhancedBigtableStubCloseTest {
private SettableFuture requestReceivedBarrier = SettableFuture.create();
private SettableFuture clientClosedBarrier = SettableFuture.create();
- private FakeServiceHelper serviceHelper;
+ private Server server;
private EnhancedBigtableStub stub;
@Before
@@ -57,11 +58,10 @@ public void setUp() throws Exception {
requestReceivedBarrier = SettableFuture.create();
clientClosedBarrier = SettableFuture.create();
- serviceHelper = new FakeServiceHelper(new FakeBigtable());
- serviceHelper.start();
+ server = FakeServiceBuilder.create(new FakeBigtable()).start();
EnhancedBigtableStubSettings stubSettings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setCredentialsProvider(NoCredentialsProvider.create())
@@ -76,7 +76,7 @@ public void setUp() throws Exception {
public void tearDown() throws Exception {
testExecutor.shutdown();
stub.close();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java
index ae045123f1..bab2b55e76 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java
@@ -41,25 +41,24 @@
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.internal.RequestContext;
import com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Queues;
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
import com.google.protobuf.StringValue;
-import io.grpc.BindableService;
import io.grpc.Context;
import io.grpc.Deadline;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.Metadata.Key;
+import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
@@ -97,7 +96,7 @@ public class EnhancedBigtableStubTest {
NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, "fake-table");
private static final String APP_PROFILE_ID = "app-profile-id";
- FakeServiceHelper serviceHelper;
+ private Server server;
private MetadataInterceptor metadataInterceptor;
private ContextInterceptor contextInterceptor;
private FakeDataService fakeDataService;
@@ -110,15 +109,14 @@ public void setUp() throws IOException, IllegalAccessException, InstantiationExc
contextInterceptor = new ContextInterceptor();
fakeDataService = new FakeDataService();
- serviceHelper =
- new FakeServiceHelper(
- ImmutableList.of(contextInterceptor, metadataInterceptor),
- null,
- ImmutableList.of(fakeDataService));
- serviceHelper.start();
+ server =
+ FakeServiceBuilder.create(fakeDataService)
+ .intercept(contextInterceptor)
+ .intercept(metadataInterceptor)
+ .start();
defaultSettings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID)
@@ -132,7 +130,7 @@ public void setUp() throws IOException, IllegalAccessException, InstantiationExc
@After
public void tearDown() {
enhancedBigtableStub.close();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
@@ -195,9 +193,7 @@ public void testBatchJwtAudience()
// Create a fixed channel that will ignore the default endpoint and connect to the emulator
ManagedChannel emulatorChannel =
- ManagedChannelBuilder.forAddress("localhost", serviceHelper.getPort())
- .usePlaintext()
- .build();
+ ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();
Metadata metadata;
try {
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java
index 760dd19911..f1655e2880 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/HeadersTest.java
@@ -35,12 +35,17 @@
import com.google.bigtable.v2.SampleRowKeysResponse;
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.internal.NameUtil;
-import com.google.cloud.bigtable.data.v2.models.*;
+import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
import com.google.cloud.bigtable.data.v2.models.Mutation;
+import com.google.cloud.bigtable.data.v2.models.Query;
+import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
+import com.google.cloud.bigtable.data.v2.models.RowMutation;
+import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
import com.google.rpc.Status;
import io.grpc.Metadata;
+import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
@@ -70,18 +75,20 @@ public class HeadersTest {
private static final Metadata.Key TEST_FIXED_HEADER =
Metadata.Key.of(TEST_FIXED_HEADER_STRING, Metadata.ASCII_STRING_MARSHALLER);
- FakeServiceHelper serviceHelper;
+ private Server server;
private BlockingQueue sentMetadata = new ArrayBlockingQueue<>(10);
private BigtableDataClient client;
@Before
public void setUp() throws Exception {
- serviceHelper = new FakeServiceHelper(new MetadataInterceptor(), new FakeBigtableService());
- serviceHelper.start();
+ server =
+ FakeServiceBuilder.create(new FakeBigtableService())
+ .intercept(new MetadataInterceptor())
+ .start();
BigtableDataSettings.Builder settings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID);
@@ -109,7 +116,7 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
client.close();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerCallableTest.java
index 03aad7f822..d6dbb969f1 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerCallableTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/HeaderTracerCallableTest.java
@@ -34,7 +34,7 @@
import com.google.bigtable.v2.SampleRowKeysRequest;
import com.google.bigtable.v2.SampleRowKeysResponse;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.internal.NameUtil;
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
@@ -47,6 +47,7 @@
import com.google.common.collect.ImmutableMap;
import io.grpc.ForwardingServerCall.SimpleForwardingServerCall;
import io.grpc.Metadata;
+import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
@@ -69,8 +70,8 @@
@RunWith(JUnit4.class)
public class HeaderTracerCallableTest {
- private FakeServiceHelper serviceHelper;
- private FakeServiceHelper serviceHelperNoHeader;
+ private Server server;
+ private Server serverNoHeader;
private FakeService fakeService = new FakeService();
@@ -95,32 +96,32 @@ public void setUp() throws Exception {
// Create a server that'll inject a server-timing header with a random number and a stub that
// connects to this server.
fakeServerTiming = new AtomicInteger(new Random().nextInt(1000) + 1);
- serviceHelper =
- new FakeServiceHelper(
- new ServerInterceptor() {
- @Override
- public ServerCall.Listener interceptCall(
- ServerCall serverCall,
- Metadata metadata,
- ServerCallHandler serverCallHandler) {
- return serverCallHandler.startCall(
- new SimpleForwardingServerCall(serverCall) {
- @Override
- public void sendHeaders(Metadata headers) {
- headers.put(
- Metadata.Key.of("server-timing", Metadata.ASCII_STRING_MARSHALLER),
- String.format("gfet4t7; dur=%d", fakeServerTiming.get()));
- super.sendHeaders(headers);
- }
- },
- metadata);
- }
- },
- fakeService);
- serviceHelper.start();
+ server =
+ FakeServiceBuilder.create(fakeService)
+ .intercept(
+ new ServerInterceptor() {
+ @Override
+ public ServerCall.Listener interceptCall(
+ ServerCall serverCall,
+ Metadata metadata,
+ ServerCallHandler serverCallHandler) {
+ return serverCallHandler.startCall(
+ new SimpleForwardingServerCall(serverCall) {
+ @Override
+ public void sendHeaders(Metadata headers) {
+ headers.put(
+ Metadata.Key.of("server-timing", Metadata.ASCII_STRING_MARSHALLER),
+ String.format("gfet4t7; dur=%d", fakeServerTiming.get()));
+ super.sendHeaders(headers);
+ }
+ },
+ metadata);
+ }
+ })
+ .start();
BigtableDataSettings settings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID)
@@ -133,11 +134,10 @@ public void sendHeaders(Metadata headers) {
// Create another server without injecting the server-timing header and another stub that
// connects to it.
- serviceHelperNoHeader = new FakeServiceHelper(fakeService);
- serviceHelperNoHeader.start();
+ serverNoHeader = FakeServiceBuilder.create(fakeService).start();
BigtableDataSettings noHeaderSettings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelperNoHeader.getPort())
+ BigtableDataSettings.newBuilderForEmulator(serverNoHeader.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID)
@@ -153,8 +153,8 @@ public void sendHeaders(Metadata headers) {
public void tearDown() {
stub.close();
noHeaderStub.close();
- serviceHelper.shutdown();
- serviceHelperNoHeader.shutdown();
+ server.shutdown();
+ serverNoHeader.shutdown();
}
@Test
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java
index 6d6cb0286a..1176214de3 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java
@@ -34,7 +34,7 @@
import com.google.bigtable.v2.ReadRowsResponse;
import com.google.bigtable.v2.ReadRowsResponse.CellChunk;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;
@@ -51,6 +51,7 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
import com.google.protobuf.StringValue;
+import io.grpc.Server;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;
@@ -101,7 +102,7 @@ public class MetricsTracerTest {
@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule();
- FakeServiceHelper serviceHelper;
+ private Server server;
@Mock(answer = Answers.CALLS_REAL_METHODS)
private BigtableGrpc.BigtableImplBase mockService;
@@ -112,13 +113,12 @@ public class MetricsTracerTest {
@Before
public void setUp() throws Exception {
- serviceHelper = new FakeServiceHelper(mockService);
- serviceHelper.start();
+ server = FakeServiceBuilder.create(mockService).start();
RpcViews.registerBigtableClientViews(localStats.getViewManager());
settings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID)
@@ -132,7 +132,7 @@ public void setUp() throws Exception {
@After
public void tearDown() {
stub.close();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsHeadersCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsHeadersCallableTest.java
index c59a848281..538d4fc246 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsHeadersCallableTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsHeadersCallableTest.java
@@ -32,7 +32,7 @@
import com.google.bigtable.v2.SampleRowKeysRequest;
import com.google.bigtable.v2.SampleRowKeysResponse;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
-import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
+import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
import com.google.cloud.bigtable.data.v2.models.Mutation;
@@ -47,6 +47,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.StringValue;
import io.grpc.Metadata;
+import io.grpc.Server;
import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
@@ -64,7 +65,7 @@
@RunWith(JUnit4.class)
public class StatsHeadersCallableTest {
- private FakeServiceHelper serviceHelper;
+ private Server server;
private FakeService fakeService = new FakeService();
@@ -81,11 +82,10 @@ public class StatsHeadersCallableTest {
@Before
public void setUp() throws Exception {
metadataInterceptor = new MetadataInterceptor();
- serviceHelper = new FakeServiceHelper(metadataInterceptor, fakeService);
- serviceHelper.start();
+ server = FakeServiceBuilder.create(fakeService).intercept(metadataInterceptor).start();
EnhancedBigtableStubSettings settings =
- BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort())
+ BigtableDataSettings.newBuilderForEmulator(server.getPort())
.setProjectId(PROJECT_ID)
.setInstanceId(INSTANCE_ID)
.setAppProfileId(APP_PROFILE_ID)
@@ -97,7 +97,7 @@ public void setUp() throws Exception {
@After
public void tearDown() {
stub.close();
- serviceHelper.shutdown();
+ server.shutdown();
}
@Test
From 9fb03607df34ff7db666cac9798e5596fbb38a35 Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Tue, 31 May 2022 14:10:12 +0000
Subject: [PATCH 8/8] chore(main): release 2.8.0 (#1265)
:robot: I have created a release *beep* *boop*
---
## [2.8.0](https://github.com/googleapis/java-bigtable/compare/v2.7.0...v2.8.0) (2022-05-27)
### Features
* split emulator into core without deps and a higher level wrapper with grpc helpers ([#1264](https://github.com/googleapis/java-bigtable/issues/1264)) ([6fdc2c1](https://github.com/googleapis/java-bigtable/commit/6fdc2c1a33e140466734debed22d50a7be726d87))
### Bug Fixes
* **java:** enable skipped tests for Native Image testing ([#1234](https://github.com/googleapis/java-bigtable/issues/1234)) ([560a501](https://github.com/googleapis/java-bigtable/commit/560a5018087c6cdc46e2c6150e6ed41075007177))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
---
CHANGELOG.md | 12 ++++++++++++
google-cloud-bigtable-bom/pom.xml | 16 ++++++++--------
google-cloud-bigtable-deps-bom/pom.xml | 2 +-
google-cloud-bigtable-emulator-core/pom.xml | 4 ++--
google-cloud-bigtable-emulator/pom.xml | 10 +++++-----
google-cloud-bigtable-stats/pom.xml | 6 +++---
google-cloud-bigtable/pom.xml | 10 +++++-----
.../java/com/google/cloud/bigtable/Version.java | 2 +-
grpc-google-cloud-bigtable-admin-v2/pom.xml | 8 ++++----
grpc-google-cloud-bigtable-v2/pom.xml | 8 ++++----
pom.xml | 12 ++++++------
proto-google-cloud-bigtable-admin-v2/pom.xml | 8 ++++----
proto-google-cloud-bigtable-v2/pom.xml | 8 ++++----
samples/snapshot/pom.xml | 2 +-
versions.txt | 14 +++++++-------
15 files changed, 67 insertions(+), 55 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0184434784..497e7a0ffb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,17 @@
# Changelog
+## [2.8.0](https://github.com/googleapis/java-bigtable/compare/v2.7.0...v2.8.0) (2022-05-27)
+
+
+### Features
+
+* split emulator into core without deps and a higher level wrapper with grpc helpers ([#1264](https://github.com/googleapis/java-bigtable/issues/1264)) ([6fdc2c1](https://github.com/googleapis/java-bigtable/commit/6fdc2c1a33e140466734debed22d50a7be726d87))
+
+
+### Bug Fixes
+
+* **java:** enable skipped tests for Native Image testing ([#1234](https://github.com/googleapis/java-bigtable/issues/1234)) ([560a501](https://github.com/googleapis/java-bigtable/commit/560a5018087c6cdc46e2c6150e6ed41075007177))
+
## [2.7.0](https://github.com/googleapis/java-bigtable/compare/v2.6.2...v2.7.0) (2022-05-20)
diff --git a/google-cloud-bigtable-bom/pom.xml b/google-cloud-bigtable-bom/pom.xml
index c1b3e40ed9..231cb5a713 100644
--- a/google-cloud-bigtable-bom/pom.xml
+++ b/google-cloud-bigtable-bom/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.google.cloud
google-cloud-bigtable-bom
- 2.7.1-SNAPSHOT
+ 2.8.0
pom
com.google.cloud
@@ -62,37 +62,37 @@
com.google.cloud
google-cloud-bigtable
- 2.7.1-SNAPSHOT
+ 2.8.0
com.google.cloud
google-cloud-bigtable-emulator
- 0.144.1-SNAPSHOT
+ 0.145.0
com.google.cloud
google-cloud-bigtable-emulator-core
- 0.144.1-SNAPSHOT
+ 0.145.0
com.google.api.grpc
grpc-google-cloud-bigtable-admin-v2
- 2.7.1-SNAPSHOT
+ 2.8.0
com.google.api.grpc
grpc-google-cloud-bigtable-v2
- 2.7.1-SNAPSHOT
+ 2.8.0
com.google.api.grpc
proto-google-cloud-bigtable-admin-v2
- 2.7.1-SNAPSHOT
+ 2.8.0
com.google.api.grpc
proto-google-cloud-bigtable-v2
- 2.7.1-SNAPSHOT
+ 2.8.0
diff --git a/google-cloud-bigtable-deps-bom/pom.xml b/google-cloud-bigtable-deps-bom/pom.xml
index d2a5768727..cf97385b7b 100644
--- a/google-cloud-bigtable-deps-bom/pom.xml
+++ b/google-cloud-bigtable-deps-bom/pom.xml
@@ -12,7 +12,7 @@