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

    https://github.com/apache/phoenix/pull/309#discussion_r215431056
  
    --- Diff: 
phoenix-core/src/it/java/org/apache/phoenix/mapreduce/VerifyReplicationToolIT.java
 ---
    @@ -0,0 +1,284 @@
    +/*
    + * 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.mapreduce;
    +
    +import java.io.IOException;
    +import java.sql.*;
    +import java.util.*;
    +
    +import com.google.common.collect.Lists;
    +import com.google.common.collect.Maps;
    +import org.apache.hadoop.fs.FileSystem;
    +import org.apache.hadoop.fs.Path;
    +import org.apache.hadoop.hbase.TableName;
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.hadoop.mapreduce.Counters;
    +import org.apache.hadoop.mapreduce.Job;
    +import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
    +import org.apache.phoenix.query.QueryConstants;
    +import org.apache.phoenix.util.ByteUtil;
    +import org.apache.phoenix.util.EnvironmentEdgeManager;
    +import org.apache.phoenix.util.ReadOnlyProps;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.BeforeClass;
    +import org.junit.Test;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import static org.junit.Assert.assertEquals;
    +
    +public class VerifyReplicationToolIT extends BaseUniqueNamesOwnClusterIT {
    +    private static final Logger LOG = 
LoggerFactory.getLogger(VerifyReplicationToolIT.class);
    +    private static final String CREATE_USER_TABLE = "CREATE TABLE IF NOT 
EXISTS %s ( " +
    +            " TENANT_ID VARCHAR NOT NULL, USER_ID VARCHAR NOT NULL, AGE 
INTEGER " +
    +            " CONSTRAINT pk PRIMARY KEY ( TENANT_ID, USER_ID ))";
    +    private static final String UPSERT_USER = "UPSERT INTO %s VALUES (?, 
?, ?)";
    +    private static final String SELECT_USER =
    +            "SELECT * FROM %s WHERE TENANT_ID = ? LIMIT %d";
    +    private static final Random RANDOM = new Random();
    +    private static final int NUM_USERS = 10;
    +    private static final int NUM_TENANTS = 2;
    +
    +    private static int tenantNum = 0;
    +    private static int userNum = 0;
    +    /** source table with 4 regions*/
    +    private static String sourceTableName;
    +    /** target table with 2 regions*/
    +    private static String targetTableName;
    +    private List<String> sourceTenants;
    +    private String sourceOnlyTenant;
    +    private String sourceAndTargetTenant;
    +    private String targetOnlyTenant;
    +    private PreparedStatement sourceStmt;
    +    private PreparedStatement targetStmt;
    +    private List<byte[]> sourceSplitPoints;
    +    private List<byte[]> targetSplitPoints;
    +
    +    @BeforeClass
    +    public static void createTables() throws Exception {
    +        NUM_SLAVES_BASE = 4;
    +        Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
    +        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
    +        Connection conn = DriverManager.getConnection(getUrl());
    +        sourceTableName = generateUniqueName();
    +        targetTableName = generateUniqueName();
    +        // tables will have the same schema, but a different number of 
regions
    +        conn.createStatement().execute(String.format(CREATE_USER_TABLE, 
sourceTableName));
    +        conn.createStatement().execute(String.format(CREATE_USER_TABLE, 
targetTableName));
    +        conn.commit();
    +    }
    +
    +    @Before
    +    public void setupTenants() throws Exception {
    +        sourceTenants = new ArrayList<>(NUM_TENANTS);
    +        sourceTenants.add("tenant" + tenantNum++);
    +        sourceTenants.add("tenant" + tenantNum++);
    +        sourceOnlyTenant = sourceTenants.get(0);
    +        sourceAndTargetTenant = sourceTenants.get(1);
    +        targetOnlyTenant = "tenant" + tenantNum++;
    +        /* upsert data and spilt table into multiple regions
    +        with each relevant region based on splitpoints
    +        residing on a different RS*/
    +        upsertData();
    +        /* splitting source table into 4 regions */
    +        splitSource(sourceTableName);
    +        /* splitting target table into 2 regions */
    +        splitTarget(targetTableName);
    +    }
    +
    +    @Test
    +    public void testVerifyRowsMatch() throws Exception {
    +        verify(String.format("TENANT_ID = '%s'", sourceAndTargetTenant), 
0, 10, 0, 0, 0, 0);
    +    }
    +
    +    @Test
    +    public void testVerifySourceOnly() throws Exception {
    +        verify(String.format("TENANT_ID = '%s'", sourceOnlyTenant), 0, 0, 
10, 10, 0, 0);
    +    }
    +
    +    @Test
    +    public void testVerifyRowsDifferent() throws Exception {
    +        // change three rows on the source table so they no longer match 
on the target
    +        upsertSelectData(sourceTableName, sourceAndTargetTenant, -1, 3);
    +        verify(String.format("TENANT_ID = '%s'", sourceAndTargetTenant), 
0, 7, 3, 0, 0, 3);
    +    }
    +
    --- End diff --
    
    Could we also have a test that verifies that it does the right thing if 
there are both source-only and target-only rows? I did a whiteboard exercise to 
prove to myself that it does, but would be good to have it in code too. 


---

Reply via email to