Discussions

News: Unit Testing Serialization Evolution

  1. Unit Testing Serialization Evolution (4 messages)

    Ever need to unit test that your class changes maintain serialization compatibility? This blog entry provides a hack that enables you to do just that. Why?
    Say for example I use session replication in my web application. If I deploy some new code to one server in the cluster to flush out any remaining bugs before a full deployment, I want the old servers to fail over to the new server. And if I decide to take that new server down and implement some more changes, I want its session state to fail over to one of the old servers that are still running. This means the serialized state of objects on the session needs to be compatible in both directions.

    Here's another example. I'm a JVM vendor. I need to make sure that my implementation of HashMap can deserialize state from an old implementation or another vendor's implementation and vice versa.

    Read Unit Testing Serialization Evolution

    Threaded Messages (4)

  2. Unit Testing Serialization Evolution[ Go to top ]

    Ick. The technique assumes that the class name is written using ObjectOutputStream.writeUTF, and nothing else uses that method. Wouldn't writeClassDescriptor/readClassDescriptor work better (not used them myself)?

    I was expecting class-loader funkyness and no renaming classes.
  3. Unit Testing Serialization Evolution[ Go to top ]

    Ick. The technique assumes that the class name is written using ObjectOutputStream.writeUTF, and nothing else uses that method. Wouldn't writeClassDescriptor/readClassDescriptor work better (not used them myself)?

    Yeah. Good suggestion.
    I was expecting class-loader funkyness and no renaming classes.

    Too much of a pain, even after you get it set up. You have to save code snapshots. Then you have to be careful to separate test code that works with the old and new classes. Not worth it in my opinion.
  4. Unit Testing Serialization Evolution[ Go to top ]

    Wouldn't writeClassDescriptor/readClassDescriptor work better (not used them myself)?

    This can work, but you have to copy and paste all of the code from ObjectStreamClass.writeNonProxy() so that you write the correct field meta data.
  5. Unit Testing Serialization Evolution[ Go to top ]

    Wouldn't writeClassDescriptor/readClassDescriptor work better (not used them myself)?

    Version 2. Sticking to public API was a little tricky.