Skip to content

Commit 210b30a

Browse files
lesvanguillanneuf
authored andcommitted
Update QuickStartIT.java (#2716)
Fixes: #2715 Reviewing QuickstartIT, it: * creates a bucket * Writes a list of assets to the bucket * wants to see that bucket in the list of assets * deletes the bucket. It should instead: * Write to a well known bucket w/ gs:/well-known-bucket/UUID/my-assets.txt * See if well-known-bucket is in my-assets.txt This way there isn't a hysteresis problem on creating and knowing about buckets. - [x] `pom.xml` parent set to latest `shared-configuration` - [x] Appropriate changes to README are included in PR - [x] API's need to be enabled to test (tell us) - [x] Environment Variables need to be set (ask us to set them) - [x] Tests pass (`mvn -P lint clean verify`) * (Note- `Checkstyle` passing is required; `Spotbugs`, `ErrorProne`, `PMD`, etc. `ERROR`'s are advisory only)
1 parent 57de426 commit 210b30a

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

asset/src/test/java/com/example/asset/QuickStartIT.java

+13-19
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import com.google.cloud.bigquery.DatasetInfo;
2828
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
2929
import com.google.cloud.storage.BlobInfo;
30-
import com.google.cloud.storage.Bucket;
31-
import com.google.cloud.storage.BucketInfo;
3230
import com.google.cloud.storage.Storage;
3331
import com.google.cloud.storage.Storage.BlobListOption;
3432
import com.google.cloud.storage.StorageOptions;
@@ -45,33 +43,29 @@
4543
@RunWith(JUnit4.class)
4644
@SuppressWarnings("checkstyle:abbreviationaswordinname")
4745
public class QuickStartIT {
48-
private static final String bucketName = UUID.randomUUID().toString();
46+
private static final String bucketName = "java-docs-samples-testing";
47+
private static final String path = UUID.randomUUID().toString();
4948
private static final String datasetName = RemoteBigQueryHelper.generateDatasetName();
5049
private ByteArrayOutputStream bout;
5150
private PrintStream out;
5251
private BigQuery bigquery;
5352

54-
private static final void deleteBucket(String bucketName) {
53+
private static final void deleteObjects() {
5554
Storage storage = StorageOptions.getDefaultInstance().getService();
56-
for (BlobInfo info : storage.list(bucketName, BlobListOption.versions(true)).getValues()) {
55+
for (BlobInfo info :
56+
storage
57+
.list(
58+
bucketName,
59+
BlobListOption.versions(true),
60+
BlobListOption.currentDirectory(),
61+
BlobListOption.prefix(path + "/"))
62+
.getValues()) {
5763
storage.delete(info.getBlobId());
5864
}
59-
storage.delete(bucketName);
60-
}
61-
62-
private static final void createBucket(String bucketName) {
63-
Storage storage = StorageOptions.getDefaultInstance().getService();
64-
if (storage.get(bucketName) != null) {
65-
// Bucket exists.
66-
return;
67-
}
68-
Bucket bucket = storage.create(BucketInfo.of(bucketName));
69-
assertThat(bucket).isNotNull();
7065
}
7166

7267
@Before
7368
public void setUp() {
74-
createBucket(bucketName);
7569
bigquery = BigQueryOptions.getDefaultInstance().getService();
7670
if (bigquery.getDataset(datasetName) == null) {
7771
Dataset dataset = bigquery.create(DatasetInfo.newBuilder(datasetName).build());
@@ -85,14 +79,14 @@ public void setUp() {
8579
public void tearDown() {
8680
String consoleOutput = bout.toString();
8781
System.setOut(null);
88-
deleteBucket(bucketName);
82+
deleteObjects();
8983
DatasetId datasetId = DatasetId.of(bigquery.getOptions().getProjectId(), datasetName);
9084
bigquery.delete(datasetId, DatasetDeleteOption.deleteContents());
9185
}
9286

9387
@Test
9488
public void testExportAssetExample() throws Exception {
95-
String assetDumpPath = String.format("gs://%s/my-assets-dump.txt", bucketName);
89+
String assetDumpPath = String.format("gs://%s/%s/my-assets-dump.txt", bucketName, path);
9690
ExportAssetsExample.main(assetDumpPath);
9791
String got = bout.toString();
9892
assertThat(got).contains(String.format("uri: \"%s\"", assetDumpPath));

0 commit comments

Comments
 (0)