Package org.syncany.operations.watch

Examples of org.syncany.operations.watch.DefaultRecursiveWatcher


    TestFileUtil.createRandomFilesInDirectory(tempDir, 50*1024, 20);   
   
    // Test
    final AtomicBoolean eventOccurred = new AtomicBoolean(false);
   
    DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
      @Override
      public void watchEventsOccurred() {
        eventOccurred.set(true);
      }     
    });
   
    // Start watcher and wait for watch service to set watch on all folders
    watcher.start();   
    Thread.sleep(100);
   
    // Event 1
    TestFileUtil.createRandomFileInDirectory(tempDir, 10);
    assertFalse(eventOccurred.get());

    Thread.sleep(550);
    assertTrue(eventOccurred.get());

    // Stop watcher (close watches)
    watcher.stop();
   
    // Tear down
    TestFileUtil.deleteDirectory(tempDir);
  }
View Full Code Here


    File subDir1 = new File(tempDir+"/subdir1");   
   
    // Test
    final AtomicBoolean eventOccurred = new AtomicBoolean(false);
   
    DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
      @Override
      public void watchEventsOccurred() {
        eventOccurred.set(true);
      }     
    });
   
    // Create sub folder BEFORE watcher starts
    subDir1.mkdir();
   
    // Start watcher and wait for watch service to set watch on all folders
    watcher.start();   
    Thread.sleep(100);
   
    // Event 1
    TestFileUtil.createRandomFileInDirectory(subDir1, 10);
    assertFalse(eventOccurred.get());

    Thread.sleep(350);
    assertTrue(eventOccurred.get());

    // Stop watcher (close watches)
    watcher.stop();
   
    // Tear down
    TestFileUtil.deleteDirectory(tempDir);
  }
View Full Code Here

    File subDir1 = new File(tempDir+"/subdir1");   
   
    // Test
    final AtomicBoolean eventOccurred = new AtomicBoolean(false);
   
    DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
      @Override
      public void watchEventsOccurred() {
        eventOccurred.set(true);
      }     
    });
   
    // Start watcher and wait for watch service to set watch on all folders
    watcher.start();   
    Thread.sleep(150);
   
    // Create sub folder AFTER watcher starts
    subDir1.mkdir();
    Thread.sleep(370);
    assertTrue(eventOccurred.get());
   
    eventOccurred.set(false);
   
    // Event on NEW subfolder
    TestFileUtil.createRandomFileInDirectory(subDir1, 10);
    assertFalse(eventOccurred.get());

    Thread.sleep(350);
    assertTrue(eventOccurred.get());

    // Stop watcher (close watches)
    watcher.stop();
   
    // Tear down
    TestFileUtil.deleteDirectory(tempDir);
  }
View Full Code Here

    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();   
   
    // Test
    final AtomicBoolean eventOccurred = new AtomicBoolean(false);
   
    DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
      @Override
      public void watchEventsOccurred() {
        eventOccurred.set(true);
      }     
    });
   
    // Start watcher and wait for watch service to set watch on all folders
    watcher.start();   
    Thread.sleep(100);

    // Create sub folder hierarchy
    File lastSubFolder = tempDir;
   
    for (int i=0; i<100; i++) {
      lastSubFolder.mkdir();
      lastSubFolder = new File(lastSubFolder+"/"+i);
    }
   
    lastSubFolder.mkdir();
   
    // Wait for settlement
    Thread.sleep(350);
    eventOccurred.set(false);
   
    // Event on DEEPEST new subfolder
    TestFileUtil.createRandomFileInDirectory(lastSubFolder, 10*1024);
    assertFalse(eventOccurred.get());
   
    Thread.sleep(500);
    assertTrue(eventOccurred.get());
   
    // Stop watcher (close watches)
    watcher.stop();
   
    // Tear down 
    TestFileUtil.deleteDirectory(tempDir);
  }
View Full Code Here

    // Test
    final AtomicLong watcherEventOccurredTime = new AtomicLong(0L);
    final AtomicInteger watcherEventOccurredCount = new AtomicInteger(0);
    final AtomicLong fileWrittenTime = new AtomicLong(0L);
   
    DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
      @Override
      public void watchEventsOccurred() {
        watcherEventOccurredCount.addAndGet(1);
        watcherEventOccurredTime.set(System.currentTimeMillis());
      }     
    });
   
    // Start watcher
    watcher.start();   
    Thread.sleep(200); // Wait for watch service to set watch on all folders
   
    File largeFile = new File(tempDir+"/largefile");
       
    TestFileUtil.createRandomFile(largeFile, 50*1024*1024);
    fileWrittenTime.set(System.currentTimeMillis());
   
    // Stop watcher (close watches)
    Thread.sleep(400); // Wait for the watcher to fire an event
    watcher.stop();
   
    // Test
    assertNotSame(0L, watcherEventOccurredTime.get());
    assertEquals(1, watcherEventOccurredCount.get());
    assertNotSame(0L, fileWrittenTime.get());
View Full Code Here

    File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();   
   
    // Test
    final AtomicInteger watcherEventOccurredCount = new AtomicInteger(0);
   
    DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
      @Override
      public void watchEventsOccurred() {
        watcherEventOccurredCount.addAndGet(1);
      }     
    });
   
    // Start watcher
    watcher.start();   
    Thread.sleep(200); // Wait for watch service to set watch on all folders
   
    for (int i=0; i<20; i++) {
      TestFileUtil.createRandomFile(new File(tempDir+"/"+i), 50*1024);
    }       

    // Stop watcher (close watches)
    Thread.sleep(400); // Wait for the watcher to fire an event
    watcher.stop();
   
    // Test
    assertEquals(1, watcherEventOccurredCount.get()); // not 20!
   
    // Tear down 
View Full Code Here

TOP

Related Classes of org.syncany.operations.watch.DefaultRecursiveWatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.