public void testRemove() throws IOException
{
File f = this.createBLOBTempFile("tempFile", 300);
FilePersistedValueData vd = new FilePersistedValueData(0, f, SpoolConfig.getDefaultSpoolConfig());
// vd.setMaxBufferSize(200*1024);
// assertNull(vd.getFile()); // not spooling by default until getAsStream() will be call
File serf = File.createTempFile("serialization", "test");
ObjectWriter wr = new ObjectWriterImpl(new FileOutputStream(serf));
PersistedValueDataWriter vdw = new PersistedValueDataWriter();
vdw.write(wr, vd);
wr.flush();
wr.close();
vd = null;
// read first time
ObjectReader or = new ObjectReaderImpl(new FileInputStream(serf));
FilePersistedValueData vd1 = null;
PersistedValueDataReader vdr = new PersistedValueDataReader(holder, SpoolConfig.getDefaultSpoolConfig());
try
{
vd1 = (FilePersistedValueData)vdr.read(or, PropertyType.BINARY);
}
catch (UnknownClassIdException e)
{
fail(e.getMessage());
}
or.close();
// Imitation save
((StreamPersistedValueData) vd1).setPersistedFile(((StreamPersistedValueData) vd1).getTempFile());
// read second time
or = new ObjectReaderImpl(new FileInputStream(serf));
FilePersistedValueData vd2 = null;
try
{
vd2 = (FilePersistedValueData)vdr.read(or, PropertyType.BINARY);
}
catch (UnknownClassIdException e)
{
fail(e.getMessage());
}
or.close();
// Imitation save
((StreamPersistedValueData) vd2).setPersistedFile(((StreamPersistedValueData) vd2).getTempFile());
assertTrue(vd1.getFile().exists());
assertTrue(vd2.getFile().exists());
// remove first one
vd1 = null;
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(vd2.getFile().exists());
f.delete();
}