|
1 | 1 | package com.scalar.db.api; |
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatCode; |
4 | 5 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
5 | 6 |
|
6 | 7 | import com.scalar.db.exception.storage.ExecutionException; |
7 | 8 | import com.scalar.db.io.Column; |
8 | 9 | import com.scalar.db.io.DataType; |
9 | 10 | import com.scalar.db.service.StorageFactory; |
| 11 | +import com.scalar.db.util.AdminTestUtils; |
10 | 12 | import java.sql.SQLException; |
11 | 13 | import java.util.ArrayList; |
12 | 14 | import java.util.Collections; |
@@ -59,7 +61,7 @@ private void dropTable() throws Exception { |
59 | 61 | if (!testData.isImportableTable()) { |
60 | 62 | dropNonImportableTable(testData.getTableName()); |
61 | 63 | } else { |
62 | | - admin.dropTable(getNamespace(), testData.getTableName()); |
| 64 | + admin.dropTable(getNamespace(), testData.getTableName(), true); |
63 | 65 | } |
64 | 66 | } |
65 | 67 | if (!admin.namespaceExists(getNamespace())) { |
@@ -108,6 +110,8 @@ protected abstract List<String> getFloatCompatibleColumnNamesOnExistingDatabase( |
108 | 110 |
|
109 | 111 | protected abstract void dropNonImportableTable(String table) throws Exception; |
110 | 112 |
|
| 113 | + protected abstract AdminTestUtils getAdminTestUtils(String testName); |
| 114 | + |
111 | 115 | @Test |
112 | 116 | public void importTable_ShouldWorkProperly() throws Exception { |
113 | 117 | // Arrange |
@@ -222,6 +226,43 @@ public void alterColumnType_WideningConversion_ForImportedTable_ShouldAlterPrope |
222 | 226 | } |
223 | 227 | } |
224 | 228 |
|
| 229 | + @Test |
| 230 | + public void dropNamespace_ShouldNotDropNonScalarDBTables() throws Exception { |
| 231 | + AdminTestUtils adminTestUtils = getAdminTestUtils(TEST_NAME); |
| 232 | + try { |
| 233 | + // Arrange |
| 234 | + testDataList.addAll(createExistingDatabaseWithAllDataTypes()); |
| 235 | + for (TestData testData : testDataList) { |
| 236 | + if (testData.isImportableTable()) { |
| 237 | + admin.importTable( |
| 238 | + getNamespace(), |
| 239 | + testData.getTableName(), |
| 240 | + Collections.emptyMap(), |
| 241 | + testData.getOverrideColumnsType()); |
| 242 | + } |
| 243 | + } |
| 244 | + for (TestData testData : testDataList) { |
| 245 | + if (testData.isImportableTable()) { |
| 246 | + admin.dropTable(getNamespace(), testData.getTableName()); |
| 247 | + } |
| 248 | + } |
| 249 | + |
| 250 | + // Act |
| 251 | + assertThatCode(() -> admin.dropNamespace(getNamespace())) |
| 252 | + .isInstanceOf(ExecutionException.class); |
| 253 | + |
| 254 | + // Assert |
| 255 | + assertThat(admin.namespaceExists(getNamespace())).isTrue(); |
| 256 | + for (TestData testData : testDataList) { |
| 257 | + if (!testData.isImportableTable()) { |
| 258 | + adminTestUtils.tableExists(getNamespace(), testData.getTableName()); |
| 259 | + } |
| 260 | + } |
| 261 | + } finally { |
| 262 | + adminTestUtils.close(); |
| 263 | + } |
| 264 | + } |
| 265 | + |
225 | 266 | private void importTable_ForImportableTable_ShouldImportProperly( |
226 | 267 | String table, Map<String, DataType> overrideColumnsType, TableMetadata metadata) |
227 | 268 | throws ExecutionException { |
|
0 commit comments