Skip to content

Commit

Permalink
Fixed an issue where ThresholdFileWriter unit tests would periodicall…
Browse files Browse the repository at this point in the history
…y fail on windows depending on the order the unit tests were run.

One of the unit tests held a handle on a file while also trying to delete the file. This caused a second unit test to fail.
  • Loading branch information
abrougher committed Jun 17, 2012
1 parent bca0669 commit 9a91d9b
Showing 1 changed file with 19 additions and 4 deletions.
Expand Up @@ -19,6 +19,7 @@
* under the License. */
package org.jumpmind.symmetric.io.data.stage;

import java.io.BufferedReader;
import java.io.File;

import org.apache.commons.io.IOUtils;
Expand All @@ -35,24 +36,38 @@ public void testNoWriteToFile() throws Exception {
File file = getTestFile();
ThresholdFileWriter writer = new ThresholdFileWriter(TEST_STR.length() + 1, new StringBuilder(), file);
writer.write(TEST_STR);

// File does not exist since we did not meet the threshold
Assert.assertFalse(file.exists());

// Check the contents of the buffer (not yet written to a file)
Assert.assertEquals(TEST_STR, IOUtils.toString(writer.getReader()));
file.delete();
}

@Test
public void testWriteToFile() throws Exception {
File file = getTestFile();
ThresholdFileWriter writer = new ThresholdFileWriter(TEST_STR.length() - 1, new StringBuilder(), file);
Assert.assertFalse(file.exists());

ThresholdFileWriter writer = new ThresholdFileWriter( TEST_STR.length() - 1, new StringBuilder(), file);
writer.write(TEST_STR);
writer.close();

// The write string exceeded the threshold so the writer should have created/written to the file
Assert.assertTrue(file.exists());
Assert.assertEquals(TEST_STR, IOUtils.toString(writer.getReader()));
file.delete();

BufferedReader reader = writer.getReader();
Assert.assertEquals(TEST_STR, IOUtils.toString(reader));
reader.close();

Assert.assertTrue(file.delete());
}

private File getTestFile() {
File file = new File("target/test/buffered.file.writer.tst");
file.getParentFile().mkdirs();

// Make sure the file doesn't already exist
file.delete();
return file;
}
Expand Down

0 comments on commit 9a91d9b

Please sign in to comment.