public static List<File> createRandomFilesInDirectory(File rootFolder, long sizeInBytes, int numOfFiles) throws IOException { List<File> newRandomFiles = new ArrayList<File>(); for (int i = 0; i < numOfFiles; i++) { newRandomFiles.add(createRandomFileInDirectory(rootFolder, sizeInBytes)); } return newRandomFiles; }
@Test public void testGetFolder() throws Exception { final AtomicInteger eventCount = new AtomicInteger(0); final Path tempDir = TestFileUtil.createTempDirectoryInSystemTemp("RecursiveWatcherTest").toPath(); RecursiveWatcher watcher = RecursiveWatcher.createRecursiveWatcher(tempDir, new ArrayList<Path>(), 300, new WatchListener() { @Override public void watchEventsOccurred() { eventCount.incrementAndGet(); } }); watcher.start(); Thread.sleep(100); TestFileUtil.createRandomFileInDirectory(tempDir.toFile(), 111); Thread.sleep(350); TestFileUtil.createRandomFileInDirectory(tempDir.toFile(), 222); Thread.sleep(350); TestFileUtil.createRandomFileInDirectory(tempDir.toFile(), 333); Thread.sleep(350); assertEquals(3, eventCount.get()); TestFileUtil.deleteDirectory(tempDir.toFile()); }
@Test public void testNextChunkEvenIfThereAreNone() throws IOException { // Test Constants final int TOTAL_FILE_SIZE = 5 * 1024; final int EXACT_CHUNK_SIZE = 512 * 1024; // Setup File inputFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE); Chunker chunker = new FixedChunker(EXACT_CHUNK_SIZE); // Create chunks Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputFile); while (chunkEnumeration.hasMoreElements()) { chunkEnumeration.nextElement(); } // This should lead to an IOException assertNull("No chunk expected, but data received.", chunkEnumeration.nextElement()); assertFalse("hasElements() should return 'false' if no chunk available.", chunkEnumeration.hasMoreElements()); }
@Test public void testNextChunkEvenIfThereAreNone() throws IOException { // Test Constants final int TOTAL_FILE_SIZE = 5*1024; final int CHUNK_SIZE = 512*1024; // Setup File inputFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE); Chunker chunker = new TttdChunker(CHUNK_SIZE); // Create chunks Enumeration<Chunk> chunkEnumeration = chunker.createChunks(inputFile); while (chunkEnumeration.hasMoreElements()) { chunkEnumeration.nextElement(); } // This should lead to an IOException assertNull("No chunk expected, but data received.", chunkEnumeration.nextElement()); assertFalse("hasElements() should return 'false' if no chunk available.", chunkEnumeration.hasMoreElements()); } }
File lockedFile = TestFileUtil.createRandomFileInDirectory(tempDir, 50*1024);
File inputRandom5MBFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE);
File inputRandom5MBFile = TestFileUtil.createRandomFileInDirectory(tempDir, TOTAL_FILE_SIZE);