kadirozde commented on code in PR #1866:
URL: https://github.com/apache/phoenix/pull/1866#discussion_r1561771543


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCBaseIT.java:
##########
@@ -0,0 +1,655 @@
+/*
+ * 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.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.ToNumberPolicy;
+import org.apache.phoenix.hbase.index.IndexRegionObserver;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.TableProperty;
+import org.apache.phoenix.util.CDCUtil;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ManualEnvironmentEdge;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.apache.phoenix.query.QueryConstants.CDC_CHANGE_IMAGE;
+import static org.apache.phoenix.query.QueryConstants.CDC_DELETE_EVENT_TYPE;
+import static org.apache.phoenix.query.QueryConstants.CDC_EVENT_TYPE;
+import static org.apache.phoenix.query.QueryConstants.CDC_POST_IMAGE;
+import static org.apache.phoenix.query.QueryConstants.CDC_PRE_IMAGE;
+import static org.apache.phoenix.query.QueryConstants.CDC_UPSERT_EVENT_TYPE;
+import static org.apache.phoenix.util.MetaDataUtil.getViewIndexPhysicalName;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class CDCBaseIT extends ParallelStatsDisabledIT {
+    static final HashSet<PTable.CDCChangeScope> CHANGE_IMG =
+            new HashSet<>(Arrays.asList(PTable.CDCChangeScope.CHANGE));
+    static final HashSet<PTable.CDCChangeScope> PRE_POST_IMG = new HashSet<>(
+            Arrays.asList(PTable.CDCChangeScope.PRE, 
PTable.CDCChangeScope.POST));
+
+    protected ManualEnvironmentEdge injectEdge;
+    protected Gson gson = new GsonBuilder()
+            .setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
+            .create();
+    protected Calendar cal = Calendar.getInstance();
+
+    protected void createTable(Connection conn, String table_sql)
+            throws Exception {
+        createTable(conn, table_sql, null, false, null, false, null);
+    }
+
+    protected void createTable(Connection conn, String table_sql,
+                               PTable.QualifierEncodingScheme encodingScheme)
+            throws Exception {
+        createTable(conn, table_sql, encodingScheme, false, null, false, null);
+    }
+
+    protected void createTable(Connection conn, String table_sql,
+                               PTable.QualifierEncodingScheme encodingScheme, 
boolean multitenant)
+            throws Exception {
+        createTable(conn, table_sql, encodingScheme, multitenant, null, false, 
null);
+    }
+
+    protected void createTable(Connection conn, String table_sql,
+                               PTable.QualifierEncodingScheme encodingScheme, 
boolean multitenant,
+                               Integer nSaltBuckets, boolean immutable, 
PTable.ImmutableStorageScheme immutableStorageScheme)
+            throws Exception {
+        createTable(conn, table_sql, encodingScheme, multitenant, 
nSaltBuckets, null, immutable, immutableStorageScheme);
+    }
+
+    protected void createTable(Connection conn, String table_sql,
+                               PTable.QualifierEncodingScheme encodingScheme, 
boolean multitenant,
+                               Integer nSaltBuckets, PTable.IndexType 
indexType, boolean immutable,
+                               PTable.ImmutableStorageScheme 
immutableStorageScheme)
+            throws Exception {
+        createTable(conn, table_sql, new HashMap<String, Object>() {{
+            put(TableProperty.COLUMN_ENCODED_BYTES.getPropertyName(), 
encodingScheme != null ?
+                    new Byte(encodingScheme.getSerializedMetadataValue()) : 
null);
+            put(TableProperty.MULTI_TENANT.getPropertyName(), multitenant);
+            put(TableProperty.SALT_BUCKETS.getPropertyName(), nSaltBuckets);
+            put(TableProperty.INDEX_TYPE.getPropertyName(), indexType);
+            put(TableProperty.IMMUTABLE_ROWS.getPropertyName(), immutable);
+            put(TableProperty.IMMUTABLE_STORAGE_SCHEME.getPropertyName(), 
immutableStorageScheme != null ?
+                    immutableStorageScheme.name() : null);
+        }});
+    }
+
+    protected void createTable(Connection conn, String table_sql,
+                               Map<String,Object> tableProps) throws Exception 
{
+        List<String> props = new ArrayList<>();
+        Byte encodingScheme = (Byte) 
TableProperty.COLUMN_ENCODED_BYTES.getValue(tableProps);
+        if (encodingScheme != null && encodingScheme !=
+                QueryServicesOptions.DEFAULT_COLUMN_ENCODED_BYTES) {
+            props.add(TableProperty.COLUMN_ENCODED_BYTES.getPropertyName() + 
"=" + encodingScheme);
+        }
+        Boolean multitenant = (Boolean) 
TableProperty.MULTI_TENANT.getValue(tableProps);
+        if (multitenant != null && multitenant) {
+            props.add(TableProperty.MULTI_TENANT.getPropertyName() + "=" + 
multitenant);
+        }
+        Integer nSaltBuckets = (Integer) 
TableProperty.SALT_BUCKETS.getValue(tableProps);
+        if (nSaltBuckets != null) {
+            props.add(TableProperty.SALT_BUCKETS.getPropertyName() + "=" + 
nSaltBuckets);
+        }
+        PTable.IndexType indexType = (PTable.IndexType) 
TableProperty.INDEX_TYPE.getValue(
+                tableProps);
+        if (indexType != null && indexType == PTable.IndexType.LOCAL) {
+            props.add(TableProperty.INDEX_TYPE.getPropertyName() + "=" +
+                    (indexType == PTable.IndexType.LOCAL ? "l" : "g"));
+        }
+        if (nSaltBuckets != null) {
+            props.add(TableProperty.INDEX_TYPE.getPropertyName() + "=" + 
indexType);
+        }
+        Boolean immutableTable = (Boolean) 
TableProperty.IMMUTABLE_ROWS.getValue(tableProps);
+        if (immutableTable) {
+            props.add(TableProperty.IMMUTABLE_ROWS.getPropertyName() + 
"=true");
+        }
+        PTable.ImmutableStorageScheme immutableStorageScheme =
+                (PTable.ImmutableStorageScheme) TableProperty
+                        .IMMUTABLE_STORAGE_SCHEME.getValue(tableProps);
+        if (immutableStorageScheme != null) {
+            props.add(TableProperty.IMMUTABLE_STORAGE_SCHEME.getPropertyName() 
+ "="
+                    + immutableStorageScheme.name());
+        }
+        table_sql += " " + String.join(", ", props);
+        conn.createStatement().execute(table_sql);
+    }
+
+    protected void createCDCAndWait(Connection conn, String tableName, String 
cdcName,
+                                    String cdc_sql) throws Exception {
+        createCDCAndWait(conn, tableName, cdcName, cdc_sql, null, null, null);
+    }
+
+    protected void createCDCAndWait(Connection conn, String tableName, String 
cdcName,
+                                  String cdc_sql, PTable.IndexType indexType) 
throws Exception{
+        createCDCAndWait(conn, tableName, cdcName, cdc_sql, null, null, 
indexType);
+    }
+
+    protected void createCDCAndWait(Connection conn, String tableName, String 
cdcName,
+                                    String cdc_sql, 
PTable.QualifierEncodingScheme encodingScheme,
+                                    Integer nSaltBuckets) throws Exception {
+        createCDCAndWait(conn, tableName, cdcName, cdc_sql, encodingScheme, 
nSaltBuckets, null);
+    }
+
+    protected void createCDCAndWait(Connection conn, String tableName, String 
cdcName,
+                                    String cdc_sql, 
PTable.QualifierEncodingScheme encodingScheme,
+                                    Integer nSaltBuckets, PTable.IndexType 
indexType) throws Exception {
+        // For CDC, multitenancy gets derived automatically via the parent 
table.
+        createTable(conn, cdc_sql, encodingScheme, false, nSaltBuckets, 
indexType, false, null);
+        String schemaName = SchemaUtil.getSchemaNameFromFullName(tableName);
+        tableName = SchemaUtil.getTableNameFromFullName(tableName);
+        IndexToolIT.runIndexTool(false, schemaName, tableName,
+                "\""+CDCUtil.getCDCIndexName(cdcName)+"\"");
+        String indexFullName = SchemaUtil.getTableName(schemaName,
+                CDCUtil.getCDCIndexName(cdcName));
+        TestUtil.waitForIndexState(conn, indexFullName, PIndexState.ACTIVE);

Review Comment:
   Is this necessary? IndexTool runs and waits for the job to complete.



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

Reply via email to