Corda: exceptions when running junit tests in IDE

175 Views Asked by At

Suddenly started seeing strange exceptions when running junit tests last week. Given my lack of deep knowledge of Corda internals at present, this (slightly embarrassingly!) took some time to resolve, but I thought the following note might save others some time. The exceptions in question are:

  • missing reference.conf
  • Class kotlin.collections.EmptyList is not annotated or on the whitelist, so cannot be used in serialization

(After a great deal of head scratching, thought, and trial and error I established this was due to missing dependencies as described below. But would appreciate comments from the Corda dev team. )

Apologies for detailed commentary below. Happy to delete if not useful / contrary to StackOverflow guidelines.

The first exception (missing reference.conf) was due to a missing dependency on the node-main module. This module contains the reference.conf text file which supplies default config for nodes. If the node starting code cannot find it an exception is thrown and the node is not started.

The second exception is due to missing node-api module. After stepping through the whole stack carefully and understanding what was happening as I progressed down through the layers, I discovered the DefaultCustomisation code which adds various core types to the whitelist for Kyro serialisation was not being invoked when running from my junit test. This exception is thrown at the point of first communication from an RPC client to a running node via the RPC proxy. In this case upon the call to "protocolVersion" where the RPCClient class checks if the server RPC protocol version is not less than that specified in the RPC client config. I assume the DefaultCustomisation is applied on first contact, and in this case due to the missing module dependency the basic list of DefaultCusomisations which exist in the node-api module were not being applied. This resulted in the above exception. There is an issue discussed on the discourse forum which is very closely related, and the notes on that issue were helpful. However, the change which was discussed and code fix subsequently applied was to ensure that the class loader of the DefaultKyroCustomizer instantiation is used when searching for plugin registries. This results in the classpath of the client rpc application being searched as opposed to the more limited classpath of the defabstract class CordaPluginRegistry (?). This didn't solve my issue as the exception was due to the rather more fundamental issue of the core DefaultCustomisation code not being accessible at runtime!

I suspect this is a non-issue when developing a distinct CordaApp which simply depends on corda.jar as all the required modules are will automatically be loaded from that jar (?). By ensuring the two Corda modules in question are loaded by the IDE (via the IntelliJ IDEA .iml file) the junit tests all then ran exception free.

However, one potential and minor suggestion might be if Corda could verify all DefaultSerialisers are present, accessible, and loaded during node startup in a similar way to the verification of presence of the reference.conf; as opposed to the issue only becoming apparent at occurrence of first attempt of RPC communication? As a sort of defensive measure possibly?

Any corrections / further comments on the above would be warmly appreciated :-)

1

There are 1 best solutions below

0
On

This is an awesome breakdown, thanks for sharing.

I can share it back home to the R3 team to dig in and see if we can add that DefaultSerializer suggestion.

Best of luck!