Skip to content

Commit 512c174

Browse files
authored
Fix inspect tests (GoogleCloudPlatform#3049)
1 parent 23e02c5 commit 512c174

File tree

1 file changed

+8
-40
lines changed

1 file changed

+8
-40
lines changed

dlp/src/test/java/dlp/snippets/InspectTests.java

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
import com.google.cloud.dlp.v2.DlpServiceClient;
2525
import com.google.privacy.dlp.v2.CancelDlpJobRequest;
2626
import java.io.ByteArrayOutputStream;
27-
import java.io.IOException;
2827
import java.io.PrintStream;
2928
import java.util.Arrays;
30-
import java.util.concurrent.ExecutionException;
3129
import java.util.concurrent.TimeUnit;
3230
import org.junit.After;
3331
import org.junit.Before;
@@ -158,60 +156,30 @@ public void testInspectImageFile() {
158156
}
159157

160158
@Test
161-
public void testInspectGcsFile() throws InterruptedException, ExecutionException, IOException {
162-
159+
public void testInspectGcsFile() throws Exception {
163160
InspectGcsFile.inspectGcsFile(PROJECT_ID, GCS_PATH, TOPIC_ID, SUBSCRIPTION_ID);
164-
// Await job creation
165-
TimeUnit.SECONDS.sleep(3);
166161

167162
String output = bout.toString();
168-
assertThat(output, containsString("Job created: "));
169-
170-
// Cancelling the job early to conserve quota
171-
String jobId = output.split("Job created: ")[1].split("\n")[0];
172-
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build();
173-
try (DlpServiceClient client = DlpServiceClient.create()) {
174-
client.cancelDlpJob(request);
175-
}
163+
assertThat(output, containsString("Job status: DONE"));
176164
}
177165

178166
@Test
179-
public void testInspectDatastoreEntity()
180-
throws InterruptedException, ExecutionException, IOException {
167+
public void testInspectDatastoreEntity() throws Exception {
181168

182169
InspectDatastoreEntity.insepctDatastoreEntity(
183170
PROJECT_ID, datastoreNamespace, datastoreKind, TOPIC_ID, SUBSCRIPTION_ID);
184-
// Await job creation
185-
TimeUnit.SECONDS.sleep(3);
186171

187172
String output = bout.toString();
188-
assertThat(output, containsString("Job created: "));
189-
190-
// Cancelling the job early to conserve quota
191-
String jobId = output.split("Job created: ")[1].split("\n")[0];
192-
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build();
193-
try (DlpServiceClient client = DlpServiceClient.create()) {
194-
client.cancelDlpJob(request);
195-
}
173+
assertThat(output, containsString("Job status: DONE"));
196174
}
197175

198176
@Test
199-
public void testInspectBigQueryTable()
200-
throws InterruptedException, ExecutionException, IOException {
177+
public void testInspectBigQueryTable() throws Exception {
201178

202-
InspectBigQueryTable.inspectBigQueryTable(
203-
PROJECT_ID, DATASET_ID, TABLE_ID, TOPIC_ID, SUBSCRIPTION_ID);
204-
// Await job creation
205-
TimeUnit.SECONDS.sleep(3);
179+
InspectBigQueryTable
180+
.inspectBigQueryTable(PROJECT_ID, DATASET_ID, TABLE_ID, TOPIC_ID, SUBSCRIPTION_ID);
206181

207182
String output = bout.toString();
208-
assertThat(output, containsString("Job created: "));
209-
210-
// Cancelling the job early to conserve quota
211-
String jobId = output.split("Job created: ")[1].split("\n")[0];
212-
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build();
213-
try (DlpServiceClient client = DlpServiceClient.create()) {
214-
client.cancelDlpJob(request);
215-
}
183+
assertThat(output, containsString("Job status: DONE"));
216184
}
217185
}

0 commit comments

Comments
 (0)