|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.relational.it.schema; |
| 21 | + |
| 22 | +import org.apache.iotdb.consensus.ConsensusFactory; |
| 23 | +import org.apache.iotdb.db.it.utils.TestUtils; |
| 24 | +import org.apache.iotdb.it.env.EnvFactory; |
| 25 | +import org.apache.iotdb.it.framework.IoTDBTestRunner; |
| 26 | +import org.apache.iotdb.itbase.category.TableClusterIT; |
| 27 | +import org.apache.iotdb.itbase.env.BaseEnv; |
| 28 | + |
| 29 | +import org.junit.After; |
| 30 | +import org.junit.Before; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.experimental.categories.Category; |
| 33 | +import org.junit.runner.RunWith; |
| 34 | + |
| 35 | +import java.sql.Connection; |
| 36 | +import java.sql.SQLException; |
| 37 | +import java.sql.Statement; |
| 38 | +import java.util.Collections; |
| 39 | + |
| 40 | +@RunWith(IoTDBTestRunner.class) |
| 41 | +@Category({TableClusterIT.class}) |
| 42 | +public class IoTDBDatabaseAutoDataRegionGroupQuotaIT { |
| 43 | + |
| 44 | + private static final int CONFIG_NODE_NUM = 1; |
| 45 | + private static final int DATA_NODE_NUM = 3; |
| 46 | + private static final int SCHEMA_REPLICATION_FACTOR = 3; |
| 47 | + private static final int DATA_REPLICATION_FACTOR = 1; |
| 48 | + private static final int DATA_REGION_PER_DATA_NODE = 2; |
| 49 | + |
| 50 | + @Before |
| 51 | + public void setUp() throws Exception { |
| 52 | + EnvFactory.getEnv() |
| 53 | + .getConfig() |
| 54 | + .getCommonConfig() |
| 55 | + .setSchemaRegionGroupExtensionPolicy("CUSTOM") |
| 56 | + .setDataRegionGroupExtensionPolicy("AUTO") |
| 57 | + .setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) |
| 58 | + .setDefaultSchemaRegionGroupNumPerDatabase(1) |
| 59 | + .setDefaultDataRegionGroupNumPerDatabase(1) |
| 60 | + .setSchemaReplicationFactor(SCHEMA_REPLICATION_FACTOR) |
| 61 | + .setDataReplicationFactor(DATA_REPLICATION_FACTOR) |
| 62 | + .setDataRegionPerDataNode(DATA_REGION_PER_DATA_NODE); |
| 63 | + EnvFactory.getEnv().initClusterEnvironment(CONFIG_NODE_NUM, DATA_NODE_NUM); |
| 64 | + } |
| 65 | + |
| 66 | + @After |
| 67 | + public void tearDown() throws Exception { |
| 68 | + EnvFactory.getEnv().cleanClusterEnvironment(); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testMaxDataRegionGroupNumUsesDataReplicationFactor() throws SQLException { |
| 73 | + try (final Connection connection = |
| 74 | + EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); |
| 75 | + final Statement statement = connection.createStatement()) { |
| 76 | + final int expectedMaxDataRegionGroupNum = |
| 77 | + (int) |
| 78 | + Math.ceil( |
| 79 | + (double) DATA_REGION_PER_DATA_NODE * DATA_NODE_NUM / DATA_REPLICATION_FACTOR); |
| 80 | + |
| 81 | + statement.execute("create database test_data_region_rf with(max_schema_region_group_num=2)"); |
| 82 | + |
| 83 | + TestUtils.assertResultSetEqual( |
| 84 | + statement.executeQuery( |
| 85 | + "select database, max_schema_region_group_num, max_data_region_group_num " |
| 86 | + + "from information_schema.databases where database = 'test_data_region_rf'"), |
| 87 | + "database,max_schema_region_group_num,max_data_region_group_num,", |
| 88 | + Collections.singleton("test_data_region_rf,2," + expectedMaxDataRegionGroupNum + ",")); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments