|
39 | 39 |
|
40 | 40 | import java.io.IOException; |
41 | 41 | import java.sql.Connection; |
| 42 | +import java.sql.ResultSet; |
42 | 43 | import java.sql.SQLException; |
43 | 44 | import java.sql.Statement; |
44 | 45 | import java.util.Collections; |
@@ -164,6 +165,53 @@ public void testRegionGroupNumControlThroughCreation() |
164 | 165 | } |
165 | 166 | } |
166 | 167 |
|
| 168 | + @Test |
| 169 | + public void testRecreateWithPartialMaxRegionGroupNumUsesDefaultCounterpart() throws SQLException { |
| 170 | + try (final Connection connection = EnvFactory.getEnv().getConnection(); |
| 171 | + final Statement statement = connection.createStatement()) { |
| 172 | + final String database = "root.rg_tree_create_schema"; |
| 173 | + statement.execute(String.format("CREATE DATABASE %s;", database)); |
| 174 | + |
| 175 | + try (final ResultSet resultSet = |
| 176 | + statement.executeQuery("SHOW DATABASES DETAILS " + database)) { |
| 177 | + Assert.assertTrue(resultSet.next()); |
| 178 | + Assert.assertEquals( |
| 179 | + testDefaultSchemaRegionGroupNumPerDatabase, |
| 180 | + resultSet.getInt("MaxSchemaRegionGroupNum")); |
| 181 | + Assert.assertEquals( |
| 182 | + testDefaultDataRegionGroupNumPerDatabase, resultSet.getInt("MaxDataRegionGroupNum")); |
| 183 | + Assert.assertFalse(resultSet.next()); |
| 184 | + } |
| 185 | + |
| 186 | + statement.execute(String.format("DROP DATABASE %s;", database)); |
| 187 | + statement.execute( |
| 188 | + String.format("CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=3;", database)); |
| 189 | + |
| 190 | + try (final ResultSet resultSet = |
| 191 | + statement.executeQuery("SHOW DATABASES DETAILS " + database)) { |
| 192 | + Assert.assertTrue(resultSet.next()); |
| 193 | + Assert.assertEquals(3, resultSet.getInt("MaxSchemaRegionGroupNum")); |
| 194 | + Assert.assertEquals( |
| 195 | + testDefaultDataRegionGroupNumPerDatabase, resultSet.getInt("MaxDataRegionGroupNum")); |
| 196 | + Assert.assertFalse(resultSet.next()); |
| 197 | + } |
| 198 | + |
| 199 | + final String dataDatabase = "root.rg_tree_create_data"; |
| 200 | + statement.execute( |
| 201 | + String.format("CREATE DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=4;", dataDatabase)); |
| 202 | + |
| 203 | + try (final ResultSet resultSet = |
| 204 | + statement.executeQuery("SHOW DATABASES DETAILS " + dataDatabase)) { |
| 205 | + Assert.assertTrue(resultSet.next()); |
| 206 | + Assert.assertEquals( |
| 207 | + testDefaultSchemaRegionGroupNumPerDatabase, |
| 208 | + resultSet.getInt("MaxSchemaRegionGroupNum")); |
| 209 | + Assert.assertEquals(4, resultSet.getInt("MaxDataRegionGroupNum")); |
| 210 | + Assert.assertFalse(resultSet.next()); |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + |
167 | 215 | @Test |
168 | 216 | public void testRegionGroupNumControlThroughAlter() |
169 | 217 | throws SQLException, ClientManagerException, IOException, InterruptedException, TException { |
@@ -236,6 +284,69 @@ public void testRegionGroupNumControlThroughAlter() |
236 | 284 | } |
237 | 285 | } |
238 | 286 |
|
| 287 | + @Test |
| 288 | + public void testAlterMaxDataRegionGroupNumCannotDecrease() throws SQLException { |
| 289 | + try (final Connection connection = EnvFactory.getEnv().getConnection(); |
| 290 | + final Statement statement = connection.createStatement()) { |
| 291 | + final String database = "root.rg_tree_decrease"; |
| 292 | + statement.execute( |
| 293 | + String.format("CREATE DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=8;", database)); |
| 294 | + statement.execute( |
| 295 | + String.format("ALTER DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=16;", database)); |
| 296 | + |
| 297 | + final SQLException exception = |
| 298 | + Assert.assertThrows( |
| 299 | + SQLException.class, |
| 300 | + () -> |
| 301 | + statement.execute( |
| 302 | + String.format( |
| 303 | + "ALTER DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=12;", database))); |
| 304 | + Assert.assertTrue( |
| 305 | + exception.getMessage(), |
| 306 | + exception |
| 307 | + .getMessage() |
| 308 | + .contains( |
| 309 | + "MaxDataRegionGroupNum should be greater than or equal to current max " |
| 310 | + + "DataRegionGroupNum: 16.")); |
| 311 | + |
| 312 | + try (final ResultSet resultSet = |
| 313 | + statement.executeQuery("SHOW DATABASES DETAILS " + database)) { |
| 314 | + Assert.assertTrue(resultSet.next()); |
| 315 | + Assert.assertEquals(16, resultSet.getInt("MaxDataRegionGroupNum")); |
| 316 | + Assert.assertFalse(resultSet.next()); |
| 317 | + } |
| 318 | + |
| 319 | + final String schemaDatabase = "root.rg_tree_decrease_schema"; |
| 320 | + statement.execute( |
| 321 | + String.format("CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=4;", schemaDatabase)); |
| 322 | + statement.execute( |
| 323 | + String.format("ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=5;", schemaDatabase)); |
| 324 | + |
| 325 | + final SQLException schemaException = |
| 326 | + Assert.assertThrows( |
| 327 | + SQLException.class, |
| 328 | + () -> |
| 329 | + statement.execute( |
| 330 | + String.format( |
| 331 | + "ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=3;", |
| 332 | + schemaDatabase))); |
| 333 | + Assert.assertTrue( |
| 334 | + schemaException.getMessage(), |
| 335 | + schemaException |
| 336 | + .getMessage() |
| 337 | + .contains( |
| 338 | + "MaxSchemaRegionGroupNum should be greater than or equal to current max " |
| 339 | + + "SchemaRegionGroupNum: 5.")); |
| 340 | + |
| 341 | + try (final ResultSet resultSet = |
| 342 | + statement.executeQuery("SHOW DATABASES DETAILS " + schemaDatabase)) { |
| 343 | + Assert.assertTrue(resultSet.next()); |
| 344 | + Assert.assertEquals(5, resultSet.getInt("MaxSchemaRegionGroupNum")); |
| 345 | + Assert.assertFalse(resultSet.next()); |
| 346 | + } |
| 347 | + } |
| 348 | + } |
| 349 | + |
239 | 350 | @Test |
240 | 351 | public void testDeprecatedRegionGroupNumSqlRejected() throws SQLException { |
241 | 352 | try (final Connection connection = EnvFactory.getEnv().getConnection(); |
|
0 commit comments