Package com.google.enterprise.connector.filesystem.LastAccessFileDelegate

Examples of com.google.enterprise.connector.filesystem.LastAccessFileDelegate.FileTime


   * Test getting and setting the last access time of the file.
   */
  public void testGetSetAccessTime() throws Exception {
    WindowsReadonlyFile file =
        new WindowsReadonlyFile(fileSystemType, file1.getAbsolutePath(), false);
    FileTime fileTime = file.getLastAccessTime();

    // A null FileTime probably means we are not running on Windows.
    // But this at least checks that we didn't blow up trying.
    if (fileTime == null) {
      assertNotWindows("access time");
      return;
    }

    // Sleep a little bit. Then access the file.
    try { Thread.sleep(3000); } catch (InterruptedException ignored) {}

    // We intentionally did not configure this to preserve LastAccessTime.
    assertEquals(FILE_ONE_CONTENTS, contents(file.getInputStream()));

    // Reading should have changed the access time of the file.
    assertFalse(fileTime.equals(file.getLastAccessTime()));

    // Restore the original access time and make sure it sticks.
    file.setLastAccessTime(fileTime);
    assertTrue(fileTime.equals(file.getLastAccessTime()));
  }
View Full Code Here


   * when not preserving.
   */
  public void testNoPreserveAccessTimeRead() throws Exception {
    MockLastAccessReadonlyFile file =
        new MockLastAccessReadonlyFile("file", false);
    FileTime fileTime = file.getLastAccessTime();
    assertNotNull(fileTime);

    // We intentionally did not configure this to preserve LastAccessTime.
    file.getInputStream().close();

    // Reading should have changed the access time of the file.
    assertFalse(fileTime.equals(file.getLastAccessTime()));

    // Restore the original access time and make sure it sticks.
    file.setLastAccessTime(fileTime);
    assertTrue(fileTime.equals(file.getLastAccessTime()));
  }
View Full Code Here

   * when not preserving.
   */
  public void testNoPreserveAccessTimeList() throws Exception {
    MockLastAccessReadonlyFile file =
        new MockLastAccessReadonlyFile("dir", false);
    FileTime fileTime = file.getLastAccessTime();
    assertNotNull(fileTime);

    // We intentionally did not configure this to preserve LastAccessTime.
    file.listFiles();

    // Reading should have changed the access time of the file.
    assertFalse(fileTime.equals(file.getLastAccessTime()));

    // Restore the original access time and make sure it sticks.
    file.setLastAccessTime(fileTime);
    assertTrue(fileTime.equals(file.getLastAccessTime()));
  }
View Full Code Here

   * Test that reading file contents preserves last access time.
   */
  public void testPreserveAccessTimeRead() throws Exception {
    MockLastAccessReadonlyFile file =
        new MockLastAccessReadonlyFile("file", true);
    FileTime fileTime = file.getLastAccessTime();
    assertNotNull(fileTime);

    // We configured this to preserve LastAccessTime.
    InputStream is = file.getInputStream();
    // Reading should have changed the access time of the file.
    assertFalse(fileTime.equals(file.getLastAccessTime()));

    // Closing the stream should restore the last access time.
    is.close();
    assertTrue(fileTime.equals(file.getLastAccessTime()));
  }
View Full Code Here

   * Test that listing directory contents preserves last access time.
   */
  public void testPreserveAccessTimeList() throws Exception {
    MockLastAccessReadonlyFile file =
        new MockLastAccessReadonlyFile("dir", true);
    FileTime fileTime = file.getLastAccessTime();
    assertNotNull(fileTime);

    // We configured this to preserve LastAccessTime.
    file.listFiles();

    // The original access time should have been restored.
    assertTrue(fileTime.equals(file.getLastAccessTime()));
  }
View Full Code Here

   */
  public void testPreserveAccessTimeMultipleReaders() throws Exception {
    MockLastAccessReadonlyFile file =
        new MockLastAccessReadonlyFile("file", true);
    String path = file.getPath();
    FileTime fileTime = file.getLastAccessTime();
    assertNotNull(fileTime);

    // We configured this to preserve LastAccessTime.
    InputStream is1 = file.getInputStream();
    InputStream is2 = file.getInputStream();
    InputStream is3 = file.getInputStream();
    // Reading should have changed the access time of the file.
    assertFalse(fileTime.equals(file.getLastAccessTime()));

    // Peek at the internal map of remembered access times.
    List<FileTime> list = AccessTimePreservingReadonlyFile.map.get(path);
    assertNotNull(list);
    assertEquals(3, list.size());

    // Closing the streams should restore the last access time
    // to the original time.
    is2.close();
    assertTrue(fileTime.equals(file.getLastAccessTime()));
    is1.close();
    assertTrue(fileTime.equals(file.getLastAccessTime()));
    is3.close();
    assertTrue(fileTime.equals(file.getLastAccessTime()));

    // We should be purged from the internal map of remembered access times.
    list = AccessTimePreservingReadonlyFile.map.get(path);
    assertNull(list);
  }
View Full Code Here

   *         retrieved.
   */
  @VisibleForTesting
  protected FileTime getLastAccessTime() {
    try {
      FileTime accessTime = delegate.getLastAccessTime();
      LOG.log(Level.FINEST, "Got the last access time for {0} as {1}",
              new Object[] { delegate.getPath(), accessTime });
      return accessTime;
    } catch (IOException e) {
      LOG.log(Level.FINEST, "Failed to get the last access time for {0}: {1}",
View Full Code Here

   * @param path
   */
  private static FileTime removeFromMap(
      AccessTimePreservingReadonlyFile<?> file) {
    String path = file.getPath();
    FileTime accessTime = null;
    synchronized (map) {
      List<FileTime> list = map.get(path);
      if (list != null && !list.isEmpty()) {
        accessTime = list.remove(list.size() - 1);
        if (list.isEmpty()) {
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.filesystem.LastAccessFileDelegate.FileTime

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.