7272@ Category (ParallelIntegrationTest .class )
7373@ RunWith (JUnit4 .class )
7474public class ITDatabaseAdminTest {
75+ private static final long DATABASE_TIMEOUT_MINUTES = 5 ;
76+ private static final long BACKUP_TIMEOUT_MINUTES = 20 ;
77+ private static final long RESTORE_TIMEOUT_MINUTES = 10 ;
7578 @ ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv ();
7679 private DatabaseAdminClient dbAdminClient ;
7780 private RemoteSpannerHelper testHelper ;
@@ -98,7 +101,7 @@ public void databaseOperations() throws Exception {
98101 String statement1 = "CREATE TABLE T (\n " + " K STRING(MAX),\n " + ") PRIMARY KEY(K)" ;
99102 OperationFuture <Database , CreateDatabaseMetadata > op =
100103 dbAdminClient .createDatabase (instanceId , dbId , ImmutableList .of (statement1 ));
101- Database db = op .get ();
104+ Database db = op .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
102105 dbs .add (db );
103106 assertThat (db .getId ().getDatabase ()).isEqualTo (dbId );
104107
@@ -119,7 +122,7 @@ public void databaseOperations() throws Exception {
119122 String statement2 = "CREATE TABLE T2 (\n " + " K2 STRING(MAX),\n " + ") PRIMARY KEY(K2)" ;
120123 OperationFuture <?, ?> op2 =
121124 dbAdminClient .updateDatabaseDdl (instanceId , dbId , ImmutableList .of (statement2 ), null );
122- op2 .get ();
125+ op2 .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
123126 List <String > statementsInDb = dbAdminClient .getDatabaseDdl (instanceId , dbId );
124127 assertThat (statementsInDb ).containsExactly (statement1 , statement2 );
125128
@@ -140,15 +143,15 @@ public void updateDdlRetry() throws Exception {
140143 String statement1 = "CREATE TABLE T (\n " + " K STRING(MAX),\n " + ") PRIMARY KEY(K)" ;
141144 OperationFuture <Database , CreateDatabaseMetadata > op =
142145 dbAdminClient .createDatabase (instanceId , dbId , ImmutableList .of (statement1 ));
143- Database db = op .get ();
146+ Database db = op .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
144147 dbs .add (db );
145148 String statement2 = "CREATE TABLE T2 (\n " + " K2 STRING(MAX),\n " + ") PRIMARY KEY(K2)" ;
146149 OperationFuture <Void , UpdateDatabaseDdlMetadata > op1 =
147150 dbAdminClient .updateDatabaseDdl (instanceId , dbId , ImmutableList .of (statement2 ), "myop" );
148151 OperationFuture <Void , UpdateDatabaseDdlMetadata > op2 =
149152 dbAdminClient .updateDatabaseDdl (instanceId , dbId , ImmutableList .of (statement2 ), "myop" );
150- op1 .get ();
151- op2 .get ();
153+ op1 .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
154+ op2 .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
152155
153156 // Remove the progress list from the metadata before comparing, as there could be small
154157 // differences between the two in the reported progress depending on exactly when each
@@ -167,7 +170,7 @@ public void databaseOperationsViaEntity() throws Exception {
167170 String statement1 = "CREATE TABLE T (\n " + " K STRING(MAX),\n " + ") PRIMARY KEY(K)" ;
168171 OperationFuture <Database , CreateDatabaseMetadata > op =
169172 dbAdminClient .createDatabase (instanceId , dbId , ImmutableList .of (statement1 ));
170- Database db = op .get ();
173+ Database db = op .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
171174 dbs .add (db );
172175 assertThat (db .getId ().getDatabase ()).isEqualTo (dbId );
173176
@@ -176,7 +179,7 @@ public void databaseOperationsViaEntity() throws Exception {
176179
177180 String statement2 = "CREATE TABLE T2 (\n " + " K2 STRING(MAX),\n " + ") PRIMARY KEY(K2)" ;
178181 OperationFuture <?, ?> op2 = db .updateDdl (ImmutableList .of (statement2 ), null );
179- op2 .get ();
182+ op2 .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES );
180183 Iterable <String > statementsInDb = db .getDdl ();
181184 assertThat (statementsInDb ).containsExactly (statement1 , statement2 );
182185 db .drop ();
@@ -308,12 +311,12 @@ public void testRetryNonIdempotentRpcsReturningLongRunningOperations() throws Ex
308311 testHelper .getInstanceId ().getInstance (),
309312 initialDatabaseId ,
310313 Collections .emptyList ());
311- databases .add (op .get ());
314+ databases .add (op .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES ));
312315 // Keep track of the original create time of this database, as we will drop this database
313316 // later and create another one with the exact same name. That means that the ListOperations
314317 // call will return at least two CreateDatabase operations. The retry logic should always
315318 // pick the last one.
316- initialDbCreateTime = op .get ().getCreateTime ();
319+ initialDbCreateTime = op .get (DATABASE_TIMEOUT_MINUTES , TimeUnit . MINUTES ).getCreateTime ();
317320 // Assert that the CreateDatabase RPC was called only once, and that the operation tracking
318321 // was resumed through a GetOperation call.
319322 assertThat (createDbInterceptor .methodCount .get ()).isEqualTo (1 );
@@ -340,7 +343,7 @@ public void testRetryNonIdempotentRpcsReturningLongRunningOperations() throws Ex
340343 databaseId ,
341344 Timestamp .ofTimeSecondsAndNanos (
342345 Timestamp .now ().getSeconds () + TimeUnit .SECONDS .convert (7L , TimeUnit .DAYS ), 0 ));
343- backups .add (op .get ());
346+ backups .add (op .get (BACKUP_TIMEOUT_MINUTES , TimeUnit . MINUTES ));
344347 // Assert that the CreateBackup RPC was called only once, and that the operation tracking
345348 // was resumed through a GetOperation call.
346349 assertThat (createDbInterceptor .methodCount .get ()).isEqualTo (1 );
@@ -368,7 +371,7 @@ public void testRetryNonIdempotentRpcsReturningLongRunningOperations() throws Ex
368371 backupId ,
369372 testHelper .getInstanceId ().getInstance (),
370373 restoredDbId );
371- databases .add (op .get ());
374+ databases .add (op .get (RESTORE_TIMEOUT_MINUTES , TimeUnit . MINUTES ));
372375 // Assert that the RestoreDatabase RPC was called only once, and that the operation
373376 // tracking was resumed through a GetOperation call.
374377 assertThat (createDbInterceptor .methodCount .get ()).isEqualTo (1 );
@@ -409,7 +412,8 @@ public void testRetryNonIdempotentRpcsReturningLongRunningOperations() throws Ex
409412 Collections .emptyList ());
410413 // Check that the second database was created and has a greater creation time than the
411414 // first.
412- Timestamp secondCreationTime = op .get ().getCreateTime ();
415+ Timestamp secondCreationTime =
416+ op .get (DATABASE_TIMEOUT_MINUTES , TimeUnit .MINUTES ).getCreateTime ();
413417 // TODO: Change this to greaterThan when the create time of a database is reported back by
414418 // the server.
415419 assertThat (secondCreationTime ).isAtLeast (initialDbCreateTime );
0 commit comments