Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit test fails with Gradle 7/Java 16 #16820

Closed
hrstoyanov opened this issue Apr 13, 2021 · 8 comments
Closed

JUnit test fails with Gradle 7/Java 16 #16820

hrstoyanov opened this issue Apr 13, 2021 · 8 comments
Assignees

Comments

@hrstoyanov
Copy link

Expected Behavior

JUnit test run with typical results.

Current Behavior

I get strange jUnit failure:

No tests found for given includes: [ai.dynamind.dbproxy.mssql.jdbc.StressTests](filter.includeTestsMatching)

Context

Here is the test file:

package ai.dynamind.dbproxy.mssql.jdbc;

import ai.dynamind.dbproxy.shared.CloseUtil;
import ai.dynamind.dbproxy.shared.LangUtil;
import org.junit.jupiter.api.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Random;

@DisplayName("Stress JDBC Transactional Tests")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class StressTests extends Base {

    private final static String[] FIRST_NAMES = new String[]{"John", "Ivan", "Rumen", "Hristo"};
    private final static String[] LAST_NAMES = new String[]{"Stoyanov", "Petrov", "Trump", "Biden", "McDonald"};
    private static final Random random = new Random();

    @Test
    @Order(1)
    @DisplayName("Open connection to proxy and create tables")
    void createTable() throws SQLException {

        System.out.println("Creating table(s)...");
        try (var statement = connection.createStatement()) {
            statement.execute(
                    """

                            drop table if exists stress_test;

                            create table stress_test(
                              client_id bigint,
                              first_name varchar(100),
                              last_name varchar(100)
                            );
                            """);
        }

        System.out.println("Creating table(s)...DONE");
    }

    @Test
    @Order(10)
    @DisplayName("run transactional inserts in threads")
    void transactionalInserts() throws SQLException {
        final var connections = new Connection[10];
        final var threads = new Thread[100];
        System.out.printf("About to run transactional INSERTs across %d connections in %d threads...", connections.length, threads.length);
        try {
            for (int i = 0; i < connections.length; i++) {
                // ds.setPacketSize(1000 + (i % 5) * 1000);
                connections[i] = DriverManager.getConnection(DBPROXY_URL);
                connections[i].setAutoCommit(false);
            }
            System.out.printf("Created %d connections\n", connections.length);
            for (int i = 0; i < threads.length; i++) {
                final int ii = i;
                threads[i] = new Thread(() -> {
                    final int connectionIndex = random.nextInt(connections.length);
                    var connection = connections[connectionIndex];
                    try (var statement = connection.prepareStatement("insert into stress_test(client_id, first_name, last_name) values(?,?,?)")) {
                        for (var firstName : FIRST_NAMES) {
                            for (var lastName : LAST_NAMES) {
                                int column = 1;
                                statement.setInt(column++, ii);
                                statement.setString(column++, firstName);
                                statement.setString(column++, lastName);
                                statement.addBatch();
                                //statement.execute();
                            }
                        }
                        statement.executeBatch();
                        connection.commit();
                    } catch (SQLException se) {
                        se.printStackTrace(System.err);
                        LangUtil.rethrowUnchecked(se);
                    }
                }, "Insert thread " + i);
                threads[i].start();
            }
            for (var thread : threads) thread.join();
            System.out.println("DONE!");
        } catch (InterruptedException se) {
            se.printStackTrace(System.err);
        } finally {
            CloseUtil.quietCloseAll(connections);
        }
    }
}

Steps to Reproduce

 ./gradlew :dbproxy:test --tests "ai.dynamind.dbproxy.mssql.jdbc.StressTests" 

> Task :dbproxy:quarkusGenerateCode
preparing quarkus application

> Task :dbproxy:quarkusGenerateCodeTests
preparing quarkus application

> Task :dbproxy:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dbproxy:test'.
> No tests found for given includes: [ai.dynamind.dbproxy.mssql.*](filter.includeTestsMatching) [ai.dynamind.dbproxy.mssql.jdbc.StressTests](--tests filter)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Your Environment

Build scan URL:
https://gradle.com/s/zjltnkaconw4e

@jjohannes
Copy link
Contributor

@hrstoyanov can you please:

  • Let us know in which Gradle version this stopped working (did it still work in 6.8.3?)
  • Share a reproducer or at least the test task configuration of your build script (in 'Steps to Reproduce' you did not link a project, but just gave the build commands)

@hrstoyanov
Copy link
Author

hrstoyanov commented Apr 14, 2021

Yes, it used to work with Gradle 6.8.3 and Java 15.0.2.

I also shared the JUnit test code above, see Context

@jjohannes
Copy link
Contributor

Thanks for confirming @hrstoyanov and sorry that I missed the "Context" part. I think it's enough for us to investigate here. Although, in general, a complete small build with build file and test would be appreciated. Then it is much easier for us to reproduce and make sure we have exactly the same setup as you.

@rieske rieske self-assigned this Apr 14, 2021
@hrstoyanov
Copy link
Author

also, I googled this issue and some people pointed to "--enable-preview" jvm option, so I tried all sorts of test configurations like:

test {
    useJUnitPlatform()
    jvmArgs([ "--enable-preview"])
}

 tasks.withType(Test) {
        useJUnitPlatform()
        jvmArgs '--enable-preview'
    }

    test {
        sourceCompatibility = JavaVersion.VERSION_16
        targetCompatibility = JavaVersion.VERSION_16
        jvmArgs([ "--enable-preview"])
    }

Nothing worked.

@rieske
Copy link
Contributor

rieske commented Apr 15, 2021

I am not able to reproduce this problem.
I tried a trivial project with Gradle 7.0 + Java16 with and without toolchains using org.junit.jupiter:junit-jupiter:5.7.1 - test filtering works as expected.
Looking at the build scan, I tried throwing Quarkus into the mix, generated a project using https://quarkus.io/guides/gradle-tooling#project-creation so that the same version of quarkus plugin is applied as in the build scan, adjusted dependencies to match the ones in attached build scan - no luck - I can use test filters to execute tests.

If you could share a minimal project (with settings and build files) that exhibits the said behavior - this would help a lot.

@jjohannes jjohannes added the @core Issue owned by GBT Core label Apr 15, 2021
@hrstoyanov
Copy link
Author

Sorry .. I figured out it is my issue and not Gradle's. Closing it.

@jjohannes jjohannes removed this from the 7.0.1 milestone Apr 16, 2021
@vandanagoyal-ak
Copy link

@hrstoyanov how did you fix it?

@alvindizon
Copy link

@hrstoyanov I'd like to know how you solved it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants