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/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/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/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/google-cloud-bigtable-bom/pom.xml b/google-cloud-bigtable-bom/pom.xml index 304606b88b..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.0 + 2.8.0 pom com.google.cloud @@ -62,32 +62,37 @@ com.google.cloud google-cloud-bigtable - 2.7.0 + 2.8.0 com.google.cloud google-cloud-bigtable-emulator - 0.144.0 + 0.145.0 + + + com.google.cloud + google-cloud-bigtable-emulator-core + 0.145.0 com.google.api.grpc grpc-google-cloud-bigtable-admin-v2 - 2.7.0 + 2.8.0 com.google.api.grpc grpc-google-cloud-bigtable-v2 - 2.7.0 + 2.8.0 com.google.api.grpc proto-google-cloud-bigtable-admin-v2 - 2.7.0 + 2.8.0 com.google.api.grpc proto-google-cloud-bigtable-v2 - 2.7.0 + 2.8.0 diff --git a/google-cloud-bigtable-deps-bom/pom.xml b/google-cloud-bigtable-deps-bom/pom.xml index 0296b01d89..cf97385b7b 100644 --- a/google-cloud-bigtable-deps-bom/pom.xml +++ b/google-cloud-bigtable-deps-bom/pom.xml @@ -12,7 +12,7 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom diff --git a/google-cloud-bigtable-emulator-core/pom.xml b/google-cloud-bigtable-emulator-core/pom.xml new file mode 100644 index 0000000000..82318f9a68 --- /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.8.0 + + + google-cloud-bigtable-emulator-core + 0.145.0 + + + 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 48d602f341..b0338106bd 100644 --- a/google-cloud-bigtable-emulator/pom.xml +++ b/google-cloud-bigtable-emulator/pom.xml @@ -5,7 +5,7 @@ 4.0.0 google-cloud-bigtable-emulator - 0.144.0 + 0.145.0 Google Cloud Java - Bigtable Emulator https://github.com/googleapis/java-bigtable @@ -14,7 +14,7 @@ com.google.cloud google-cloud-bigtable-parent - 2.7.0 + 2.8.0 scm:git:git@github.com:googleapis/java-bigtable.git @@ -69,8 +69,8 @@ org.apache.maven.plugins maven-dependency-plugin - - io.grpc:grpc-netty-shaded + + com.google.api:gax-grpc @@ -81,14 +81,14 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import com.google.cloud google-cloud-bigtable-bom - 2.7.0 + 2.8.0 pom import @@ -96,16 +96,29 @@ - + + com.google.cloud + google-cloud-bigtable-emulator-core + 0.145.0 + + com.google.api api-common + + + com.google.guava + guava + io.grpc grpc-api - - provided + + + + com.google.api + gax-grpc @@ -160,11 +173,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/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-stats/pom.xml b/google-cloud-bigtable-stats/pom.xml index 019d3c1bcf..c47ae85703 100644 --- a/google-cloud-bigtable-stats/pom.xml +++ b/google-cloud-bigtable-stats/pom.xml @@ -5,7 +5,7 @@ com.google.cloud google-cloud-bigtable-parent - 2.7.0 + 2.8.0 4.0.0 @@ -13,7 +13,7 @@ through Stackdriver. Built-in metrics will be implemented with shaded OpenCensus so it won't interfere with customer's application metrics. --> google-cloud-bigtable-stats - 2.7.0 + 2.8.0 Experimental project to shade OpenCensus dependencies. @@ -21,7 +21,7 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index be934dc8e6..45e29e80ee 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.8.0 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.8.0 - 2.7.0 + 2.8.0 google-cloud-bigtable @@ -43,14 +43,14 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import com.google.cloud google-cloud-bigtable-bom - 2.7.0 + 2.8.0 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..d3e3147498 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.8.0"; // {x-version-update-end} } 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/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/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); 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 diff --git a/grpc-google-cloud-bigtable-admin-v2/pom.xml b/grpc-google-cloud-bigtable-admin-v2/pom.xml index ec3499f2e8..38ca24d893 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.8.0 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.8.0 @@ -18,14 +18,14 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import com.google.cloud google-cloud-bigtable-bom - 2.7.0 + 2.8.0 pom import diff --git a/grpc-google-cloud-bigtable-v2/pom.xml b/grpc-google-cloud-bigtable-v2/pom.xml index de9fbccd64..3e63d98638 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.8.0 grpc-google-cloud-bigtable-v2 GRPC library for grpc-google-cloud-bigtable-v2 com.google.cloud google-cloud-bigtable-parent - 2.7.0 + 2.8.0 @@ -18,14 +18,14 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import com.google.cloud google-cloud-bigtable-bom - 2.7.0 + 2.8.0 pom import diff --git a/pom.xml b/pom.xml index fa3b1e8c93..b2335ea9d3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ google-cloud-bigtable-parent pom - 2.7.0 + 2.8.0 Google Cloud Bigtable Parent https://github.com/googleapis/java-bigtable @@ -152,33 +152,33 @@ com.google.api.grpc proto-google-cloud-bigtable-v2 - 2.7.0 + 2.8.0 com.google.api.grpc proto-google-cloud-bigtable-admin-v2 - 2.7.0 + 2.8.0 com.google.api.grpc grpc-google-cloud-bigtable-v2 - 2.7.0 + 2.8.0 com.google.api.grpc grpc-google-cloud-bigtable-admin-v2 - 2.7.0 + 2.8.0 com.google.cloud google-cloud-bigtable - 2.7.0 + 2.8.0 com.google.cloud google-cloud-conformance-tests - 0.2.11 + 0.3.0 com.google.truth @@ -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/proto-google-cloud-bigtable-admin-v2/pom.xml b/proto-google-cloud-bigtable-admin-v2/pom.xml index 94152d9de0..35d0008618 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.8.0 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.8.0 @@ -18,14 +18,14 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import com.google.cloud google-cloud-bigtable-bom - 2.7.0 + 2.8.0 pom import diff --git a/proto-google-cloud-bigtable-v2/pom.xml b/proto-google-cloud-bigtable-v2/pom.xml index 252dbedf8a..cf7e5cb736 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.8.0 proto-google-cloud-bigtable-v2 PROTO library for proto-google-cloud-bigtable-v2 com.google.cloud google-cloud-bigtable-parent - 2.7.0 + 2.8.0 @@ -18,14 +18,14 @@ com.google.cloud google-cloud-bigtable-deps-bom - 2.7.0 + 2.8.0 pom import com.google.cloud google-cloud-bigtable-bom - 2.7.0 + 2.8.0 pom import 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 diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 2947938372..83f70ac2c3 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.8.0 diff --git a/versions.txt b/versions.txt index 6bd15bdaf1..91ce3500f4 100644 --- a/versions.txt +++ b/versions.txt @@ -1,9 +1,10 @@ # 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.8.0:2.8.0 +grpc-google-cloud-bigtable-admin-v2:2.8.0:2.8.0 +grpc-google-cloud-bigtable-v2:2.8.0:2.8.0 +proto-google-cloud-bigtable-admin-v2:2.8.0:2.8.0 +proto-google-cloud-bigtable-v2:2.8.0:2.8.0 +google-cloud-bigtable-emulator:0.145.0:0.145.0 +google-cloud-bigtable-emulator-core:2.8.0:2.8.0