Skip to content

Commit

Permalink
PHOENIX-4731 Make running transactional unit tests for a given provid…
Browse files Browse the repository at this point in the history
…er optional
  • Loading branch information
JamesRTaylor committed Oct 5, 2018
1 parent 84a5ac3 commit d720f39
Show file tree
Hide file tree
Showing 83 changed files with 1,823 additions and 720 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ target/
release/
RESULTS/
CSV_EXPORT/
.DS_Store

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
Expand Down Expand Up @@ -1074,6 +1075,9 @@ public void testAddingRowTimestampColumnNotAllowedViaAlterTable() throws Excepti

@Test
public void testCreatingTxnTableFailsIfTxnsDisabled() throws Exception {
if (!TransactionFactory.Provider.getDefault().runTests()) {
return;
}
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(false));
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.hadoop.hbase.client.HTable;
Expand All @@ -49,6 +50,7 @@
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
Expand All @@ -57,9 +59,12 @@
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -695,7 +700,7 @@ public void assertTableDefinition(Connection conn, String fullTableName, PTableT
delta += salted ? 1 : 0;
String[] cols;
if (isMultiTenant && tableType!=PTableType.VIEW) {
cols = (String[])ArrayUtils.addAll(new String[]{"TENANT_ID"}, columnNames);
cols = ArrayUtils.addAll(new String[]{"TENANT_ID"}, columnNames);
}
else {
cols = columnNames;
Expand Down Expand Up @@ -907,7 +912,12 @@ public void testDivergedViewsStayDiverged() throws Exception {

@Test
public void testMakeBaseTableTransactional() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl());
if (!TransactionFactory.Provider.TEPHRA.runTests()) {
return;
}
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
props.setProperty(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
try (Connection conn = DriverManager.getConnection(getUrl(), props);
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
String baseTableName = SchemaUtil.getTableName(SCHEMA1, generateUniqueName());
String viewOfTable = SchemaUtil.getTableName(SCHEMA2, generateUniqueName());
Expand All @@ -931,8 +941,9 @@ public void testMakeBaseTableTransactional() throws Exception {
assertFalse(phoenixConn.getTable(new PTableKey(null, baseTableName)).isTransactional());
assertFalse(viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable)).isTransactional());

// make the base table transactional
conn.createStatement().execute("ALTER TABLE " + baseTableName + " SET TRANSACTIONAL=true");
// make the base table transactional and explicitly set TEPHRA as provider since only it
// supports transitioning from non transactional to transactional
conn.createStatement().execute("ALTER TABLE " + baseTableName + " SET TRANSACTIONAL=true, TRANSACTION_PROVIDER='TEPHRA'");
// query the view to force the table cache to be updated
viewConn.createStatement().execute("SELECT * FROM " + viewOfTable);
htable = phoenixConn.getQueryServices().getTable(Bytes.toBytes(baseTableName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
Expand All @@ -57,23 +58,23 @@ public abstract class BaseViewIT extends ParallelStatsEnabledIT {
protected String schemaName;
protected String fullTableName;
protected String tableDDLOptions;
protected boolean transactional;
protected String txProvider;

public BaseViewIT( boolean transactional) {
public BaseViewIT( String txProvider) {
StringBuilder optionBuilder = new StringBuilder();
this.transactional = transactional;
if (transactional) {
optionBuilder.append(" TRANSACTIONAL=true ");
this.txProvider = txProvider;
if (txProvider != null) {
optionBuilder.append(" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "'");
}
this.schemaName = "S_" + generateUniqueName();
this.tableDDLOptions = optionBuilder.toString();
this.tableName = "T_" + generateUniqueName();
this.fullTableName = SchemaUtil.getTableName(schemaName, tableName);
}

@Parameters(name="transactional = {0}")
public static Collection<Boolean> data() {
return Arrays.asList(new Boolean[] { false, true });
@Parameters(name="transactionProvider={0}")
public static Collection<Object[]> data() {
return TestUtil.filterTxParamData(Arrays.asList(new Object[][] { {"TEPHRA"}, {"OMID"}, {null} }), 0);
}

protected void testUpdatableViewWithIndex(Integer saltBuckets, boolean localIndex) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

public class ColumnEncodedImmutableNonTxStatsCollectorIT extends StatsCollectorIT {

public ColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, boolean transactional,
public ColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
return Arrays.asList(new Boolean[][] {
{ false, false, false, true }, { false, false, true, true }
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ false, null, false, true }, { false, null, true, true }
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@
import java.util.Collection;

import org.apache.phoenix.schema.stats.StatsCollectorIT;
import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;

public class ColumnEncodedImmutableTxStatsCollectorIT extends StatsCollectorIT {

public ColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, boolean transactional,
public ColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
return Arrays.asList(
new Boolean[][] { { false, true, false, true }, { false, true, true, true }, });
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return TestUtil.filterTxParamData(
Arrays.asList(
new Object[][] {
{ false, "TEPHRA", false, true },
{ false, "TEPHRA", true, true }, }), 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

public class ColumnEncodedMutableNonTxStatsCollectorIT extends StatsCollectorIT {

public ColumnEncodedMutableNonTxStatsCollectorIT(boolean mutable, boolean transactional,
public ColumnEncodedMutableNonTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Boolean[][] { { true, false, false, true }, { true, false, true, true } });
new Object[][] { { true, null, false, true }, { true, null, true, true } });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@
import java.util.Collection;

import org.apache.phoenix.schema.stats.StatsCollectorIT;
import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;

public class ColumnEncodedMutableTxStatsCollectorIT extends StatsCollectorIT {

public ColumnEncodedMutableTxStatsCollectorIT(boolean mutable, boolean transactional,
public ColumnEncodedMutableTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
return Arrays.asList(
new Boolean[][] { { true, true, false, true }, { true, true, true, true } });
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return TestUtil.filterTxParamData(
Arrays.asList(new Object[][] {
{ true, "TEPHRA", false, true },
{ true, "TEPHRA", true, true } }), 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void close() throws SQLException {
}

@Override
public synchronized PhoenixTransactionClient initTransactionClient(Provider provider) {
public synchronized PhoenixTransactionClient initTransactionClient(Provider provider) throws SQLException {
PhoenixTransactionService txService = txServices[provider.ordinal()];
if (txService == null) {
txService = txServices[provider.ordinal()] = provider.getTransactionProvider().getTransactionService(config, connectionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public void testMutableIndexWithUpdates() throws Exception {
//assert we are pulling from index table.
rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
actualExplainPlan = QueryUtil.getExplainPlan(rs);
// TODO: why is it a 1-WAY parallel scan only for !transactional && mutable && localIndex
IndexToolIT.assertExplainPlan(localIndex, actualExplainPlan, dataTableFullName, indexTableFullName);

rs = stmt.executeQuery(selectSql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -70,15 +71,13 @@ public class IndexToolIT extends ParallelStatsEnabledIT {
private final boolean transactional;
private final boolean directApi;
private final String tableDDLOptions;
private final boolean mutable;
private final boolean useSnapshot;

public IndexToolIT(boolean transactional, boolean mutable, boolean localIndex,
public IndexToolIT(String transactionProvider, boolean mutable, boolean localIndex,
boolean directApi, boolean useSnapshot) {
this.localIndex = localIndex;
this.transactional = transactional;
this.transactional = transactionProvider != null;
this.directApi = directApi;
this.mutable = mutable;
this.useSnapshot = useSnapshot;
StringBuilder optionBuilder = new StringBuilder();
if (!mutable) {
Expand All @@ -88,7 +87,7 @@ public IndexToolIT(boolean transactional, boolean mutable, boolean localIndex,
if (!(optionBuilder.length() == 0)) {
optionBuilder.append(",");
}
optionBuilder.append(" TRANSACTIONAL=true ");
optionBuilder.append(" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'");
}
optionBuilder.append(" SPLIT ON(1,2)");
this.tableDDLOptions = optionBuilder.toString();
Expand All @@ -107,22 +106,22 @@ public static void setup() throws Exception {
}

@Parameters(
name = "transactional = {0} , mutable = {1} , localIndex = {2}, directApi = {3}, useSnapshot = {4}")
public static Collection<Boolean[]> data() {
List<Boolean[]> list = Lists.newArrayListWithExpectedSize(16);
name = "transactionProvider={0},mutable={1},localIndex={2},directApi={3},useSnapshot={4}")
public static Collection<Object[]> data() {
List<Object[]> list = Lists.newArrayListWithExpectedSize(48);
boolean[] Booleans = new boolean[] { false, true };
for (boolean transactional : Booleans) {
for (Object transactionProvider : new String[] {"TEPHRA", "OMID", null}) {
for (boolean mutable : Booleans) {
for (boolean localIndex : Booleans) {
for (boolean directApi : Booleans) {
for (boolean useSnapshot : Booleans) {
list.add(new Boolean[] { transactional, mutable, localIndex, directApi, useSnapshot });
list.add(new Object[] { transactionProvider, mutable, localIndex, directApi, useSnapshot });
}
}
}
}
}
return list;
return TestUtil.filterTxParamData(list,0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

public class NonColumnEncodedImmutableNonTxStatsCollectorIT extends StatsCollectorIT {

public NonColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, boolean transactional,
public NonColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Boolean[][] { { false, false, false, false }, { false, false, true, false } });
new Object[][] { { false, null, false, false }, { false, null, true, false } });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@
import java.util.Collection;

import org.apache.phoenix.schema.stats.StatsCollectorIT;
import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;

public class NonColumnEncodedImmutableTxStatsCollectorIT extends StatsCollectorIT {

public NonColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, boolean transactional,
public NonColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable,transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
return Arrays.asList(
new Boolean[][] { { false, true, false, false }, { false, true, true, false } });
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return TestUtil.filterTxParamData(Arrays.asList(
new Object[][] {
{ false, "TEPHRA", false, false }, { false, "TEPHRA", true, false },
{ false, "OMID", false, false }, { false, "OMID", true, false },
}),1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.phoenix.end2end;

import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
import static org.apache.phoenix.util.TestUtil.getTableName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.stats.StatsCollectorIT;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.runners.Parameterized.Parameters;

import com.google.common.collect.Maps;

public class SysTableNamespaceMappedStatsCollectorIT extends StatsCollectorIT {

public SysTableNamespaceMappedStatsCollectorIT(boolean mutable, boolean transactional,
public SysTableNamespaceMappedStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}

@Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
public static Collection<Boolean[]> data() {
return Arrays.asList(
new Boolean[][] { { true, true, false, false }, { true, true, false, true }, });
@Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
public static Collection<Object[]> data() {
return TestUtil.filterTxParamData(Arrays.asList(
new Object[][] {
{ true, "TEPHRA", false, false }, { true, "TEPHRA", false, true },
{ true, "OMID", false, false },
}), 1);
}

@BeforeClass
Expand Down
Loading

0 comments on commit d720f39

Please sign in to comment.