Github user samarthjain commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/127#discussion_r44853416
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheIT.java 
---
    @@ -0,0 +1,122 @@
    +package org.apache.phoenix.tx;
    +
    +import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
    +import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
    +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
    +import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
    +import static org.junit.Assert.assertFalse;
    +import static org.mockito.Matchers.anyLong;
    +import static org.mockito.Matchers.eq;
    +import static org.mockito.Matchers.isNull;
    +import static org.mockito.Mockito.reset;
    +import static org.mockito.Mockito.times;
    +import static org.mockito.Mockito.verify;
    +
    +import java.sql.Connection;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.util.Properties;
    +
    +import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT;
    +import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
    +import org.apache.phoenix.query.ConnectionQueryServices;
    +import org.apache.phoenix.query.QueryConstants;
    +import org.apache.phoenix.schema.MetaDataClient;
    +import org.apache.phoenix.schema.PName;
    +import org.apache.phoenix.schema.types.PVarchar;
    +import org.apache.phoenix.util.PhoenixRuntime;
    +import org.apache.phoenix.util.PropertiesUtil;
    +import org.apache.phoenix.util.TestUtil;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.mockito.Mockito;
    +
    +/**
    + * Verifies the number of rpcs calls from {@link MetaDataClient} 
updateCache() 
    + * for transactional and non-transactional tables.
    + */
    +public class UpdateCacheIT extends BaseHBaseManagedTimeIT {
    +
    +    @Before
    +    public void setUp() throws SQLException {
    +        ensureTableCreated(getUrl(), TRANSACTIONAL_DATA_TABLE);
    +        ensureTableCreated(getUrl(), MUTABLE_INDEX_DATA_TABLE);
    +    }
    +
    +   @Test
    +   public void testUpdateCacheForTxnTable() throws Exception {
    +           helpTestUpdateCache(true, null);
    +   }
    +   
    +   @Test
    +   public void testUpdateCacheForNonTxnTable() throws Exception {
    +           helpTestUpdateCache(false, null);
    +   }
    +   
    +   public static void helpTestUpdateCache(boolean isTransactional, Long 
scn) throws Exception {
    +           String tableName = isTransactional ? TRANSACTIONAL_DATA_TABLE : 
MUTABLE_INDEX_DATA_TABLE;
    +           String fullTableName = INDEX_DATA_SCHEMA + 
QueryConstants.NAME_SEPARATOR + tableName;
    +           String selectSql = "SELECT * FROM "+fullTableName;
    +           // use a spyed ConnectionQueryServices so we can verify calls 
to getTable
    +           ConnectionQueryServices connectionQueryServices = 
Mockito.spy(driver.getConnectionQueryServices(getUrl(), 
PropertiesUtil.deepCopy(TEST_PROPERTIES)));
    +           Properties props = new Properties();
    +           props.putAll(PhoenixEmbeddedDriver.DEFFAULT_PROPS.asMap());
    +           if (scn!=null) {
    +                   props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(scn));
    +           }
    +           Connection conn = connectionQueryServices.connect(getUrl(), 
props);
    +           try {
    +                   conn.setAutoCommit(false);
    +           String upsert = "UPSERT INTO " + fullTableName + "(varchar_pk, 
char_pk, int_pk, long_pk, decimal_pk, date_pk) VALUES(?, ?, ?, ?, ?, ?)";
    +           PreparedStatement stmt = conn.prepareStatement(upsert);
    +                   // upsert three rows
    +           TestUtil.setRowKeyColumns(stmt, 1);
    +                   stmt.execute();
    +                   TestUtil.setRowKeyColumns(stmt, 2);
    +                   stmt.execute();
    +                   TestUtil.setRowKeyColumns(stmt, 3);
    +                   stmt.execute();
    +                   conn.commit();
    +                   // for non txn tables verify only one rpc to fetch 
table metadata, 
    +                   // for txn tables the table will already be present in 
the cache because MetaDataClient.createTableInternal starts a txn 
    +//                 if (!isTransactional) {
    --- End diff --
    
    Minor nit: remove commented code, please


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to