How would you unittest a safe-publication guarantee in Java?
To be concrete:
I have a Cache interface that has a method getOrLoad(K key, ObjectLoader loader). Thing is, if a Cache cannot find an object for the given key, then it must load it from the ObjectLoader instance. However, the Cache is required to guarantee that the act of loading an object from the loader and putting it into the Cache, constitutes a safe publication.
I'm now in the midst of writing a generic junit test for this Cache interface and I wonder how I would test that the Cache implementations adhere to this safe publication guarantee.
Any ideas? The actual code is in the test-systest module part of the code repository in case you want to poke at the real files.