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

8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.sh to jtreg java test #11910

Closed
wants to merge 8 commits into from

Conversation

mpdonova
Copy link
Contributor

@mpdonova mpdonova commented Jan 9, 2023

Removed SSLSocketParametersTest.sh script (which just called a Java file) and configured the java code to run directly with jtreg


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.sh to jtreg java test

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11910/head:pull/11910
$ git checkout pull/11910

Update a local copy of the PR:
$ git checkout pull/11910
$ git pull https://git.openjdk.org/jdk pull/11910/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11910

View PR using the GUI difftool:
$ git pr show -t 11910

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11910.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 9, 2023

👋 Welcome back mpdonova! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 9, 2023
@openjdk
Copy link

openjdk bot commented Jan 9, 2023

@mpdonova The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jan 9, 2023
@mlbridge
Copy link

mlbridge bot commented Jan 9, 2023

Webrevs

@mpdonova mpdonova changed the title 8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTestsh to jtreg java test 8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.sh to jtreg java test Jan 19, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Feb 7, 2023

@mpdonova This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@mpdonova
Copy link
Contributor Author

mpdonova commented Feb 7, 2023

Can someone take a look at this? Thanks!

Comment on lines 181 to 192
case 4 -> {
try {
run(new ServerFactory(SSLContext.getDefault(),
new String[]{"dummy_ciphersuite"}, null, false),
true);
} catch (NoSuchAlgorithmException exc) {
throw new RuntimeException("Could not create SSLContext.", exc);
} catch (IllegalArgumentException exc) {
if (!exc.getMessage().toLowerCase().contains("unsupported ciphersuite")) {
throw exc;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the story with the different exception catching here and in case 5? It doesn't look like a simple refactoring. Is another bug being fixed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The expected result of cases 4 and 5 is that an IllegalArgumentException is thrown because of the unsupported ciphersuite. The original code just caught Exception which would hide a problem in the test e.g., if SSLContext.getDefault() throws the NoSuchAlgorithmException.

Copy link
Member

Choose a reason for hiding this comment

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

OK - but the run( ) method catches IllegalArgumentException already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exception is actually being thrown from the ServerFactory constructor. I updated the code to remove the call to run() and added a comment clarifying the exception handling.

case 4 -> {
try {
new ServerFactory(SSLContext.getDefault(),
new String[]{"dummy_ciphersuite"}, null, false);
Copy link
Member

Choose a reason for hiding this comment

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

what if the constructor doesn't throw any exception? shouldn't the test fail? or should run be called in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch; yes, the test should fail. I updated these cases.

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

Thanks for the update. I believe this looks good, but it would be nice to get @stuart-marks or @RogerRiggs approval before integrating.

@openjdk
Copy link

openjdk bot commented Feb 17, 2023

@mpdonova This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.sh to jtreg java test

Reviewed-by: dfuchs, smarks

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 21 new commits pushed to the master branch:

  • 843d632: 8303442: Clean up w2k_lsa_auth linker parameters
  • d4dcba0: 8303267: Prefer ArrayList to LinkedList in ConcurrentLocksPrinter
  • 2c7d2c0: 8303411: JFR problem list entry for JDK-8247776 should be removed
  • 0b63557: 8303039: Utilize coverageLevels.txt
  • 32247c3: 8303476: Add the runtime version in the release file of a JDK image
  • 0926d0c: 8302516: Do some cleanup of nsk/share/jdi/EventHandler.java
  • b51ea42: 8303354: addCertificatesToKeystore in KeystoreImpl.m needs CFRelease call in early potential CHECK_NULL return
  • fb13063: 8303409: Add Windows AArch64 ABI support to the Foreign Function & Memory API
  • c9afd55: 8302820: Remove costs for NMTPreInit when NMT is off
  • 72de24e: 8303457: Introduce convenience test library APIs for creating test servers for tests in test/jdk/java/net/httpclient
  • ... and 11 more: https://git.openjdk.org/jdk/compare/6af17c1b7d26e639a655405c66aaa1e37a5d8489...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch, @RogerRiggs, @stuart-marks) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 17, 2023
}
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

The default should be retained to produce an error.

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 put the default case back

}
}
}

public void runTest(String[] args) {

int test = Integer.parseInt(args[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the parseInt to main() and call runTest with the test number.

Comment on lines +28 to +34
* @run main/othervm SSLSocketParametersTest 1
* @run main/othervm SSLSocketParametersTest 2
* @run main/othervm SSLSocketParametersTest 3
* @run main/othervm SSLSocketParametersTest 4
* @run main/othervm SSLSocketParametersTest 5
* @run main/othervm SSLSocketParametersTest 6
* @run main/othervm SSLSocketParametersTest 7
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a fresh VM needed for each of these tests?
From a naive point of view it appears that 1, 2, 3, 4, 6, 7 use the same system properties.
The tests would complete more quickly if they could run the compatible tests in a single VM.
Perhaps main() could iterate over the args[n] and run the corresponding test.

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 tried this suggestion but test case 6 failed. From the logs, it looked like an object was being re-used and an exception wasn't being thrown when it should have been.

e);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this finally-block is intended to unexport any exported RMI service, which will let the JVM exit. However, this is somewhat fragile. If the unexportObject() call fails with some other exception, the object might remain exported, and the JVM will hang indefinitely. (This has historically been a problem with RMI tests.)

Since the original version of the test ran each case in a separate JVM, I think it's ok to continue to do the same. The old version of the test called System.exit() along most code paths. It's somewhat odd that exit wasn't called along all code paths. Perhaps those code paths weren't taken, or if they were, the JVM exited of its own accord. In any case, I'd suggest ensuring that exit() is called along all code paths (success and failure) and keeping separate @run main/othervm lines in the header to run each case in its own JVM. This is at least equivalent to what the shell script based test was doing.

As an optimization, it might be reasonable to try to run some subset of the tests in a single JVM. They can't all be run in the same JVM though, because of system properties, so this would require some complexity to support running some cases in the same JVM and some in separate JVMs. It's not clear to me whether that's warranted.

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 don't think all of those code paths ever executed. If System.exit() is called, regardless of the exit code, make treats it as an error:

TEST RESULT: Failed. Unexpected exit from test [exit code: 0]

I added a try/catch in main so that if an exception is thrown during the test, System.exit will be called.

Copy link
Member

Choose a reason for hiding this comment

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

My bad, I was confused about the execution environments. In the old test, jtreg invoked the shell script, which in turn invoked the Java test as a standalone Java program. In that environment it's paramount that every code path call System.exit() in order to avoid stale JVMs building up.

The new test is invoked directly by jtreg, which disallows calling System.exit(). Instead, every code path needs to result in the main() method completing somehow, either via a normal return or by throwing an exception directly or letting one propagate from some called method. So, you need to pull out the try/catch and any calls to System.exit(). Sorry about that.

If we're going to stick with a scheme where we're running separate JVM per test, there's no need to unexport any RMI service. When main() returns or throws an exception, jtreg will detect this and terminate the JVM because of /othervm, and any exported RMI services will be destroyed at that time. Thus, the finally-block in testRmiCommunication can simply be removed.

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 removed the finally block.

if (!exc.getMessage().toLowerCase().contains("unsupported protocol")) {
throw exc;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Having exception handling in the run() method and also in this switch statement is quite confusing. It obscures the fact that these cases (4 and 5) don't call run() at all. It would be good to find a structure that makes it clear that some test cases are for exceptions that occur at ServerFactory creation time and other exceptions occur when an actual socket connection is attempted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps some refactoring should be done in a separate PR.
The stated goal was to remove the use of the shell script; but its easy to start to refactor more and more.

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 did a little refactoring here to clarify (I hope) the tests and remove some redundant code.

@stuart-marks
Copy link
Member

General comments: the ClientFactory, ServerFactory, and HelloClient classes don't seem to be adding much value. Also, the setup of the HelloImpl service could probably be simplified by not having it extend UnicastRemoteObject and instead calling UnicastRemoteObject.exportObject(). These are held over from the original test and don't have much do with the shell script conversion, though, so you might choose not to undertake these cleanups now. But if you're interested, let me know and we can discuss them further.

throw exc;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Overall this test method makes sense, as it asserts that an IllegalArgumentException must be thrown with the given exception message. (A comment to this effect would be helpful.) As such, the catch of NoSuchAlgorithmException is confusing. I think this is here because SSLContext.getDefault() lists this as a checked exception. If so, then I'd suggest simply propagating it by adding a throws clause for this method. This also means adding a throws clause to the runTest() method, possibly just throws Exception. In general this is OK for jtreg tests to propagate any checked exception out of main, since jtreg will handle and report any unexpectedly propagated exceptions. It's thus unnecessary for test code to have catch-clauses for anything that the test isn't actually handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exception handling has been cleaned up here and the other place you pointed out.

if (!expectException) {
throw new RuntimeException("An error occurred during test execution", exc);
} else {
System.out.println("Caught expected exception: " + exc);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite clear on what the expected exception actually is -- is it an IllegalArgumentException or an IOException? Or does it differ from case to case? It would be good to be precise about exactly which exception is expected to be thrown from which test case. If IOException is caught here only because it's declared to be thrown by some method, and it's incidental to the test, I'd suggest it be propagated. (See my similar comments on testServerFactory.)

@stuart-marks
Copy link
Member

OK, I think this is pretty good as it stands. It achieves the original goal of converting the shell script test to a regular Java jtreg test; the shell script is removed entirely, and the Java code is cleaned up and is 20% shorter. Hooray! So I think this can go in as it stands.

Optionally, if you're game to continue working on this, there are some additional cleanups that can be done. This is now digging into the Java code that was already in the test before you got involved. Specifically:

  1. The HelloImpl and HelloClient classes aren't adding much value and can pretty much be deleted if the object is exported with something like:

    Hello stub = (Hello) UnicastRemoteObject.exportObject(new HelloImpl(), port, csf, ssf);

or similar.

  1. The ClientFactory and ServerFactory classes aren't adding much value. They override the create methods and print a message, but otherwise don't do anything beyond what's done in their respective superclasses.

  2. The exception handling is now fairly simple, but one still needs to read through the code to figure out what is actually being tested. The expectedException boolean also makes things a little harder to read since it can invert the logic. I observe that the various test frameworks (such as Test-NG or JUnit) have APIs for this such as assertThrows or expectThrows which return the caught exception, allowing additional assertions to be made over it, and failing the test if the expected exception type isn't thrown. I think this would improve the test cases where an exception is expected, but it might not be worth the effort of converting to one of the frameworks.

It's up to you (and your project lead) as to how to proceed. You could continue here, or in another PR, or just consider this done and move onto the next thing.

@mpdonova
Copy link
Contributor Author

mpdonova commented Mar 2, 2023

I created a new bug, JDK-8303525, for the additional refactoring suggestions. I assigned it to myself but wouldn't be bothered if someone else wanted to take it.

@mpdonova
Copy link
Contributor Author

mpdonova commented Mar 2, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Mar 2, 2023
@openjdk
Copy link

openjdk bot commented Mar 2, 2023

@mpdonova
Your change (at version 59e3081) is now ready to be sponsored by a Committer.

@stuart-marks
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Mar 6, 2023

Going to push as commit ccfe167.
Since your change was applied there have been 69 commits pushed to the master branch:

  • cfb0a25: 8303440: The "ZonedDateTime.parse" may not accept the "UTC+XX" zone id
  • a97271e: 8301793: AlgorithmId should not encode a missing parameters field as NULL unless hardcoded
  • cac81dd: 8303577: [JVMCI] OOME causes crash while translating exceptions
  • 877ab65: 8303264: Refactor nsk/stress/strace to extract shared and remove redundant code
  • ae8730f: 8303486: [REDO] Update ProcessTools.startProcess(...) to exit early if process exit before linePredicate is printed.
  • 5977f26: 8303604: Passing by-value structs whose size is not power of 2 doesn't work on all platforms (mainline)
  • dccfe8a: 8303582: Reduce duplication in jdk/java/foreign tests
  • 8e20145: 8300654: Remove JVMFlag::flag_error_str as it is unused
  • bdffe46: 8301222: Generalize check_release_entry in OopStorage
  • ec4e8aa: 8303244: G1: call CardTable::clear_MemRegion directly
  • ... and 59 more: https://git.openjdk.org/jdk/compare/6af17c1b7d26e639a655405c66aaa1e37a5d8489...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Mar 6, 2023
@openjdk openjdk bot closed this Mar 6, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Mar 6, 2023
@openjdk
Copy link

openjdk bot commented Mar 6, 2023

@stuart-marks @mpdonova Pushed as commit ccfe167.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants