Author: sergiykarpenko
Date: 2010-10-22 07:24:11 -0400 (Fri, 22 Oct 2010)
New Revision: 3337
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/CASableFileIOChannelTestBase.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java
Log:
EXOJCR-999: tests updated - now unused FileCleaners will be stopped
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java 2010-10-22
10:32:02 UTC (rev 3336)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java 2010-10-22
11:24:11 UTC (rev 3337)
@@ -153,8 +153,7 @@
wconf.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
- FileCleanerHolder wfcleaner =
- (FileCleanerHolder)wsc.getComponent(FileCleanerHolder.class);
+ FileCleanerHolder wfcleaner =
(FileCleanerHolder)wsc.getComponent(FileCleanerHolder.class);
fileCleaner = wfcleaner.getFileCleaner();
holder = new ReaderSpoolFileHolder();
}
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/CASableFileIOChannelTestBase.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/CASableFileIOChannelTestBase.java 2010-10-22
10:32:02 UTC (rev 3336)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/CASableFileIOChannelTestBase.java 2010-10-22
11:24:11 UTC (rev 3337)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.impl.storage.value.cas.RecordAlreadyExistsException;
import org.exoplatform.services.jcr.impl.storage.value.cas.RecordNotFoundException;
import org.exoplatform.services.jcr.impl.storage.value.cas.ValueContentAddressStorage;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -48,8 +47,6 @@
protected ValueContentAddressStorage vcas;
- protected FileCleaner fileCleaner;
-
protected File rootDir;
protected String storageId;
@@ -61,9 +58,6 @@
{
super.setUp();
- if (fileCleaner == null)
- fileCleaner = new FileCleaner();
-
if (vcas == null)
initVCAS();
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java 2010-10-22
10:32:02 UTC (rev 3336)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java 2010-10-22
11:24:11 UTC (rev 3337)
@@ -43,7 +43,7 @@
private File rootDir;
- private FileCleaner cleaner = new FileCleaner(2000);
+ private FileCleaner cleaner;
private ValueDataResourceHolder resources = new ValueDataResourceHolder();
@@ -57,6 +57,8 @@
{
super.setUp();
+ cleaner = new FileCleaner(2000);
+
rootDir = new File(new File("target"), "vs1");
rootDir.mkdirs();
@@ -67,6 +69,15 @@
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void tearDown() throws Exception
+ {
+ cleaner.halt();
+ }
+
public void testRead() throws Exception
{
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java 2010-10-22
10:32:02 UTC (rev 3336)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java 2010-10-22
11:24:11 UTC (rev 3337)
@@ -81,27 +81,34 @@
public void testIfFinalizeRemovesTempFileStreamValueData() throws Exception
{
+ FileCleaner testFileCleaner = new FileCleaner(1000, true);
+ try
+ {
+ byte[] buf = "0123456789".getBytes();
+ SwapFile file = SwapFile.get(new File("target"),
"testIfFinalizeRemovesTempFileStreamValueData");
+ //File file = new
File("target/testIfFinalizeRemovesTempFileStreamValueData");
+ //if (file.exists())
+ // file.delete();
+ FileOutputStream out = new FileOutputStream(file);
+ out.write(buf);
+ out.close();
- byte[] buf = "0123456789".getBytes();
- SwapFile file = SwapFile.get(new File("target"),
"testIfFinalizeRemovesTempFileStreamValueData");
- //File file = new
File("target/testIfFinalizeRemovesTempFileStreamValueData");
- //if (file.exists())
- // file.delete();
- FileOutputStream out = new FileOutputStream(file);
- out.write(buf);
- out.close();
+ CleanableFilePersistedValueData vd = new CleanableFilePersistedValueData(0,
file, testFileCleaner);
+ assertTrue(file.exists());
- CleanableFilePersistedValueData vd = new CleanableFilePersistedValueData(0, file,
new FileCleaner(1000, true));
- assertTrue(file.exists());
+ vd = null;
+ System.gc();
- vd = null;
- System.gc();
+ // allows GC to call finalize on vd
+ Thread.sleep(2500);
+ System.gc();
- // allows GC to call finalize on vd
- Thread.sleep(2500);
- System.gc();
-
- assertFalse(file.exists());
+ assertFalse(file.exists());
+ }
+ finally
+ {
+ testFileCleaner.halt();
+ }
}
public void testConcurrentFileStreamValueDataReading() throws Exception
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java 2010-10-22
10:32:02 UTC (rev 3336)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java 2010-10-22
11:24:11 UTC (rev 3337)
@@ -66,37 +66,46 @@
public void testCreateFileStreamTransientValueData() throws Exception
{
+ FileCleaner testFileCleaner = new FileCleaner();
+ try
+ {
+ byte[] buf = "0123456789".getBytes();
+ File file = new
File("target/testCreateFileStreamTransientValueData");
+ if (file.exists())
+ file.delete();
+ FileOutputStream out = new FileOutputStream(file);
+ out.write(buf);
+ out.close();
- byte[] buf = "0123456789".getBytes();
- File file = new File("target/testCreateFileStreamTransientValueData");
- if (file.exists())
- file.delete();
- FileOutputStream out = new FileOutputStream(file);
- out.write(buf);
- out.close();
+ FileInputStream fs1 = new FileInputStream(file);
+ TransientValueData vd =
+ new TransientValueData(0, null, fs1, null, testFileCleaner, 5, new
File("target"), true);
- FileInputStream fs1 = new FileInputStream(file);
- TransientValueData vd = new TransientValueData(0, null, fs1, null, new
FileCleaner(), 5, new File("target"), true);
+ // spool to file
+ InputStream fs2 = vd.getAsStream();
+ assertEquals(10, vd.getLength());
+ assertTrue(fs2 instanceof FileInputStream);
- // spool to file
- InputStream fs2 = vd.getAsStream();
- assertEquals(10, vd.getLength());
- assertTrue(fs2 instanceof FileInputStream);
+ // not the same object as new is is from spool file
+ assertNotSame(fs1, fs2);
+ // spooled to file so not a byte array
+ assertFalse(vd.isByteArray());
- // not the same object as new is is from spool file
- assertNotSame(fs1, fs2);
- // spooled to file so not a byte array
- assertFalse(vd.isByteArray());
+ // next call return not the same object as well
+ // (new stream every time)
+ assertNotSame(vd.getAsStream(), fs2);
+ assertEquals(10, vd.getLength());
- // next call return not the same object as well
- // (new stream every time)
- assertNotSame(vd.getAsStream(), fs2);
- assertEquals(10, vd.getLength());
+ // gets as byte array
+ assertEquals(10, vd.getAsByteArray().length);
+ // but still spooled to file
+ assertFalse(vd.isByteArray());
- // gets as byte array
- assertEquals(10, vd.getAsByteArray().length);
- // but still spooled to file
- assertFalse(vd.isByteArray());
+ }
+ finally
+ {
+ testFileCleaner.halt();
+ }
}
@@ -118,7 +127,7 @@
// TODO not influenced here as will be spooled to byte array anyway
//vd.setMaxBufferSize(5);
//vd.setFileCleaner(new FileCleaner());
-
+
//
InputStream fs2 = vd.getAsStream();
assertEquals(10, vd.getLength());
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java 2010-10-22
10:32:02 UTC (rev 3336)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java 2010-10-22
11:24:11 UTC (rev 3337)
@@ -50,43 +50,51 @@
public void testNewBinaryValue() throws Exception
{
+ FileCleaner testFileCleaner = new FileCleaner();
- byte[] buf = "012345678901234567890123456789".getBytes();
- File file = new File("target/testNewBinaryValue");
- if (file.exists())
- file.delete();
- FileOutputStream out = new FileOutputStream(file);
- out.write(buf);
- out.close();
+ try
+ {
+ byte[] buf = "012345678901234567890123456789".getBytes();
+ File file = new File("target/testNewBinaryValue");
+ if (file.exists())
+ file.delete();
+ FileOutputStream out = new FileOutputStream(file);
+ out.write(buf);
+ out.close();
- FileInputStream fs1 = new FileInputStream(file);
- BinaryValue val = new BinaryValue(fs1, new FileCleaner(), tempDirectory,
maxFufferSize);
- InputStream str1 = val.getStream();
- assertNotNull(str1);
+ FileInputStream fs1 = new FileInputStream(file);
+ BinaryValue val = new BinaryValue(fs1, testFileCleaner, tempDirectory,
maxFufferSize);
+ InputStream str1 = val.getStream();
+ assertNotNull(str1);
- // obj returned by getStream() is not the same as incoming stream
- assertNotSame(str1, fs1);
+ // obj returned by getStream() is not the same as incoming stream
+ assertNotSame(str1, fs1);
- // streams returned by subsequent call of val.getStream() are equals
- assertEquals(str1, val.getStream());
+ // streams returned by subsequent call of val.getStream() are equals
+ assertEquals(str1, val.getStream());
- // another one value using the same string
- BinaryValue val2 = new BinaryValue(fs1, new FileCleaner(), tempDirectory,
maxFufferSize);
- InputStream str2 = val2.getStream();
+ // another one value using the same string
+ BinaryValue val2 = new BinaryValue(fs1, testFileCleaner, tempDirectory,
maxFufferSize);
+ InputStream str2 = val2.getStream();
- // are not the same although created from same Stream
- assertNotSame(str1, str2);
+ // are not the same although created from same Stream
+ assertNotSame(str1, str2);
- // stream already consumed
- try
- {
- val.getString();
- fail("IllegalStateException should have been thrown");
+ // stream already consumed
+ try
+ {
+ val.getString();
+ fail("IllegalStateException should have been thrown");
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ // System.out.println(" >>>>>>>>STRING >>>
"+);
}
- catch (IllegalStateException e)
+ finally
{
+ testFileCleaner.halt();
}
- // System.out.println(" >>>>>>>>STRING >>>
"+);
}
public void testNewBinaryValueFromString() throws Exception