Skip to content

Commit

Permalink
[CALCITE-4821] Move utility test classes into calcite-testkit and unp…
Browse files Browse the repository at this point in the history
…ublish -test.jar
  • Loading branch information
vlsi committed Oct 5, 2021
1 parent 2fdc537 commit ef40b52
Show file tree
Hide file tree
Showing 121 changed files with 2,144 additions and 1,399 deletions.
2 changes: 1 addition & 1 deletion babel/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
testImplementation("org.hsqldb:hsqldb")
testImplementation("org.incava:java-diff")
testImplementation("org.slf4j:slf4j-log4j12")
testImplementation(project(":core", "testClasses"))
testImplementation(project(":testkit"))
}

val fmppMain by tasks.registering(org.apache.calcite.buildtools.fmpp.FmppTask::class) {
Expand Down
1 change: 1 addition & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ dependencies {
apiv("org.apache.cassandra:cassandra-all")
apiv("org.apache.commons:commons-dbcp2")
apiv("org.apache.commons:commons-lang3")
apiv("org.apache.commons:commons-pool2")
apiv("org.apache.geode:geode-core")
apiv("org.apache.hadoop:hadoop-client", "hadoop")
apiv("org.apache.hadoop:hadoop-common", "hadoop")
Expand Down
13 changes: 1 addition & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ val sqllineClasspath by configurations.creating {

dependencies {
sqllineClasspath(platform(project(":bom")))
sqllineClasspath(project(":testkit"))
sqllineClasspath("sqlline:sqlline")
for (p in adaptersForSqlline) {
sqllineClasspath(project(p))
Expand Down Expand Up @@ -778,11 +779,6 @@ allprojects {
archiveClassifier.set("tests")
}

val testSourcesJar by tasks.registering(Jar::class) {
from(sourceSets["test"].allJava)
archiveClassifier.set("test-sources")
}

val sourcesJar by tasks.registering(Jar::class) {
from(sourceSets["main"].allJava)
archiveClassifier.set("sources")
Expand All @@ -793,18 +789,11 @@ allprojects {
archiveClassifier.set("javadoc")
}

val testClasses by configurations.creating {
extendsFrom(configurations["testRuntime"])
}

val archives by configurations.getting

// Parenthesis needed to use Project#getArtifacts
(artifacts) {
testClasses(testJar)
archives(sourcesJar)
archives(testJar)
archives(testSourcesJar)
}

val archivesBaseName = "calcite-$name"
Expand Down
2 changes: 1 addition & 1 deletion cassandra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {

implementation("org.apache.calcite.avatica:avatica-core")

testImplementation(project(":core", "testClasses"))
testImplementation(project(":testkit"))
testImplementation("org.apache.cassandra:cassandra-all") {
exclude("org.slf4j", "log4j-over-slf4j")
.because("log4j is already present in the classpath")
Expand Down
15 changes: 1 addition & 14 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,20 @@ dependencies {
testOracle("com.oracle.ojdbc:ojdbc8")
testPostgresql("org.postgresql:postgresql")

testImplementation(project(":testkit"))
testImplementation("commons-lang:commons-lang")
testImplementation("net.hydromatic:foodmart-data-hsqldb")
testImplementation("net.hydromatic:foodmart-queries")
testImplementation("net.hydromatic:quidem")
testImplementation("net.hydromatic:scott-data-hsqldb")
testImplementation("org.apache.calcite.avatica:avatica-server")
testImplementation("org.apache.commons:commons-pool2")
testImplementation("org.hsqldb:hsqldb")
testImplementation("org.incava:java-diff")
testImplementation("sqlline:sqlline")
testImplementation(kotlin("stdlib-jdk8"))
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit5"))
testRuntimeOnly("org.slf4j:slf4j-log4j12")
}

// There are users that reuse/extend test code (e.g. Apache Felix)
// So publish test jar to Nexus repository
// TODO: remove when calcite-test-framework is extracted to a standalone artifact
publishing {
publications {
named<MavenPublication>(project.name) {
artifact(tasks.testJar.get())
}
}
}

tasks.jar {
CrLfSpec(LineEndings.LF).run {
into("codegen") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.calcite.config.CalciteSystemProperty;
import org.apache.calcite.test.CalciteAssert;
import org.apache.calcite.test.JdbcFrontLinqBackTest;
import org.apache.calcite.test.JdbcTest;
import org.apache.calcite.test.schemata.hr.Employee;
import org.apache.calcite.util.TestUtil;
import org.apache.calcite.util.Util;

Expand Down Expand Up @@ -533,9 +533,9 @@ private String pad(String x) {
}

public static Connection makeConnection() throws Exception {
List<JdbcTest.Employee> employees = new ArrayList<JdbcTest.Employee>();
List<Employee> employees = new ArrayList<Employee>();
for (int i = 1; i <= 101; i++) {
employees.add(new JdbcTest.Employee(i, 0, "first", 0f, null));
employees.add(new Employee(i, 0, "first", 0f, null));
}
Connection conn = JdbcFrontLinqBackTest.makeConnection(employees);
return conn;
Expand Down
12 changes: 6 additions & 6 deletions core/src/test/java/org/apache/calcite/plan/RelWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
import org.apache.calcite.sql.fun.SqlTrimFunction;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.test.JdbcTest;
import org.apache.calcite.test.MockSqlOperatorTable;
import org.apache.calcite.test.RelBuilderTest;
import org.apache.calcite.test.schemata.hr.HrSchema;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.tools.RelBuilder;
Expand Down Expand Up @@ -432,7 +432,7 @@ static Stream<SqlExplainFormat> explainFormats() {
String s =
Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
rootSchema.add("hr",
new ReflectiveSchema(new JdbcTest.HrSchema()));
new ReflectiveSchema(new HrSchema()));
LogicalTableScan scan =
LogicalTableScan.create(cluster,
relOptSchema.getTableForMember(
Expand Down Expand Up @@ -477,7 +477,7 @@ static Stream<SqlExplainFormat> explainFormats() {
String s =
Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
rootSchema.add("hr",
new ReflectiveSchema(new JdbcTest.HrSchema()));
new ReflectiveSchema(new HrSchema()));
LogicalTableScan scan =
LogicalTableScan.create(cluster,
relOptSchema.getTableForMember(
Expand Down Expand Up @@ -528,7 +528,7 @@ static Stream<SqlExplainFormat> explainFormats() {
Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
SchemaPlus schema =
rootSchema.add("hr",
new ReflectiveSchema(new JdbcTest.HrSchema()));
new ReflectiveSchema(new HrSchema()));
final RelJsonReader reader =
new RelJsonReader(cluster, relOptSchema, schema);
RelNode node;
Expand All @@ -555,7 +555,7 @@ static Stream<SqlExplainFormat> explainFormats() {
Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
SchemaPlus schema =
rootSchema.add("hr",
new ReflectiveSchema(new JdbcTest.HrSchema()));
new ReflectiveSchema(new HrSchema()));
final RelJsonReader reader =
new RelJsonReader(cluster, relOptSchema, schema);
RelNode node;
Expand Down Expand Up @@ -585,7 +585,7 @@ static Stream<SqlExplainFormat> explainFormats() {
Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
SchemaPlus schema =
rootSchema.add("hr",
new ReflectiveSchema(new JdbcTest.HrSchema()));
new ReflectiveSchema(new HrSchema()));
final RelJsonReader reader =
new RelJsonReader(cluster, relOptSchema, schema);
RelNode node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.apache.calcite.avatica.util.TimeUnitRange;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.test.RexImplicationCheckerTest.Fixture;
import org.apache.calcite.test.RexImplicationCheckerFixtures.Fixture;
import org.apache.calcite.util.DateString;
import org.apache.calcite.util.TimestampString;
import org.apache.calcite.util.Util;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.calcite.sql.parser;

/**
* Tests SQL Parser.
*/
public class CoreSqlParserTest extends SqlParserTest {
}
21 changes: 21 additions & 0 deletions core/src/test/java/org/apache/calcite/test/CoreQuidemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*/
package org.apache.calcite.test;

import org.apache.calcite.config.CalciteConnectionProperty;
import org.apache.calcite.prepare.Prepare;
import org.apache.calcite.util.TryThreadLocal;

import net.hydromatic.quidem.Quidem;

import java.sql.Connection;
import java.util.Collection;

/**
Expand Down Expand Up @@ -46,6 +50,23 @@ public static Collection<Object[]> data() {
return data(first);
}

@Override protected Quidem.ConnectionFactory createConnectionFactory() {
return new QuidemConnectionFactory() {
@Override public Connection connect(String name, boolean reference) throws Exception {
switch (name) {
case "blank":
return CalciteAssert.that()
.with(CalciteConnectionProperty.PARSER_FACTORY,
ExtensionDdlExecutor.class.getName() + "#PARSER_FACTORY")
.with(CalciteAssert.SchemaSpec.BLANK)
.connect();
default:
}
return super.connect(name, reference);
}
};
}

/** Override settings for "sql/misc.iq". */
public void testSqlMisc(String path) throws Exception {
switch (CalciteAssert.DB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected static void populate(SqlIdentifier name, SqlNode query,

/** Table backed by a Java list. */
private static class MutableArrayTable
extends JdbcTest.AbstractModifiableTable {
extends AbstractModifiableTable {
final List list = new ArrayList();
private final RelProtoDataType protoRowType;

Expand Down
Loading

0 comments on commit ef40b52

Please sign in to comment.