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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run",
"modification": 4
"modification": 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,57 +117,6 @@ public class GroupByKeyTest implements Serializable {
/** Shared test base class with setup/teardown helpers. */
public abstract static class SharedTestBase {
@Rule public transient TestPipeline p = TestPipeline.create();

private static final String PROJECT_ID = "apache-beam-testing";
private static final String SECRET_ID = "gbek-test";
public static String gcpSecretVersionName;
private static String secretId;

@BeforeClass
public static void setup() throws IOException {
secretId = String.format("%s-%d", SECRET_ID, new SecureRandom().nextInt(10000));
SecretManagerServiceClient client;
try {
client = SecretManagerServiceClient.create();
} catch (IOException e) {
gcpSecretVersionName = null;
return;
}
ProjectName projectName = ProjectName.of(PROJECT_ID);
SecretName secretName = SecretName.of(PROJECT_ID, secretId);

try {
client.getSecret(secretName);
} catch (Exception e) {
com.google.cloud.secretmanager.v1.Secret secret =
com.google.cloud.secretmanager.v1.Secret.newBuilder()
.setReplication(
com.google.cloud.secretmanager.v1.Replication.newBuilder()
.setAutomatic(
com.google.cloud.secretmanager.v1.Replication.Automatic.newBuilder()
.build())
.build())
.build();
client.createSecret(projectName, secretId, secret);
byte[] secretBytes = new byte[32];
new SecureRandom().nextBytes(secretBytes);
client.addSecretVersion(
secretName,
SecretPayload.newBuilder()
.setData(ByteString.copyFrom(java.util.Base64.getUrlEncoder().encode(secretBytes)))
.build());
}
gcpSecretVersionName = secretName.toString() + "/versions/latest";
}

@AfterClass
public static void tearDown() throws IOException {
if (gcpSecretVersionName != null) {
SecretManagerServiceClient client = SecretManagerServiceClient.create();
SecretName secretName = SecretName.of(PROJECT_ID, secretId);
client.deleteSecret(secretName);
}
}
}

/** Tests validating basic {@link GroupByKey} scenarios. */
Expand Down Expand Up @@ -673,6 +622,61 @@ public void testLargeKeys10MB() throws Exception {
public void testLargeKeys100MB() throws Exception {
runLargeKeysTest(p, 100 << 20);
}
}

/** Tests validating GroupByKey behaviors with the gbek flag set. */
@RunWith(JUnit4.class)
public static class GbekTests extends SharedTestBase {
private static final String PROJECT_ID = "apache-beam-testing";
private static final String SECRET_ID = "gbek-test";
public static String gcpSecretVersionName;
private static String secretId;

@BeforeClass
public static void setup() throws IOException {
secretId = String.format("%s-%d", SECRET_ID, new SecureRandom().nextInt(10000));
SecretManagerServiceClient client;
try {
client = SecretManagerServiceClient.create();
} catch (IOException e) {
gcpSecretVersionName = null;
return;
}
ProjectName projectName = ProjectName.of(PROJECT_ID);
SecretName secretName = SecretName.of(PROJECT_ID, secretId);

try {
client.getSecret(secretName);
} catch (Exception e) {
com.google.cloud.secretmanager.v1.Secret secret =
com.google.cloud.secretmanager.v1.Secret.newBuilder()
.setReplication(
com.google.cloud.secretmanager.v1.Replication.newBuilder()
.setAutomatic(
com.google.cloud.secretmanager.v1.Replication.Automatic.newBuilder()
.build())
.build())
.build();
client.createSecret(projectName, secretId, secret);
byte[] secretBytes = new byte[32];
new SecureRandom().nextBytes(secretBytes);
client.addSecretVersion(
secretName,
SecretPayload.newBuilder()
.setData(ByteString.copyFrom(java.util.Base64.getUrlEncoder().encode(secretBytes)))
.build());
}
gcpSecretVersionName = secretName.toString() + "/versions/latest";
}

@AfterClass
public static void tearDown() throws IOException {
if (gcpSecretVersionName != null) {
SecretManagerServiceClient client = SecretManagerServiceClient.create();
SecretName secretName = SecretName.of(PROJECT_ID, secretId);
client.deleteSecret(secretName);
}
}

@Test
@Category(NeedsRunner.class)
Expand Down
Loading