Skip to content

Commit 6abf46d

Browse files
authored
Add wait for cache expiry (#3040)
1 parent 53383a9 commit 6abf46d

18 files changed

+154
-112
lines changed

core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static Properties getProperties(String testName) {
3737
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
3838
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
3939

40+
// Metadata cache expiration time
41+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
42+
4043
return properties;
4144
}
4245

core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public static Properties getProperties(String testName) {
3232
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
3333
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
3434

35+
// Metadata cache expiration time
36+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
37+
3538
return properties;
3639
}
3740

core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public static Properties getProperties(String testName) {
5252
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
5353
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
5454

55+
// Metadata cache expiration time
56+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
57+
5558
return properties;
5659
}
5760

core/src/integration-test/java/com/scalar/db/storage/jdbc/ConsensusCommitAdminIntegrationTestWithJdbcDatabase.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.catchThrowable;
66

7+
import com.google.common.util.concurrent.Uninterruptibles;
78
import com.scalar.db.api.DistributedTransactionManager;
89
import com.scalar.db.api.Insert;
910
import com.scalar.db.api.InsertBuilder;
@@ -28,6 +29,7 @@
2829
import java.util.List;
2930
import java.util.Map;
3031
import java.util.Properties;
32+
import java.util.concurrent.TimeUnit;
3133
import org.junit.jupiter.api.Test;
3234
import org.junit.jupiter.api.condition.DisabledIf;
3335
import org.junit.jupiter.api.condition.EnabledIf;
@@ -329,8 +331,8 @@ public void alterColumnType_WideningConversion_ShouldAlterColumnTypesCorrectly()
329331
@Test
330332
@EnabledIf("isOracle")
331333
public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorrectly()
332-
throws ExecutionException, IOException, TransactionException {
333-
try {
334+
throws ExecutionException, TransactionException {
335+
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
334336
// Arrange
335337
Map<String, String> options = getCreationOptions();
336338
TableMetadata.Builder currentTableMetadataBuilder =
@@ -346,23 +348,24 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
346348

347349
int expectedColumn3Value = 1;
348350
float expectedColumn4Value = 4.0f;
349-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
350-
InsertBuilder.Buildable insert =
351-
Insert.newBuilder()
352-
.namespace(namespace1)
353-
.table(TABLE4)
354-
.partitionKey(Key.ofInt("c1", 1))
355-
.clusteringKey(Key.ofInt("c2", 2))
356-
.intValue("c3", expectedColumn3Value)
357-
.floatValue("c4", expectedColumn4Value);
358-
transactionalInsert(manager, insert.build());
359-
}
351+
InsertBuilder.Buildable insert =
352+
Insert.newBuilder()
353+
.namespace(namespace1)
354+
.table(TABLE4)
355+
.partitionKey(Key.ofInt("c1", 1))
356+
.clusteringKey(Key.ofInt("c2", 2))
357+
.intValue("c3", expectedColumn3Value)
358+
.floatValue("c4", expectedColumn4Value);
359+
transactionalInsert(manager, insert.build());
360360

361361
// Act
362362
admin.alterColumnType(namespace1, TABLE4, "c3", DataType.BIGINT);
363363
Throwable exception =
364364
catchThrowable(() -> admin.alterColumnType(namespace1, TABLE4, "c4", DataType.DOUBLE));
365365

366+
// Wait for cache expiry
367+
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
368+
366369
// Assert
367370
assertThat(exception).isInstanceOf(UnsupportedOperationException.class);
368371
TableMetadata.Builder expectedTableMetadataBuilder =
@@ -376,18 +379,16 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
376379
TableMetadata expectedTableMetadata = expectedTableMetadataBuilder.build();
377380
assertThat(admin.getTableMetadata(namespace1, TABLE4)).isEqualTo(expectedTableMetadata);
378381

379-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
380-
Scan scan =
381-
Scan.newBuilder()
382-
.namespace(namespace1)
383-
.table(TABLE4)
384-
.partitionKey(Key.ofInt("c1", 1))
385-
.build();
386-
List<Result> results = transactionalScan(manager, scan);
387-
assertThat(results).hasSize(1);
388-
Result result = results.get(0);
389-
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
390-
}
382+
Scan scan =
383+
Scan.newBuilder()
384+
.namespace(namespace1)
385+
.table(TABLE4)
386+
.partitionKey(Key.ofInt("c1", 1))
387+
.build();
388+
List<Result> results = transactionalScan(manager, scan);
389+
assertThat(results).hasSize(1);
390+
Result result = results.get(0);
391+
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
391392
} finally {
392393
admin.dropTable(namespace1, TABLE4, true);
393394
}

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminIntegrationTest.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.catchThrowable;
66

7+
import com.google.common.util.concurrent.Uninterruptibles;
78
import com.scalar.db.api.DistributedStorage;
89
import com.scalar.db.api.DistributedStorageAdminIntegrationTestBase;
910
import com.scalar.db.api.Put;
@@ -28,6 +29,7 @@
2829
import java.util.List;
2930
import java.util.Map;
3031
import java.util.Properties;
32+
import java.util.concurrent.TimeUnit;
3133
import org.junit.jupiter.api.Test;
3234
import org.junit.jupiter.api.condition.DisabledIf;
3335
import org.junit.jupiter.api.condition.EnabledIf;
@@ -398,7 +400,7 @@ public void alterColumnType_WideningConversion_ShouldAlterColumnTypesCorrectly()
398400
@EnabledIf("isOracle")
399401
public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorrectly()
400402
throws ExecutionException, IOException {
401-
try {
403+
try (DistributedStorage storage = storageFactory.getStorage()) {
402404
// Arrange
403405
Map<String, String> options = getCreationOptions();
404406
TableMetadata.Builder currentTableMetadataBuilder =
@@ -414,17 +416,15 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
414416

415417
int expectedColumn3Value = 1;
416418
float expectedColumn4Value = 4.0f;
417-
try (DistributedStorage storage = storageFactory.getStorage()) {
418-
PutBuilder.Buildable put =
419-
Put.newBuilder()
420-
.namespace(getNamespace1())
421-
.table(getTable4())
422-
.partitionKey(Key.ofInt(getColumnName1(), 1))
423-
.clusteringKey(Key.ofInt(getColumnName2(), 2))
424-
.intValue(getColumnName3(), expectedColumn3Value)
425-
.floatValue(getColumnName4(), expectedColumn4Value);
426-
storage.put(put.build());
427-
}
419+
PutBuilder.Buildable put =
420+
Put.newBuilder()
421+
.namespace(getNamespace1())
422+
.table(getTable4())
423+
.partitionKey(Key.ofInt(getColumnName1(), 1))
424+
.clusteringKey(Key.ofInt(getColumnName2(), 2))
425+
.intValue(getColumnName3(), expectedColumn3Value)
426+
.floatValue(getColumnName4(), expectedColumn4Value);
427+
storage.put(put.build());
428428

429429
// Act
430430
admin.alterColumnType(getNamespace1(), getTable4(), getColumnName3(), DataType.BIGINT);
@@ -434,6 +434,9 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
434434
admin.alterColumnType(
435435
getNamespace1(), getTable4(), getColumnName4(), DataType.DOUBLE));
436436

437+
// Wait for cache expiry
438+
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
439+
437440
// Assert
438441
assertThat(exception).isInstanceOf(UnsupportedOperationException.class);
439442
TableMetadata.Builder expectedTableMetadataBuilder =
@@ -448,19 +451,17 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
448451
assertThat(admin.getTableMetadata(getNamespace1(), getTable4()))
449452
.isEqualTo(expectedTableMetadata);
450453

451-
try (DistributedStorage storage = storageFactory.getStorage()) {
452-
Scan scan =
453-
Scan.newBuilder()
454-
.namespace(getNamespace1())
455-
.table(getTable4())
456-
.partitionKey(Key.ofInt(getColumnName1(), 1))
457-
.build();
458-
try (Scanner scanner = storage.scan(scan)) {
459-
List<Result> results = scanner.all();
460-
assertThat(results).hasSize(1);
461-
Result result = results.get(0);
462-
assertThat(result.getBigInt(getColumnName3())).isEqualTo(expectedColumn3Value);
463-
}
454+
Scan scan =
455+
Scan.newBuilder()
456+
.namespace(getNamespace1())
457+
.table(getTable4())
458+
.partitionKey(Key.ofInt(getColumnName1(), 1))
459+
.build();
460+
try (Scanner scanner = storage.scan(scan)) {
461+
List<Result> results = scanner.all();
462+
assertThat(results).hasSize(1);
463+
Result result = results.get(0);
464+
assertThat(result.getBigInt(getColumnName3())).isEqualTo(expectedColumn3Value);
464465
}
465466
} finally {
466467
admin.dropTable(getNamespace1(), getTable4(), true);

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcEnv.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static Properties getProperties(String testName) {
3737
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
3838
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
3939

40+
// Metadata cache expiration time
41+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
42+
4043
return properties;
4144
}
4245

core/src/integration-test/java/com/scalar/db/storage/jdbc/SingleCrudOperationTransactionAdminIntegrationTestWithJdbcDatabase.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.assertj.core.api.Assertions.assertThatCode;
55
import static org.assertj.core.api.Assertions.catchThrowable;
66

7+
import com.google.common.util.concurrent.Uninterruptibles;
78
import com.scalar.db.api.DistributedTransactionManager;
89
import com.scalar.db.api.Insert;
910
import com.scalar.db.api.InsertBuilder;
@@ -28,6 +29,7 @@
2829
import java.util.List;
2930
import java.util.Map;
3031
import java.util.Properties;
32+
import java.util.concurrent.TimeUnit;
3133
import org.junit.jupiter.api.Test;
3234
import org.junit.jupiter.api.condition.DisabledIf;
3335
import org.junit.jupiter.api.condition.EnabledIf;
@@ -329,8 +331,8 @@ public void alterColumnType_WideningConversion_ShouldAlterColumnTypesCorrectly()
329331
@Test
330332
@EnabledIf("isOracle")
331333
public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorrectly()
332-
throws ExecutionException, IOException, TransactionException {
333-
try {
334+
throws ExecutionException, TransactionException {
335+
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
334336
// Arrange
335337
Map<String, String> options = getCreationOptions();
336338
TableMetadata.Builder currentTableMetadataBuilder =
@@ -346,23 +348,24 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
346348

347349
int expectedColumn3Value = 1;
348350
float expectedColumn4Value = 4.0f;
349-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
350-
InsertBuilder.Buildable insert =
351-
Insert.newBuilder()
352-
.namespace(namespace1)
353-
.table(TABLE4)
354-
.partitionKey(Key.ofInt("c1", 1))
355-
.clusteringKey(Key.ofInt("c2", 2))
356-
.intValue("c3", expectedColumn3Value)
357-
.floatValue("c4", expectedColumn4Value);
358-
transactionalInsert(manager, insert.build());
359-
}
351+
InsertBuilder.Buildable insert =
352+
Insert.newBuilder()
353+
.namespace(namespace1)
354+
.table(TABLE4)
355+
.partitionKey(Key.ofInt("c1", 1))
356+
.clusteringKey(Key.ofInt("c2", 2))
357+
.intValue("c3", expectedColumn3Value)
358+
.floatValue("c4", expectedColumn4Value);
359+
transactionalInsert(manager, insert.build());
360360

361361
// Act
362362
admin.alterColumnType(namespace1, TABLE4, "c3", DataType.BIGINT);
363363
Throwable exception =
364364
catchThrowable(() -> admin.alterColumnType(namespace1, TABLE4, "c4", DataType.DOUBLE));
365365

366+
// Wait for cache expiry
367+
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
368+
366369
// Assert
367370
assertThat(exception).isInstanceOf(UnsupportedOperationException.class);
368371
TableMetadata.Builder expectedTableMetadataBuilder =
@@ -376,18 +379,16 @@ public void alterColumnType_Oracle_WideningConversion_ShouldAlterColumnTypesCorr
376379
TableMetadata expectedTableMetadata = expectedTableMetadataBuilder.build();
377380
assertThat(admin.getTableMetadata(namespace1, TABLE4)).isEqualTo(expectedTableMetadata);
378381

379-
try (DistributedTransactionManager manager = transactionFactory.getTransactionManager()) {
380-
Scan scan =
381-
Scan.newBuilder()
382-
.namespace(namespace1)
383-
.table(TABLE4)
384-
.partitionKey(Key.ofInt("c1", 1))
385-
.build();
386-
List<Result> results = transactionalScan(manager, scan);
387-
assertThat(results).hasSize(1);
388-
Result result = results.get(0);
389-
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
390-
}
382+
Scan scan =
383+
Scan.newBuilder()
384+
.namespace(namespace1)
385+
.table(TABLE4)
386+
.partitionKey(Key.ofInt("c1", 1))
387+
.build();
388+
List<Result> results = transactionalScan(manager, scan);
389+
assertThat(results).hasSize(1);
390+
Result result = results.get(0);
391+
assertThat(result.getBigInt("c3")).isEqualTo(expectedColumn3Value);
391392
} finally {
392393
admin.dropTable(namespace1, TABLE4, true);
393394
}

core/src/integration-test/java/com/scalar/db/storage/multistorage/ConsensusCommitNullMetadataIntegrationTestWithMultiStorage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ protected Properties getProperties(String testName) {
5757
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
5858
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
5959

60+
// Metadata cache expiration time
61+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
62+
6063
return ConsensusCommitTestUtils.loadConsensusCommitProperties(properties);
6164
}
6265

core/src/integration-test/java/com/scalar/db/storage/multistorage/ConsensusCommitSpecificIntegrationTestWithMultiStorage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ protected Properties getProperties(String testName) {
5757
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
5858
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + testName);
5959

60+
// Metadata cache expiration time
61+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
62+
6063
return ConsensusCommitTestUtils.loadConsensusCommitProperties(properties);
6164
}
6265

core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageAdminIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ private void initMultiStorageAdmin() {
143143
DatabaseConfig.SYSTEM_NAMESPACE_NAME,
144144
DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME + "_" + TEST_NAME);
145145

146+
// Metadata cache expiration time
147+
properties.setProperty(DatabaseConfig.METADATA_CACHE_EXPIRATION_TIME_SECS, "1");
148+
146149
DatabaseConfig databaseConfig = new DatabaseConfig(properties);
147150
multiStorageAdmin = new MultiStorageAdmin(databaseConfig);
148151

0 commit comments

Comments
 (0)