8000 ENT-11328: Update node initialisation to be flexible if JDK modules are not open to reflection by shamsasari · Pull Request #7640 · corda/corda · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ENT-11328: Update node initialisation to be flexible if JDK modules are not open to reflection #7640

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

Draft
wants to merge 2 commits into
base: release/os/4.12
Choose a base branch
from

Conversation

shamsasari
Copy link
Contributor
@shamsasari shamsasari commented Jan 3, 2024

This was work-in-progress, exploratory PR

The overall goal was to eliminate, or reduce as much as possible, the need for the JVM --add-opens flags when running the unit tests. The reason for this is it will also affect users when they write tests using the mock network or the in-process node driver. The users will essentially need to copy most of the same flags the node uses when it runs. This isn't a very good user experience, though perhaps manageable with some documentation.

The process I took was to remove the node-jvm-args.txt from the jvmArgs for all unit tests, and only added for tests which absolutely needed them, such as checkpoint serialisation tests. This later example had its own module created checkpoint-tests.

The main reason the flags are needed is due to Kryo serialisation of checkpoints, when it tries to access private members of the JDK via reflection. The access is typically needed by the Kryo serialisers, so instead of adding these serialisers, it first checks if it has access to do so and then adds them. This is primarily done by the new Class<*>.isPackageOpen. If the package is open, which will be the case with a proper Corda node process, then the serialiser is added as usual. If it's not open, which will be the case with mock nodes, then it registers a fall back serialiser via Kryo.registerAsInaccessible. This will try to write out checkpoints using a backend serialiser, but it will not be able to deserialise the correct type. For example, it will serialise an unmodifiableList using a normal List serialiser, but it can't deserialise it since it needs access to internals of the unmodifiableList class. So instead during checkpoint deserialisation it will throw an exception with a help message:

Restoring checkpoints containing ${type.name} objects is not supported in this test " +
                "environment. If you wish to restore these checkpoints in your tests then use the out-of-process node driver, or add " +
                "--add-opens=${type.fullyQualifiedPackage}=ALL-UNNAMED to the test JVM args.

Since most mock node tests will not be restarting nodes, which is when checkpoints are deserialised, this will not affect majority of tests.

There are other changes to reduce the need to reflect on JDK internals.

@shamsasari shamsasari force-pushed the shams-flexible-kryo-init branch from 344cd9b to a39e0d6 Compare January 3, 2024 17:06
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.

1 participant
0