MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
loader.storeEntireState(is);
is.close();
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
bais = new ByteArrayInputStream(baos.toByteArray());
is = new MarshalledValueInputStream(bais);
loader.storeEntireState(is);
is.close();
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
assertEquals(null, loader.get(FQN));
/* Use a complex object to ensure that the class catalog is used. */
Complex c1 = new Complex();
Complex c2 = new Complex(c1);
/* Add objects. */
loader.put(FQN, 1, c1);
loader.put(FQN, 2, c2);
assertEquals(c1, loader.get(FQN).get(1));
assertEquals(c2, loader.get(FQN).get(2));
assertEquals(2, loader.get(FQN).size());
/* Save state. */
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
assertTrue(baos.size() > STREAM_HEADER_LENGTH);
os.close();
byte[] savedState = baos.toByteArray();
/* Clear state. */
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
os.close();
bais = new ByteArrayInputStream(baos.toByteArray());
is = new MarshalledValueInputStream(bais);
loader.storeEntireState(is);
is.close();
assertEquals(null, loader.get(FQN));
/* Restore state. */
bais = new ByteArrayInputStream(savedState);
is = new MarshalledValueInputStream(bais);
loader.storeEntireState(is);
is.close();
assertEquals(c1, loader.get(FQN).get(1));
assertEquals(c2, loader.get(FQN).get(2));