ranganathg commented on code in PR #1691: URL: https://github.com/apache/phoenix/pull/1691#discussion_r1341607601
########## phoenix-core/src/it/java/org/apache/phoenix/end2end/InvalidateMetadataCacheIT.java: ########## @@ -0,0 +1,141 @@ +/* + * 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.regionserver.HRegionServer; +import org.apache.phoenix.query.BaseTest; +import org.apache.phoenix.thirdparty.com.google.common.collect.Maps; +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.ReadOnlyProps; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.Map; +import java.util.Properties; + +import static org.apache.hadoop.hbase.coprocessor.CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY; +import static org.apache.phoenix.coprocessor.MetaDataEndpointImpl.PHOENIX_METADATA_CACHE_INVALIDATION_TIMEOUT_MS; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.fail; + +@Category({NeedsOwnMiniClusterTest.class }) +public class InvalidateMetadataCacheIT extends BaseTest { + private static final Logger LOGGER = LoggerFactory.getLogger(InvalidateMetadataCacheIT.class); + + @BeforeClass + public static synchronized void doSetup() throws Exception { + NUM_SLAVES_BASE = 2; + Map<String, String> props = Maps.newHashMapWithExpectedSize(1); + // to fail fast in case of exception. + props.put("hbase.client.retries.number", String.valueOf(0)); + props.put(REGIONSERVER_COPROCESSOR_CONF_KEY, + FailingPhoenixRegionServerEndpoint.class.getName()); + // Setting phoenix metadata cache invalidation timeout to a small number to fail fast. + props.put(PHOENIX_METADATA_CACHE_INVALIDATION_TIMEOUT_MS, String.valueOf(2000)); + setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); + } + + /** + * Add FailingPhoenixRegionServerEndpoint as regionserver co-processor. + * Make one of the regionserver sleep in invalidateServerMetadataCache method. This will trigger + * TimeoutException in MetadataEndpointImpl#invalidateServerMetadataCacheWithRetries method. + * Make sure that ALTER TABLE ADD COLUMN statement fails. + */ + @Test + public void testAddColumnWithTimeout() { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + String dataTableFullName = generateUniqueName(); + String ddl = getCreateTableStmt(dataTableFullName); + HRegionServer regionServerZero = utility.getMiniHBaseCluster().getRegionServer(0); + FailingPhoenixRegionServerEndpoint coprocForRS0 = + getFailingPhoenixRegionServerEndpoint(regionServerZero); + coprocForRS0.sleep(); + try(Connection conn = DriverManager.getConnection(getUrl(), props)) { + conn.createStatement().execute(ddl); + conn.createStatement().execute("ALTER TABLE " + dataTableFullName + + " ADD CF.col2 integer"); + fail("Shouldn't reach heere"); + } catch (Exception e) { + LOGGER.error("Exception while adding column", e); + // This is expected Review Comment: should we add assertTrue in this exception - kind of like a completion of assertion (Act - Arrange - Assert)? similarly below? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
