Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ Bigtable integration tests can either be run against an emulator or a real Bigta
target environment can be selected via the `bigtable.env` system property. By default it is set to
`emulator` and the other option is `prod`.

To use the `emulator` environment, please install the gcloud sdk and use it to install the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add these instructions to the emulator package?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, these instructions are for running the tests. The emulator package has instructions focusing on how a customer can use the emulator for their own tests:

https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-testing/google-cloud-bigtable-emulator

`cbtemulator` via `gcloud components install bigtable`.

To use the `prod` environment:
1. Set up the target table using `google-cloud-bigtable/scripts/setup-test-table.sh`
2. Download the [JSON service account credentials file][create-service-account] from the Google
Expand Down
5 changes: 5 additions & 0 deletions google-cloud-clients/google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<artifactId>grpc-google-cloud-bigtable-admin-v2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-emulator</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package com.google.cloud.bigtable.data.v2.it.env;

import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings;
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
import com.google.cloud.bigtable.emulator.v2.Emulator;

public class EmulatorEnv implements TestEnv {
private static final String PROJECT_ID = "fake-project";
Expand All @@ -25,19 +29,28 @@ public class EmulatorEnv implements TestEnv {
private static final String FAMILY_ID = "cf";

private Emulator emulator;
private BigtableTableAdminClient tableAdminClient;
private BigtableDataClient dataClient;

@Override
public void start() throws Exception {
emulator = Emulator.createGCloud();
emulator = Emulator.createBundled();
emulator.start();

emulator
.getTableAdminClient()
.createTable(CreateTableRequest.of(TABLE_ID).addFamily(FAMILY_ID));
tableAdminClient =
BigtableTableAdminClient.create(
BigtableTableAdminSettings.newBuilderForEmulator(emulator.getPort()).build());
dataClient =
BigtableDataClient.create(
BigtableDataSettings.newBuilderForEmulator(emulator.getPort()).build());

tableAdminClient.createTable(CreateTableRequest.of(TABLE_ID).addFamily(FAMILY_ID));
}

@Override
public void stop() throws Exception {
tableAdminClient.close();
dataClient.close();
emulator.stop();
}

Expand All @@ -63,7 +76,7 @@ public String getRowPrefix() {

@Override
public BigtableDataClient getDataClient() {
return emulator.getDataClient();
return dataClient;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -83,7 +89,20 @@ public class DownloadComponentsMojo extends AbstractMojo {
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

private ExecutorService executor;

public void execute() throws MojoExecutionException {
executor = Executors.newCachedThreadPool();

try {
executeInner();
} finally {
executor.shutdown();
executor = null;
}
}

private void executeInner() throws MojoExecutionException {
if (shouldSkipDownload) {
return;
}
Expand Down Expand Up @@ -119,18 +138,36 @@ public void execute() throws MojoExecutionException {
checksums = new HashMap<>();
}

// Download any updated components
for (Component component : components) {
// Download any updated components in parallel
List<Future<?>> futures = Lists.newArrayList();

for (final Component component : components) {
if (!forceRefresh && component.getChecksum().equals(checksums.get(component.getId()))) {
continue;
}

futures.add(downloadComponentAsync(component));
}

// Wait for all downloads to finish and unwrap any errors
for (Future<?> future : futures) {
try {
downloadComponent(component);
} catch (Exception e) {
throw new MojoExecutionException("Failed to download component " + component.getId(), e);
future.get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MojoExecutionException) {
throw ((MojoExecutionException) e.getCause());
} else {
throw new MojoExecutionException(
"Unexpected execution error downloading component", e.getCause());
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new MojoExecutionException("Interrupted while downloading component");
}
}
if (futures.size() > 0) {
getLog().info("Finished downloading all components");
}

// Write the checksums of the newly updated components.
try {
Expand Down Expand Up @@ -251,6 +288,22 @@ private Map<String, String> parseLocalChecksums() throws IOException {
return results;
}

private Future<Void> downloadComponentAsync(final Component component) {
return executor.submit(
new Callable<Void>() {
@Override
public Void call() throws MojoExecutionException {
try {
downloadComponent(component);
} catch (Exception e) {
throw new MojoExecutionException("Failed to download " + component.getId(), e);
}

return null;
}
});
}

/** Downloads and extracts the component into the destinationDir. */
private void downloadComponent(Component component) throws IOException, NoSuchAlgorithmException {
getLog().info("Downloading " + component.getId());
Expand Down