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

GH-4592 Replace a Junit4 Suite with v5 DynamicTest #4593

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

JervenBolleman
Copy link
Contributor

Also replaces a static so more tests should be runnable in parallel in the future.

GitHub issue closes #4592


PR Author Checklist (see the contributor guidelines for more details):

  • my pull request is self-contained
  • I've added tests for the changes I made
  • I've applied code formatting (you can use mvn process-resources to format from the command line)
  • I've squashed my commits where necessary
  • every commit message starts with the issue number (GH-xxxx) followed by a meaningful description of the change

@JervenBolleman JervenBolleman self-assigned this May 22, 2023
@JervenBolleman JervenBolleman added this to the 5.0.0 milestone May 22, 2023
@JervenBolleman JervenBolleman linked an issue May 22, 2023 that may be closed by this pull request
@JervenBolleman
Copy link
Contributor Author

@abrokenjester I think I got the upgrade of the manifest based tests to junit5 done. I removed some old deprecated test classes now that we are going to go to v5 as they are not compatible. They would need a similar non compatible rewrite to make work.

@JervenBolleman JervenBolleman added the ⛔ Not backwards compatible A change that breaks backwards compatibility and needs a major release label May 22, 2023
@JervenBolleman JervenBolleman requested review from hmottestad and removed request for abrokenjester October 31, 2023 19:39
@hmottestad
Copy link
Contributor

@JervenBolleman I'll try to take at look at this as soon as I can.

@JervenBolleman
Copy link
Contributor Author

@hmottestad I am rebasing this so that you don't need to deal with the mergeconflicts.

@hmottestad
Copy link
Contributor

@hmottestad I am rebasing this so that you don't need to deal with the mergeconflicts.

Thanks!

@JervenBolleman JervenBolleman force-pushed the GH-4592-junit5-repository-sparql-compliance branch from ef38ad4 to 8c33d62 Compare October 31, 2023 21:48
@JervenBolleman
Copy link
Contributor Author

JervenBolleman commented Nov 1, 2023

@hmottestad the verify/integration-tests stage passes on my laptop.

