nsgupta1 commented on a change in pull request #677: PHOENIX-5671 Add tests for ViewUtil URL: https://github.com/apache/phoenix/pull/677#discussion_r366069407
########## File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewUtilIT.java ########## @@ -0,0 +1,315 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.end2end; + +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Table; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.util.SchemaUtil; +import org.apache.phoenix.util.TableViewFinderResult; +import org.apache.phoenix.schema.PTable; +import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ViewUtil; +import org.junit.Test; + +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.Properties; + +import static org.apache.phoenix.coprocessor.MetaDataProtocol.MIN_SPLITTABLE_SYSTEM_CATALOG; +import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_LINK_HBASE_TABLE_NAME; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertEquals; + +public class ViewUtilIT extends ParallelStatsDisabledIT { + + @Test + public void testGetSystemTableForChildLinks() throws Exception { + assertEquals(SYSTEM_LINK_HBASE_TABLE_NAME, ViewUtil.getSystemTableForChildLinks( + MIN_SPLITTABLE_SYSTEM_CATALOG, config)); + + // lower version should also give CHILD_LINK table as server upgrade to advanced version + assertEquals(SYSTEM_LINK_HBASE_TABLE_NAME, ViewUtil.getSystemTableForChildLinks( + MIN_SPLITTABLE_SYSTEM_CATALOG - 1, config)); + } + + @Test + public void testHasChildViewsInGlobalViewCase() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + TableName catalogOrChildTableName = ViewUtil.getSystemTableForChildLinks(0, config); + String schema = generateUniqueName(); + byte[] schemaInBytes = schema.getBytes(StandardCharsets.UTF_8); + byte[] tenantIdInBytes = new byte[0]; + String fullTableName = schema + "." + generateUniqueName(); + String secondLevelViewName = schema + "." + generateUniqueName(); + String thirdLevelViewName4 = schema + "." + generateUniqueName(); + String leafViewName1 = schema + "." + generateUniqueName(); + String leafViewName2 = schema + "." + generateUniqueName(); + + String tableDDLQuery = "CREATE TABLE " + fullTableName + " (A BIGINT PRIMARY KEY, B BIGINT)"; + String viewDDLQuery = "CREATE VIEW %s AS SELECT * FROM %s"; + + try (Connection conn = DriverManager.getConnection(getUrl(), props)) { + conn.createStatement().execute(tableDDLQuery); + conn.createStatement().execute( + String.format(viewDDLQuery, secondLevelViewName, fullTableName)); + conn.createStatement().execute( + String.format(viewDDLQuery, leafViewName1, secondLevelViewName)); + conn.createStatement().execute( + String.format(viewDDLQuery, thirdLevelViewName4, secondLevelViewName)); + conn.createStatement().execute( + String.format(viewDDLQuery, leafViewName2, thirdLevelViewName4)); + + try (PhoenixConnection phoenixConnection = + DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class)) { + Table catalogOrChildTable = phoenixConnection.getQueryServices().getTable( + SchemaUtil.getPhysicalName(catalogOrChildTableName.toBytes(), + phoenixConnection.getQueryServices().getProps()).getName()); + + assertEquals(true, ViewUtil.hasChildViews(catalogOrChildTable, Review comment: @yanxinyi you can directly use assertTrue or assertFalse instead of assertEquals(true, expression). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
