Skip to content

Commit 12f6928

Browse files
committed
Update tests
1 parent 4b8afae commit 12f6928

File tree

9 files changed

+364
-124
lines changed

9 files changed

+364
-124
lines changed

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.scalar.db.storage.cassandra;
22

3+
import com.google.common.util.concurrent.Uninterruptibles;
34
import com.scalar.db.api.DistributedStorageAdminPermissionIntegrationTestBase;
45
import com.scalar.db.util.AdminTestUtils;
56
import com.scalar.db.util.PermissionTestUtils;
@@ -11,6 +12,9 @@
1112

1213
public class CassandraAdminPermissionIntegrationTest
1314
extends DistributedStorageAdminPermissionIntegrationTestBase {
15+
private static final int SLEEP_BETWEEN_RETRIES_SECONDS = 3;
16+
private static final int MAX_RETRY_COUNT = 10;
17+
1418
@Override
1519
protected Properties getProperties(String testName) {
1620
return CassandraEnv.getProperties(testName);
@@ -36,6 +40,90 @@ protected PermissionTestUtils getPermissionTestUtils(String testName) {
3640
return new CassandraPermissionTestUtils(getProperties(testName));
3741
}
3842

43+
@Override
44+
protected void waitForNamespaceCreation() {
45+
try {
46+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
47+
int retryCount = 0;
48+
while (retryCount < MAX_RETRY_COUNT) {
49+
if (utils.namespaceExists(NAMESPACE)) {
50+
utils.close();
51+
return;
52+
}
53+
Uninterruptibles.sleepUninterruptibly(
54+
SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS);
55+
retryCount++;
56+
}
57+
utils.close();
58+
throw new RuntimeException("Namespace was not created after " + MAX_RETRY_COUNT + " retries");
59+
} catch (Exception e) {
60+
throw new RuntimeException("Failed to wait for namespace creation", e);
61+
}
62+
}
63+
64+
@Override
65+
protected void waitForTableCreation() {
66+
try {
67+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
68+
int retryCount = 0;
69+
while (retryCount < MAX_RETRY_COUNT) {
70+
if (utils.tableExists(NAMESPACE, TABLE)) {
71+
utils.close();
72+
return;
73+
}
74+
Uninterruptibles.sleepUninterruptibly(
75+
SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS);
76+
retryCount++;
77+
}
78+
utils.close();
79+
throw new RuntimeException("Table was not created after " + MAX_RETRY_COUNT + " retries");
80+
} catch (Exception e) {
81+
throw new RuntimeException("Failed to wait for table creation", e);
82+
}
83+
}
84+
85+
@Override
86+
protected void waitForNamespaceDeletion() {
87+
try {
88+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
89+
int retryCount = 0;
90+
while (retryCount < MAX_RETRY_COUNT) {
91+
if (!utils.namespaceExists(NAMESPACE)) {
92+
utils.close();
93+
return;
94+
}
95+
Uninterruptibles.sleepUninterruptibly(
96+
SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.MILLISECONDS);
97+
retryCount++;
98+
}
99+
utils.close();
100+
throw new RuntimeException("Namespace was not deleted after " + MAX_RETRY_COUNT + " retries");
101+
} catch (Exception e) {
102+
throw new RuntimeException("Failed to wait for namespace deletion", e);
103+
}
104+
}
105+
106+
@Override
107+
protected void waitForTableDeletion() {
108+
try {
109+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
110+
int retryCount = 0;
111+
while (retryCount < MAX_RETRY_COUNT) {
112+
if (!utils.tableExists(NAMESPACE, TABLE)) {
113+
utils.close();
114+
return;
115+
}
116+
Uninterruptibles.sleepUninterruptibly(
117+
SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS);
118+
retryCount++;
119+
}
120+
utils.close();
121+
throw new RuntimeException("Table was not deleted after " + MAX_RETRY_COUNT + " retries");
122+
} catch (Exception e) {
123+
throw new RuntimeException("Failed to wait for table deletion", e);
124+
}
125+
}
126+
39127
@Test
40128
@Override
41129
@Disabled("Import-related functionality is not supported in Cassandra")

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.scalar.db.storage.cassandra;
22

3+
import com.google.common.util.concurrent.Uninterruptibles;
34
import com.scalar.db.api.DistributedStoragePermissionIntegrationTestBase;
5+
import com.scalar.db.util.AdminTestUtils;
46
import com.scalar.db.util.PermissionTestUtils;
57
import java.util.Collections;
68
import java.util.Map;
79
import java.util.Properties;
10+
import java.util.concurrent.TimeUnit;
811

912
public class CassandraPermissionIntegrationTest
1013
extends DistributedStoragePermissionIntegrationTestBase {
14+
private static final int SLEEP_BETWEEN_RETRIES_SECONDS = 3;
15+
private static final int MAX_RETRY_COUNT = 10;
16+
1117
@Override
1218
protected Properties getProperties(String testName) {
1319
return CassandraEnv.getProperties(testName);
@@ -27,4 +33,29 @@ protected Map<String, String> getCreationOptions() {
2733
protected PermissionTestUtils getPermissionTestUtils(String testName) {
2834
return new CassandraPermissionTestUtils(getProperties(testName));
2935
}
36+
37+
@Override
38+
protected AdminTestUtils getAdminTestUtils(String testName) {
39+
return new CassandraAdminTestUtils(getProperties(testName));
40+
}
41+
42+
@Override
43+
protected void waitForTableCreation() {
44+
try {
45+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
46+
int retryCount = 0;
47+
while (retryCount < MAX_RETRY_COUNT) {
48+
if (utils.tableExists(NAMESPACE, TABLE)) {
49+
utils.close();
50+
return;
51+
}
52+
Uninterruptibles.sleepUninterruptibly(SLEEP_BETWEEN_RETRIES_SECONDS, TimeUnit.SECONDS);
53+
retryCount++;
54+
}
55+
utils.close();
56+
throw new RuntimeException("Table was not created after " + MAX_RETRY_COUNT + " retries");
57+
} catch (Exception e) {
58+
throw new RuntimeException("Failed to wait for table creation", e);
59+
}
60+
}
3061
}

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package com.scalar.db.storage.dynamo;
22

33
import com.google.common.collect.ImmutableMap;
4+
import com.google.common.util.concurrent.Uninterruptibles;
45
import com.scalar.db.api.DistributedStorageAdminPermissionIntegrationTestBase;
56
import com.scalar.db.util.AdminTestUtils;
67
import com.scalar.db.util.PermissionTestUtils;
78
import java.util.Map;
89
import java.util.Properties;
10+
import java.util.concurrent.TimeUnit;
911
import org.junit.jupiter.api.Disabled;
1012
import org.junit.jupiter.api.Test;
1113

1214
public class DynamoAdminPermissionIntegrationTest
1315
extends DistributedStorageAdminPermissionIntegrationTestBase {
16+
private static final int SLEEP_BETWEEN_TESTS_SECONDS = 10;
17+
private static final int SLEEP_BETWEEN_RETRIES_SECONDS = 3;
18+
private static final int MAX_RETRY_COUNT = 10;
19+
1420
@Override
1521
protected Properties getProperties(String testName) {
1622
return DynamoEnv.getProperties(testName);
@@ -36,6 +42,53 @@ protected PermissionTestUtils getPermissionTestUtils(String testName) {
3642
return new DynamoPermissionTestUtils(getProperties(testName));
3743
}
3844

45+
@Override
46+
protected void waitForTableCreation() {
47+
try {
48+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
49+
int retryCount = 0;
50+
while (retryCount < MAX_RETRY_COUNT) {
51+
if (utils.tableExists(NAMESPACE, TABLE)) {
52+
utils.close();
53+
return;
54+
}
55+
Uninterruptibles.sleepUninterruptibly(
56+
SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS);
57+
retryCount++;
58+
}
59+
utils.close();
60+
throw new RuntimeException("Table was not created after " + MAX_RETRY_COUNT + " retries");
61+
} catch (Exception e) {
62+
throw new RuntimeException("Failed to wait for table creation", e);
63+
}
64+
}
65+
66+
@Override
67+
protected void waitForTableDeletion() {
68+
try {
69+
AdminTestUtils utils = getAdminTestUtils(TEST_NAME);
70+
int retryCount = 0;
71+
while (retryCount < MAX_RETRY_COUNT) {
72+
if (!utils.tableExists(NAMESPACE, TABLE)) {
73+
utils.close();
74+
return;
75+
}
76+
Uninterruptibles.sleepUninterruptibly(
77+
SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS);
78+
retryCount++;
79+
}
80+
utils.close();
81+
throw new RuntimeException("Table was not deleted after " + MAX_RETRY_COUNT + " retries");
82+
} catch (Exception e) {
83+
throw new RuntimeException("Failed to wait for table deletion", e);
84+
}
85+
}
86+
87+
@Override
88+
protected void sleepBetweenTests() {
89+
Uninterruptibles.sleepUninterruptibly(SLEEP_BETWEEN_TESTS_SECONDS, TimeUnit.SECONDS);
90+
}
91+
3992
@Test
4093
@Override
4194
@Disabled("Import-related functionality is not supported in DynamoDB")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static Properties getProperties(String testName) {
3535
String isEmulator = System.getProperty(PROP_DYNAMO_EMULATOR, DEFAULT_DYNAMO_EMULATOR);
3636

3737
Properties properties = new Properties();
38-
if (isEmulator.equals("true") && endpointOverride != null) {
38+
if (Boolean.parseBoolean(isEmulator) && endpointOverride != null) {
3939
properties.setProperty(DynamoConfig.ENDPOINT_OVERRIDE, endpointOverride);
4040
}
4141
properties.setProperty(DatabaseConfig.CONTACT_POINTS, region);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.collect.ImmutableMap;
44
import com.scalar.db.api.DistributedStoragePermissionIntegrationTestBase;
5+
import com.scalar.db.util.AdminTestUtils;
56
import com.scalar.db.util.PermissionTestUtils;
67
import java.util.Map;
78
import java.util.Properties;
@@ -27,4 +28,9 @@ protected Map<String, String> getCreationOptions() {
2728
protected PermissionTestUtils getPermissionTestUtils(String testName) {
2829
return new DynamoPermissionTestUtils(getProperties(testName));
2930
}
31+
32+
@Override
33+
protected AdminTestUtils getAdminTestUtils(String testName) {
34+
return new DynamoAdminTestUtils(getProperties(testName));
35+
}
3036
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.scalar.db.storage.jdbc;
22

33
import com.scalar.db.api.DistributedStoragePermissionIntegrationTestBase;
4+
import com.scalar.db.util.AdminTestUtils;
45
import com.scalar.db.util.PermissionTestUtils;
56
import java.util.Properties;
67

@@ -19,4 +20,9 @@ protected Properties getPropertiesForNormalUser(String testName) {
1920
protected PermissionTestUtils getPermissionTestUtils(String testName) {
2021
return new JdbcPermissionTestUtils(getProperties(testName));
2122
}
23+
24+
@Override
25+
protected AdminTestUtils getAdminTestUtils(String testName) {
26+
return new JdbcAdminTestUtils(getProperties(testName));
27+
}
2228
}

integration-test/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
implementation "org.mockito:mockito-inline:${mockitoVersion}"
2121
implementation "org.apache.commons:commons-lang3:${commonsLangVersion}"
2222
implementation "com.google.code.gson:gson:${gsonVersion}"
23+
implementation "dev.failsafe:failsafe:3.3.2"
2324

2425
// for SpotBugs
2526
compileOnly "com.github.spotbugs:spotbugs-annotations:${spotbugsVersion}"

0 commit comments

Comments
 (0)