However, it does fail on my desktop with the same error as given by the github action :(

@JervenBolleman
Copy link
Contributor Author

@kenwenzel would you mind having a look at this failure. The tests pass for native and memory on all my systems. However, on my desktop and the github action I have strange errors. One difference is that my laptop is fedora while desktop and github action are ubuntu based.

@kenwenzel
Copy link
Contributor

@kenwenzel would you mind having a look at this failure. The tests pass for native and memory on all my systems. However, on my desktop and the github action I have strange errors. One difference is that my laptop is fedora while desktop and github action are ubuntu based.

Hi @JervenBolleman,

the NPEs are due to lazy values. Maybe the hash code function tries to initialize these values after the store has already been closed.
I've improved the handling of lazy values in this commit:
9b0622a

This should ensure that values do not leave the SAIL in an uninitialized state.
It may be the case that I've overseen something.

@JervenBolleman
Copy link
Contributor Author

@kenwenzel @hmottestad I found that part of the reason is that these tests now run concurrently and where sharing state. I fixed just this and will push a new commit.

@JervenBolleman JervenBolleman force-pushed the GH-4592-junit5-repository-sparql-compliance branch from e9d57aa to f289202 Compare November 3, 2023 10:28
tests.toArray(result);

return result;
public Collection<DynamicTest> tests() {
Copy link
Contributor

@hmottestad hmottestad Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this needs the @testfactory annotation. IntelliJ doesn't seem to pick up the annotation on the abstract method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably applies to other similar methods too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is actually an error in the manifest file itself. There is a query that looks for mf:include but the manifest file for geosparql uses mf:entities and even a different IRI prefix for mf:. Let me have a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at a current develop integration test job I think these tests are not run at this time either...

[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-failsafe-plugin:3.1.2:verify (verify) @ rdf4j-geosparql-compliance ---

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reenabled these tests. Lucky they all pass :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several other similar methods that were missing the @testfactory annotation. Did you look over the rest of the code?

@hmottestad
Copy link
Contributor

Screenshot 2023-11-10 at 12 56 05

This is pretty sweet! I can debug a single test in IntelliJ!

Comment on lines +273 to +282

public Stream<DynamicTest> tests() {
return Stream.of(makeTest("GH4499BindFilterNotExist2", this::testGH4499BindFilterNotExist2),
makeTest("GH4499BindFilterNotExist1", this::testGH4499BindFilterNotExist1),
makeTest("GH3696Bind", this::testGH3696Bind), makeTest("SelectBindOnly", this::testSelectBindOnly),
makeTest("SES2250BindErrorsInPath", this::testSES2250BindErrorsInPath),
makeTest("SES2250BindErrors", this::testSES2250BindErrors),
makeTest("BindScopeUnion", this::testBindScopeUnion), makeTest("BindScope", this::testBindScope),
makeTest("BindError", this::testBindError));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to stick with the regular @test annotation? Or maybe generate this list of tests in a more automatic way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure it out from the documentation :(

Copy link
Contributor

@hmottestad hmottestad Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChatGPT recommends this:

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Stream;

import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.junit.jupiter.api.DynamicTest;

public class BindTest extends AbstractComplianceTest {

    // ... existing methods ...

    public Stream<DynamicTest> tests() {
        // You may need to adjust how the repository connection is obtained
        Repository repo = getRepository(); // Or however you obtain a repository instance
        RepositoryConnection conn = repo.getConnection();

        return Arrays.stream(BindTest.class.getDeclaredMethods())
                     .filter(method -> shouldRunAsTest(method))
                     .map(method -> createDynamicTestFromMethod(method, conn));
    }

    private boolean shouldRunAsTest(Method method) {
        // Check if the method is a test method and takes a RepositoryConnection as argument
        return method.getName().startsWith("test") && 
               method.getParameterCount() == 1 &&
               method.getParameterTypes()[0] == RepositoryConnection.class;
    }

    private DynamicTest createDynamicTestFromMethod(Method method, RepositoryConnection conn) {
        return DynamicTest.dynamicTest(method.getName(), () -> {
            try {
                method.invoke(BindTest.this, conn);
            } catch (Exception e) {
                throw e.getCause();
            }
        });
    }

    private Repository getRepository() {
        // Implement this method to return your Repository instance
        return ...;
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno how pretty that is though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going back to junit v2 ;) I don't mind, the official way is to generate some kind of test template. But it is a lot of work for a little gain. @hmottestad Is it ok if we merge as is and leave that as a todo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can always change it up later, and your approach does allow IntelliJ to run a single test instead of having to run the entire suite.

Also replaces a static so more tests should be runnable in parallel in
the future.

Signed-off-by: Jerven Bolleman <[email protected]>
Also delete some deprecated tests classes that are no longer compatible
with the junit5 way of doing things.

Signed-off-by: Jerven Bolleman <[email protected]>
Allow for non DAWG approved tests to run.
Adds a manifest-all.ttl file for geosparql like sparql 1.1. compliance.

Also remove some unused imports.
Signed-off-by: Jerven Bolleman <[email protected]>
@JervenBolleman JervenBolleman force-pushed the GH-4592-junit5-repository-sparql-compliance branch from 4f3ba48 to da3e01e Compare November 10, 2023 15:43
@JervenBolleman
Copy link
Contributor Author

@hmottestad sorry for the force push to undo the merge commit :(

@JervenBolleman
Copy link
Contributor Author

JervenBolleman commented Nov 10, 2023 via email

@JervenBolleman
Copy link
Contributor Author

@hmottestad you where completely right I had missed a @testfactory and it was needed! thanks and have a good weekend.

@hmottestad hmottestad removed the ⛔ Not backwards compatible A change that breaks backwards compatibility and needs a major release label Nov 22, 2023
@hmottestad hmottestad requested review from hmottestad and removed request for hmottestad November 22, 2023 19:00
Copy link
Contributor

@hmottestad hmottestad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JervenBolleman thanks for these fixes! You can go ahead and merge when you want.

@JervenBolleman JervenBolleman merged commit bb7ac22 into develop Nov 23, 2023
9 checks passed
@JervenBolleman JervenBolleman deleted the GH-4592-junit5-repository-sparql-compliance branch November 23, 2023 09:10
@hmottestad hmottestad added the M3 label Jun 5, 2024
@hmottestad hmottestad removed this from the 5.0.0 milestone Jun 5, 2024
@hmottestad hmottestad removed the M3 label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate RepositorySPARQLComplianceTestSuite to JUnit5
3 participants