You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2024/01/18 06:15:32 UTC
(cassandra) branch cassandra-5.0 updated: Enhanced usage of test method names in CQLTester for better test debugging
This is an automated email from the ASF dual-hosted git repository.
bereng pushed a commit to branch cassandra-5.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-5.0 by this push:
new 666f7df803 Enhanced usage of test method names in CQLTester for better test debugging
666f7df803 is described below
commit 666f7df8034fbb10843be7ed61f869cc881c28c5
Author: Bereng <be...@gmail.com>
AuthorDate: Mon Jan 15 09:35:22 2024 +0100
Enhanced usage of test method names in CQLTester for better test debugging
patch by Berenguer Blasi, Benjamin Lerer; reviewed by Benjamin Lerer for CASSANDRA-19050
Co-authored-by: Benjamin Lerer <b....@gmail.com>
Co-authored-by: Berenguer Blasi <be...@gmail.com>
---
test/unit/org/apache/cassandra/cql3/CQLTester.java | 49 +++++++++++++++++++---
...tabilityTest.java => JMXCompatibilityTest.java} | 3 +-
2 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 63f297dd51..be3aa01dff 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -39,6 +39,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -65,11 +66,14 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -180,6 +184,11 @@ import static org.apache.cassandra.config.CassandraRelevantProperties.TEST_DRIVE
import static org.apache.cassandra.config.CassandraRelevantProperties.TEST_REUSE_PREPARED;
import static org.apache.cassandra.config.CassandraRelevantProperties.TEST_ROW_CACHE_SIZE;
import static org.apache.cassandra.config.CassandraRelevantProperties.TEST_USE_PREPARED;
+import static org.apache.cassandra.cql3.SchemaElement.SchemaElementType.AGGREGATE;
+import static org.apache.cassandra.cql3.SchemaElement.SchemaElementType.FUNCTION;
+import static org.apache.cassandra.cql3.SchemaElement.SchemaElementType.MATERIALIZED_VIEW;
+import static org.apache.cassandra.cql3.SchemaElement.SchemaElementType.TABLE;
+import static org.apache.cassandra.cql3.SchemaElement.SchemaElementType.TYPE;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -197,6 +206,12 @@ public abstract class CQLTester
protected static final Logger logger = LoggerFactory.getLogger(CQLTester.class);
+ // We make the test method name available and also use it when creating KS, table,...
+ @Rule
+ public final TestName testName = new TestName();
+ // Some tests use hardcoded constants so we may want to disable it
+ protected static volatile boolean decorateCQLWithTestNames = true;
+
public static final String KEYSPACE = "cql_test_keyspace";
public static final String KEYSPACE_PER_TEST = "cql_test_keyspace_alt";
protected static final boolean USE_PREPARED_VALUES = TEST_USE_PREPARED.getBoolean();
@@ -903,14 +918,14 @@ public abstract class CQLTester
protected String createTypeName()
{
- String typeName = String.format("type_%02d", seqNumber.getAndIncrement());
+ String typeName = createSchemaElementName(TYPE, null);
types.add(typeName);
return typeName;
}
protected String createFunctionName(String keyspace)
{
- return String.format("%s.function_%02d", keyspace, seqNumber.getAndIncrement());
+ return createSchemaElementName(FUNCTION, keyspace);
}
protected void registerFunction(String functionName, String argTypes)
@@ -935,7 +950,7 @@ public abstract class CQLTester
protected String createAggregateName(String keyspace)
{
- return String.format("%s.aggregate_%02d", keyspace, seqNumber.getAndIncrement());
+ return createSchemaElementName(AGGREGATE, keyspace);
}
protected void registerAggregate(String aggregateName, String argTypes)
@@ -983,11 +998,27 @@ public abstract class CQLTester
protected String createKeyspaceName()
{
- String currentKeyspace = String.format("keyspace_%02d", seqNumber.getAndIncrement());
+ String currentKeyspace = createSchemaElementName(SchemaElement.SchemaElementType.KEYSPACE, null);
keyspaces.add(currentKeyspace);
return currentKeyspace;
}
+ private String createSchemaElementName(SchemaElement.SchemaElementType type, String keyspace)
+ {
+ String prefix = keyspace == null ? "" : keyspace + '.';
+ String typeName = type == MATERIALIZED_VIEW ? "mv" : type.name().toLowerCase(Locale.US);
+ int sequence = seqNumber.getAndIncrement();
+ int usedSpaceSoFar = prefix.length() + typeName.length() + Math.max(2, numberOfDigits(sequence)) + 1;
+ String testMethodName = StringUtils.truncate(getTestMethodName(), SchemaConstants.NAME_LENGTH - usedSpaceSoFar);
+ return String.format("%s%s%s_%02d", prefix, typeName, testMethodName, sequence);
+ }
+
+ private int numberOfDigits(int i)
+ {
+ assert i >= 0;
+ return i == 0 ? 1 : (int) (Math.log10(i) + 1);
+ }
+
protected String createTable(String query)
{
return createTable(KEYSPACE, query);
@@ -1014,7 +1045,7 @@ public abstract class CQLTester
protected String createTableName(String tableName)
{
- String currentTable = tableName == null ? String.format("table_%02d", seqNumber.getAndIncrement()) : tableName;
+ String currentTable = tableName == null ? createSchemaElementName(TABLE, null) : tableName;
tables.add(currentTable);
return currentTable;
}
@@ -1092,7 +1123,7 @@ public abstract class CQLTester
protected String createViewName()
{
- String currentView = String.format("mv_%02d", seqNumber.getAndIncrement());
+ String currentView = createSchemaElementName(MATERIALIZED_VIEW, null);
views.add(currentView);
return currentView;
}
@@ -2566,6 +2597,12 @@ public abstract class CQLTester
return metrics.get(metricName);
}
+ private String getTestMethodName()
+ {
+ return decorateCQLWithTestNames && testName.getMethodName() != null ? '_' + testName.getMethodName().toLowerCase().replaceAll("[^\\w]", "_")
+ : "";
+ }
+
public static class Vector<T> extends AbstractList<T>
{
private final T[] values;
diff --git a/test/unit/org/apache/cassandra/tools/JMXCompatabilityTest.java b/test/unit/org/apache/cassandra/tools/JMXCompatibilityTest.java
similarity index 99%
rename from test/unit/org/apache/cassandra/tools/JMXCompatabilityTest.java
rename to test/unit/org/apache/cassandra/tools/JMXCompatibilityTest.java
index d4cdfae827..60df477577 100644
--- a/test/unit/org/apache/cassandra/tools/JMXCompatabilityTest.java
+++ b/test/unit/org/apache/cassandra/tools/JMXCompatibilityTest.java
@@ -60,7 +60,7 @@ import static com.google.common.collect.Lists.newArrayList;
* select * from table_00 where pk=42;
* }
*/
-public class JMXCompatabilityTest extends CQLTester
+public class JMXCompatibilityTest extends CQLTester
{
private static final Map<String, String> ENV = ImmutableMap.of("JAVA_HOME", CassandraRelevantProperties.JAVA_HOME.getString());
@@ -72,6 +72,7 @@ public class JMXCompatabilityTest extends CQLTester
@BeforeClass
public static void setup() throws Exception
{
+ decorateCQLWithTestNames = false;
DatabaseDescriptor.daemonInitialization();
DatabaseDescriptor.setColumnIndexSizeInKiB(0); // make sure the column index is created
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org