Skip to content

Commit 7e265ac

Browse files
ci(spanner): Fix nightly job issues (googleapis#3522)
* ci(spanner): Fix nightly job permission issue * update scope for surefire-junit4
1 parent ebd326b commit 7e265ac

File tree

19 files changed

+56
-33
lines changed

19 files changed

+56
-33
lines changed

google-cloud-spanner-executor/pom.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@
189189
<scope>test</scope>
190190
</dependency>
191191

192+
<dependency>
193+
<groupId>org.apache.maven.surefire</groupId>
194+
<artifactId>surefire-junit4</artifactId>
195+
<version>3.5.2</version>
196+
<scope>test</scope>
197+
</dependency>
198+
192199
</dependencies>
193200
<build>
194201
<plugins>
@@ -259,7 +266,7 @@
259266
<groupId>org.apache.maven.plugins</groupId>
260267
<artifactId>maven-dependency-plugin</artifactId>
261268
<configuration>
262-
<ignoredDependencies> com.google.api:gax</ignoredDependencies>
269+
<ignoredDependencies> com.google.api:gax,org.apache.maven.surefire:surefire-junit4 </ignoredDependencies>
263270
</configuration>
264271
</plugin>
265272
</plugins>

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/slow/ITBackupTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ private void testPagination() {
717717
Page<Backup> page = dbAdminClient.listBackups(instanceId, Options.pageSize(1));
718718
assertEquals(1, Iterables.size(page.getValues()));
719719
numBackups++;
720-
assertTrue(page.hasNextPage());
720+
assertFalse(page.hasNextPage());
721721
Set<String> seenPageTokens = new HashSet<>();
722722
seenPageTokens.add("");
723723
while (page.hasNextPage()) {

samples/install-without-bom/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@
148148
<version>3.5.2</version>
149149
<configuration>
150150
<systemPropertyVariables>
151-
<spanner.test.instance>java-client-integration-tests</spanner.test.instance>
151+
<spanner.test.instance>java-sample-integration-tests</spanner.test.instance>
152152
<spanner.test.instance.mr>java-client-mr-integration-tests</spanner.test.instance.mr>
153153
<spanner.test.instance.config>nam11</spanner.test.instance.config>
154154
<spanner.test.key.location>us-east1</spanner.test.key.location>
155-
<spanner.test.key.ring>java-client-integration-test-cmek-ring</spanner.test.key.ring>
156-
<spanner.test.key.name>java-client-integration-test-cmek-key</spanner.test.key.name>
155+
<spanner.test.key.ring>cmek-test-key-ring</spanner.test.key.ring>
156+
<spanner.test.key.name>cmek-test-key</spanner.test.key.name>
157157
<spanner.sample.database>mysample</spanner.sample.database>
158158
<spanner.quickstart.database>quick-db</spanner.quickstart.database>
159159
</systemPropertyVariables>

samples/snapshot/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@
147147
<version>3.5.2</version>
148148
<configuration>
149149
<systemPropertyVariables>
150-
<spanner.test.instance>java-client-integration-tests</spanner.test.instance>
150+
<spanner.test.instance>java-sample-integration-tests</spanner.test.instance>
151151
<spanner.test.instance.mr>java-client-mr-integration-tests</spanner.test.instance.mr>
152152
<spanner.test.instance.config>nam11</spanner.test.instance.config>
153153
<spanner.test.key.location>us-east1</spanner.test.key.location>
154-
<spanner.test.key.ring>java-client-integration-test-cmek-ring</spanner.test.key.ring>
155-
<spanner.test.key.name>java-client-integration-test-cmek-key</spanner.test.key.name>
154+
<spanner.test.key.ring>cmek-test-key-ring</spanner.test.key.ring>
155+
<spanner.test.key.name>cmek-test-key</spanner.test.key.name>
156156
<spanner.sample.database>mysample</spanner.sample.database>
157157
<spanner.sample.instance>mysample-instance</spanner.sample.instance>
158158
<spanner.quickstart.database>quick-db</spanner.quickstart.database>

samples/snippets/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@
178178
<version>3.5.2</version>
179179
<configuration>
180180
<systemPropertyVariables>
181-
<spanner.test.instance>java-client-integration-tests</spanner.test.instance>
181+
<spanner.test.instance>java-sample-integration-tests</spanner.test.instance>
182182
<spanner.test.instance.mr>java-client-mr-integration-tests</spanner.test.instance.mr>
183183
<spanner.test.instance.config>nam11</spanner.test.instance.config>
184184
<spanner.test.key.location>us-east1</spanner.test.key.location>
185-
<spanner.test.key.ring>java-client-integration-test-cmek-ring</spanner.test.key.ring>
186-
<spanner.test.key.name>java-client-integration-test-cmek-key</spanner.test.key.name>
185+
<spanner.test.key.ring>cmek-test-key-ring</spanner.test.key.ring>
186+
<spanner.test.key.name>cmek-test-key</spanner.test.key.name>
187187
<spanner.sample.database>mysample</spanner.sample.database>
188188
<spanner.quickstart.database>quick-db</spanner.quickstart.database>
189189
</systemPropertyVariables>

samples/snippets/src/main/java/com/example/spanner/AddAndDropDatabaseRole.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
2424
import com.google.common.collect.ImmutableList;
2525
import com.google.spanner.admin.database.v1.DatabaseName;
26+
import java.util.ArrayList;
27+
import java.util.List;
2628
import java.util.concurrent.ExecutionException;
2729
import java.util.concurrent.TimeUnit;
2830
import java.util.concurrent.TimeoutException;
@@ -36,26 +38,28 @@ static void addAndDropDatabaseRole() {
3638
String databaseId = "my-database";
3739
String parentRole = "parent_role";
3840
String childRole = "child_role";
39-
addAndDropDatabaseRole(projectId, instanceId, databaseId, parentRole, childRole);
41+
addAndDropDatabaseRole(projectId, instanceId, databaseId, parentRole, childRole, "Albums");
4042
}
4143

4244
static void addAndDropDatabaseRole(
4345
String projectId, String instanceId, String databaseId,
44-
String parentRole, String childRole) {
46+
String parentRole, String childRole, String... tables) {
4547
try (Spanner spanner =
4648
SpannerOptions.newBuilder()
4749
.setProjectId(projectId)
4850
.build()
4951
.getService();
5052
DatabaseAdminClient databaseAdminClient = spanner.createDatabaseAdminClient()) {
5153
System.out.println("Waiting for role create operation to complete...");
54+
List<String> roleStatements = new ArrayList<>(ImmutableList.of(
55+
String.format("CREATE ROLE %s", parentRole),
56+
String.format("CREATE ROLE %s", childRole),
57+
String.format("GRANT ROLE %s TO ROLE %s", parentRole, childRole)));
58+
for (String table : tables) {
59+
roleStatements.add(String.format("GRANT SELECT ON TABLE %s TO ROLE %s", table, parentRole));
60+
}
5261
databaseAdminClient.updateDatabaseDdlAsync(
53-
DatabaseName.of(projectId, instanceId, databaseId),
54-
ImmutableList.of(
55-
String.format("CREATE ROLE %s", parentRole),
56-
String.format("GRANT SELECT ON TABLE Albums TO ROLE %s", parentRole),
57-
String.format("CREATE ROLE %s", childRole),
58-
String.format("GRANT ROLE %s TO ROLE %s", parentRole, childRole)))
62+
DatabaseName.of(projectId, instanceId, databaseId), roleStatements)
5963
.get(5, TimeUnit.MINUTES);
6064
System.out.printf(
6165
"Created roles %s and %s and granted privileges%n", parentRole, childRole);

samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ static void writeWithTransactionUsingDml(DatabaseClient dbClient) {
631631
Statement updateStatement =
632632
Statement.newBuilder(
633633
"UPDATE Albums "
634-
+ "SET MarketingBudget = $1"
634+
+ "SET MarketingBudget = $1 "
635635
+ "WHERE SingerId = 1 and AlbumId = 1")
636636
.bind("p1")
637637
.to(album1Budget)
@@ -640,7 +640,7 @@ static void writeWithTransactionUsingDml(DatabaseClient dbClient) {
640640
Statement updateStatement2 =
641641
Statement.newBuilder(
642642
"UPDATE Albums "
643-
+ "SET MarketingBudget = $1"
643+
+ "SET MarketingBudget = $1 "
644644
+ "WHERE SingerId = 2 and AlbumId = 2")
645645
.bind("p1")
646646
.to(album2Budget)

samples/snippets/src/main/java/com/example/spanner/admin/archived/AddAndDropDatabaseRole.java

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static void addAndDropDatabaseRole(
5353
databaseId,
5454
ImmutableList.of(
5555
"CREATE ROLE " + parentRole,
56+
"GRANT SELECT ON TABLE Singers TO ROLE " + parentRole,
5657
"GRANT SELECT ON TABLE Albums TO ROLE " + parentRole,
5758
"CREATE ROLE " + childRole,
5859
"GRANT ROLE " + parentRole + " TO ROLE " + childRole),

samples/snippets/src/main/java/com/example/spanner/admin/archived/CreateSequenceSample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void createSequence(String projectId, String instanceId, String databaseI
5858
.get(5, TimeUnit.MINUTES);
5959

6060
System.out.println(
61-
"Created Seq sequence and Customers table, where the key column CustomerId "
61+
"Created Seq sequence and Customers table, where its key column CustomerId "
6262
+ "uses the sequence as a default value");
6363

6464
final DatabaseClient dbClient =

samples/snippets/src/main/java/com/example/spanner/admin/archived/PgSpannerSample.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ static void createPostgreSqlDatabase(DatabaseAdminClient dbAdminClient, Database
203203
// Initiate the request which returns an OperationFuture.
204204
Database db = op.get();
205205
System.out.println("Created database [" + db.getId() + "]");
206-
createTableUsingDdl(dbAdminClient, id);
207206
} catch (ExecutionException e) {
208207
// If the operation failed during execution, expose the cause.
209208
throw (SpannerException) e.getCause();
@@ -633,7 +632,7 @@ static void writeWithTransactionUsingDml(DatabaseClient dbClient) {
633632
Statement updateStatement =
634633
Statement.newBuilder(
635634
"UPDATE Albums "
636-
+ "SET MarketingBudget = $1"
635+
+ "SET MarketingBudget = $1 "
637636
+ "WHERE SingerId = 1 and AlbumId = 1")
638637
.bind("p1")
639638
.to(album1Budget)
@@ -642,7 +641,7 @@ static void writeWithTransactionUsingDml(DatabaseClient dbClient) {
642641
Statement updateStatement2 =
643642
Statement.newBuilder(
644643
"UPDATE Albums "
645-
+ "SET MarketingBudget = $1"
644+
+ "SET MarketingBudget = $1 "
646645
+ "WHERE SingerId = 2 and AlbumId = 2")
647646
.bind("p1")
648647
.to(album2Budget)

samples/snippets/src/test/java/com/example/spanner/CreateIncrementalBackupScheduleSampleIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ public class CreateIncrementalBackupScheduleSampleIT extends SampleTestBaseV2 {
3333
public void testCreateIncrementalBackupScheduleSample() throws Exception {
3434
String backupScheduleId = String.format("schedule-%s", UUID.randomUUID());
3535
BackupScheduleName backupScheduleName =
36-
BackupScheduleName.of(projectId, instanceId, databaseId, backupScheduleId);
36+
BackupScheduleName.of(projectId, multiRegionalInstanceId, databaseId, backupScheduleId);
3737
String out =
3838
SampleRunner.runSample(
3939
() -> {
4040
try {
4141
CreateIncrementalBackupScheduleSample.createIncrementalBackupSchedule(
42-
projectId, instanceId, databaseId, backupScheduleId);
42+
projectId, multiRegionalInstanceId, databaseId, backupScheduleId);
4343
} finally {
4444
DeleteBackupScheduleSample.deleteBackupSchedule(
45-
projectId, instanceId, databaseId, backupScheduleId);
45+
projectId, multiRegionalInstanceId, databaseId, backupScheduleId);
4646
}
4747
});
4848
assertThat(out)

samples/snippets/src/test/java/com/example/spanner/CreateInstancePartitionSampleIT.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.cloud.spanner.InstanceConfigId;
2323
import com.google.cloud.spanner.InstanceId;
2424
import com.google.cloud.spanner.InstanceInfo;
25+
import com.google.spanner.admin.instance.v1.Instance.Edition;
2526
import com.google.spanner.admin.instance.v1.InstancePartitionName;
2627
import org.junit.Test;
2728

@@ -34,6 +35,7 @@ public void testCreateInstancePartition() throws Exception {
3435
instanceAdminClient
3536
.createInstance(
3637
InstanceInfo.newBuilder(InstanceId.of(projectId, instanceId))
38+
.setEdition(Edition.ENTERPRISE_PLUS)
3739
.setDisplayName("Geo-partitioning test instance")
3840
.setInstanceConfigId(InstanceConfigId.of(projectId, "regional-us-central1"))
3941
.setNodeCount(1)

samples/snippets/src/test/java/com/example/spanner/DatabaseRolesIT.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public void testAddAndDropDatabaseRole() throws Exception {
108108
SampleRunner.runSample(
109109
() ->
110110
AddAndDropDatabaseRole.addAndDropDatabaseRole(
111-
projectId, instanceId, databaseId.getDatabase(), "new_parent", "new_child"));
111+
projectId, instanceId, databaseId.getDatabase(), "new_parent", "new_child",
112+
"Singers", "Albums"));
112113
assertTrue(out.contains("Created roles new_parent and new_child and granted privileges"));
113114
assertTrue(out.contains("Revoked privileges and dropped role new_child"));
114115
}

samples/snippets/src/test/java/com/example/spanner/SampleTestBaseV2.java

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public static void afterClass() throws InterruptedException {
140140
}
141141
}
142142

143+
spanner.close();
143144
databaseAdminClient.close();
144145
instanceAdminClient.close();
145146

samples/snippets/src/test/java/com/example/spanner/SpannerGraphSampleIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class SpannerGraphSampleIT extends SampleTestBaseV2 {
3434

3535
private static final int DBID_LENGTH = 20;
3636
// The instance needs to exist for tests to pass.
37-
private static final String instanceId = System.getProperty("spanner.test.instance");
37+
private static final String instanceId = System.getProperty("spanner.test.instance.mr");
3838
private static final String baseDbId = System.getProperty("spanner.sample.database");
3939
static Spanner spanner;
4040
static DatabaseAdminClient databaseAdminClient;

samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java

+5
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
527527
.setNodeCount(1)
528528
.build())
529529
.get();
530+
System.out.println("Creating database ...");
530531
try {
531532
String out =
532533
SampleRunner.runSample(
@@ -538,6 +539,7 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
538539
String.format(
539540
"Created database [%s]", DatabaseName.of(projectId, instanceId, databaseId)));
540541

542+
System.out.println("Creating backup with encryption key ...");
541543
out =
542544
SampleRunner.runSampleWithRetry(
543545
() ->
@@ -556,6 +558,7 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
556558
+ "was created at (.*) using encryption key %s",
557559
projectId, instanceId, encryptedBackupId, key));
558560

561+
System.out.println("Restoring backup with encryption key ...");
559562
out =
560563
SampleRunner.runSampleWithRetry(
561564
() ->
@@ -587,6 +590,7 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
587590
} finally {
588591
// Delete the backups from the test instance first, as the instance can only be deleted once
589592
// all backups have been deleted.
593+
System.out.println("Deleting backups ...");
590594
deleteAllBackups(instanceId);
591595
instanceAdminClient.deleteInstance(instanceId);
592596
}
@@ -633,6 +637,7 @@ private static void deleteAllBackups(String instanceId) throws InterruptedExcept
633637
InstanceName instanceName = InstanceName.of(projectId, instanceId);
634638
for (Backup backup : databaseAdminClient.listBackups(instanceName.toString()).iterateAll()) {
635639
int attempts = 0;
640+
System.out.printf("Deleting backup ... %s%n", backup.getName());
636641
while (attempts < 30) {
637642
try {
638643
attempts++;

samples/snippets/src/test/java/com/example/spanner/admin/archived/CustomInstanceConfigSampleIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void testCustomInstanceConfigOperations() throws Exception {
4141
SampleRunner.runSample(
4242
() ->
4343
ListInstanceConfigOperationsSample.listInstanceConfigOperations(projectId));
44-
assertTrue(out2.contains("List instance config operation"));
44+
assertTrue(out2.contains("Create instance config operation"));
4545

4646
// Update display name to a randomly generated instance config id.
4747
final String out3 =

samples/snippets/src/test/java/com/example/spanner/admin/archived/DatabaseRolesIT.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
import org.junit.After;
3232
import org.junit.Before;
3333
import org.junit.BeforeClass;
34+
import org.junit.FixMethodOrder;
3435
import org.junit.Test;
3536
import org.junit.runner.RunWith;
3637
import org.junit.runners.JUnit4;
38+
import org.junit.runners.MethodSorters;
3739

3840
/** Integration tests for FGAC samples for GoogleStandardSql dialect. */
3941
@RunWith(JUnit4.class)
42+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
4043
public class DatabaseRolesIT extends SampleTestBase {
4144

4245
private static DatabaseId databaseId;
@@ -105,7 +108,7 @@ public void testAddAndDropDatabaseRole() throws Exception {
105108
SampleRunner.runSample(
106109
() ->
107110
AddAndDropDatabaseRole.addAndDropDatabaseRole(
108-
projectId, instanceId, databaseId.getDatabase(), "new-parent", "new-child"));
111+
projectId, instanceId, databaseId.getDatabase(), "new_parent", "new_child"));
109112
assertTrue(out.contains("Created roles new_parent and new_child and granted privileges"));
110113
assertTrue(out.contains("Revoked privileges and dropped role new_child"));
111114
}

samples/snippets/src/test/java/com/example/spanner/admin/archived/PgSpannerSampleIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void testSample() throws Exception {
130130
assertThat(databaseId).isNotNull();
131131

132132
System.out.println("Create Database ...");
133-
String out = runSample("createpgdatabase");
133+
String out = runSample("createdatabase");
134134
assertThat(out).contains("Created database");
135135
assertThat(out).contains(dbId.getName());
136136

0 commit comments

Comments
 (0)