gjacoby126 commented on a change in pull request #520: PHOENIX-5333: A tool to 
upgrade existing tables/indexes to use self-c…
URL: https://github.com/apache/phoenix/pull/520#discussion_r296922222
 
 

 ##########
 File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexUpgradeToolIT.java
 ##########
 @@ -0,0 +1,303 @@
+/*
+ * 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 com.google.common.collect.Maps;
+import com.sun.jna.StringArray;
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableNotFoundException;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.phoenix.hbase.index.IndexRegionObserver;
+import org.apache.phoenix.hbase.index.Indexer;
+import org.apache.phoenix.index.GlobalIndexChecker;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.mapreduce.index.IndexUpgradeTool;
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized.Parameters;
+import org.junit.runners.Parameterized;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+
+import static org.apache.phoenix.mapreduce.index.IndexUpgradeTool.ROLLBACK_OP;
+import static org.apache.phoenix.mapreduce.index.IndexUpgradeTool.UPGRADE_OP;
+import static org.mockito.Mockito.when;
+
+@RunWith(Parameterized.class)
+@Category(NeedsOwnMiniClusterTest.class)
+public class IndexUpgradeToolIT extends BaseTest {
+
+    private static final String [] INDEXES_LIST = {"TEST.INDEX1", 
"TEST.INDEX2", "TEST1.INDEX3",
+            "TEST1.INDEX2","TEST1.INDEX1","TEST.INDEX3"};
+    private static final String [] TABLE_LIST = 
{"TEST.MOCK1","TEST1.MOCK2","TEST.MOCK3"};
+    private static final String INPUT_LIST = 
"TEST.MOCK1:INDEX1,INDEX2;TEST1.MOCK2:INDEX3,INDEX2,"
+            + "INDEX1;TEST.MOCK3:INDEX3";
+    private static final String HOST = "localhost";
+    private static final String INPUT_FILE = 
"/tmp/input_file_index_upgrade.csv";
+    private final boolean mutable;
+    private final boolean upgrade;
+    private static Map<String, String> serverProps = 
Maps.newHashMapWithExpectedSize(1),
+            clientProps = Maps.newHashMapWithExpectedSize(1);
+    private StringBuilder optionsBuilder;
+    private String tableDDLOptions, port;
+    private Connection conn;
+    private Admin admin;
+    private IndexUpgradeTool iut;
+    private IndexTool indexTool;
+
+    @Before
+    public void setup () throws Exception {
+        optionsBuilder = new StringBuilder();
+
+        indexTool = Mockito.mock(IndexTool.class);
+        String []args = new String[5];
+        when(indexTool.run(args)).thenReturn(0);
+
+        if (upgrade) {
+            // we need to destroy the cluster if it was initiated using 
property as true
+            if (Boolean.TRUE.toString().equals(clientProps
+                    .get(QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB))) 
{
+                tearDownMiniClusterAsync(1);
+            }
+            //To mimic the upgrade scenario, so that table creation uses old 
design
+            clientProps.put(QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB,
+                    Boolean.FALSE.toString());
+        } else {
+            if (Boolean.FALSE.toString().equals(clientProps
+                    .get(QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB))) 
{
+                tearDownMiniClusterAsync(1);
+            }
+            //To mimic the rollback scenario, so that table creation uses new 
design
+            clientProps.put(QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB,
+                    Boolean.TRUE.toString());
+        }
+
+        setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
+                new ReadOnlyProps(clientProps.entrySet().iterator()));
+
+        conn = DriverManager.getConnection(getUrl(), new Properties());
+        conn.setAutoCommit(true);
+        ConnectionQueryServices queryServices = 
conn.unwrap(PhoenixConnection.class)
+                .getQueryServices();
+        admin = queryServices.getAdmin();
+        port = 
queryServices.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT);
+        iut = new IndexUpgradeTool(upgrade ? UPGRADE_OP : ROLLBACK_OP, 
INPUT_LIST,
+                null, HOST, port,null,false, true);
+
+        if (!mutable) {
+            optionsBuilder.append(" IMMUTABLE_ROWS=true");
+        }
+        tableDDLOptions = optionsBuilder.toString();
+        prepareSetup();
+    }
+
+
+    private void prepareSetup() throws SQLException {
+        //inputList is "TEST.MOCK1: INDEX1, INDEX2; TEST1.MOCK2: INDEX3, 
INDEX2, INDEX1;
+        // TEST.MOCK3: INDEX3";
+        conn.createStatement().execute("CREATE TABLE TEST.MOCK1 (id bigint NOT 
NULL "
+                + "PRIMARY KEY, a.name varchar, sal bigint, address 
varchar)"+tableDDLOptions);
+        conn.createStatement().execute("CREATE TABLE TEST1.MOCK2 (id bigint 
NOT NULL "
+                + "PRIMARY KEY, name varchar, city varchar, phone 
bigint)"+tableDDLOptions);
+        conn.createStatement().execute("CREATE TABLE TEST.MOCK3 (id bigint NOT 
NULL "
+                + "PRIMARY KEY, name varchar, age bigint)"+tableDDLOptions);
+
+        conn.createStatement().execute("CREATE INDEX INDEX1 ON TEST.MOCK1 
(sal, a.name)");
+        conn.createStatement().execute("CREATE INDEX INDEX2 ON TEST.MOCK1 
(a.name)");
+        conn.createStatement().execute("CREATE INDEX INDEX1 ON TEST1.MOCK2 
(city)");
+        conn.createStatement().execute("CREATE INDEX INDEX2 ON TEST1.MOCK2 
(phone)");
+        conn.createStatement().execute("CREATE INDEX INDEX3 ON TEST1.MOCK2 
(name)");
+        conn.createStatement().execute("CREATE INDEX INDEX3 ON TEST.MOCK3 
(age, name)");
+    }
+
+    @Parameters(name ="IndexUpgradeToolIT_mutable={0},upgrade={1}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+            {false, false},
+            {true, false},
+            {false, true},
+            {true, true}
+        });
+    }
+
+    public IndexUpgradeToolIT (boolean mutable, boolean upgrade) {
+        this.mutable = mutable;
+        this.upgrade = upgrade;
+    }
+
+    @Test
+    public void testToolWithMultiTablesMultiIndexes() throws Exception {
+        preValidate();
+        iut.prepareToolSetup();
+        iut.executeTool();
+        postValidate();
+    }
+
+    @Test
+    public void testToolWithInputFileParameter() throws Exception {
+        BufferedWriter writer = new BufferedWriter(new FileWriter(new 
File(INPUT_FILE)));
+        writer.write(INPUT_LIST);
+        writer.close();
+
+        preValidate();
+
+        iut.setInputTables(null);
+        iut.setInputFile(INPUT_FILE);
+        iut.prepareToolSetup();
+        iut.executeTool();
+
+        postValidate();
+    }
+
+    @Test
+    public void testToolWithShowParameter() throws Exception {
 
 Review comment:
   nit: test should be called "testToolWithDryRunParameter" or something similar

----------------------------------------------------------------
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

Reply via email to