コード例 #1
0
  public void testClearContainerAndThenDeleteContainer() throws IOException {
    storageStrategy.createContainer(CONTAINER_NAME);
    Set<String> blobs =
        TestUtils.createBlobsInContainer(
            CONTAINER_NAME,
            new String[] {
              TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
              TestUtils.createRandomBlobKey(
                  "bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg")
            });
    // test if file exits
    for (String blob : blobs) {
      TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
    }

    // clear the container
    storageStrategy.clearContainer(CONTAINER_NAME);
    // test if container still exits
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
    // test if file was cleared
    for (String blob : blobs) {
      TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, false);
    }

    // delete the container
    storageStrategy.deleteContainer(CONTAINER_NAME);
    // test if container still exits
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
    assertFalse(storageStrategy.containerExists(CONTAINER_NAME), "Container still exists");
  }
コード例 #2
0
 public void testClearContainer_NotExistingContainer() throws IOException {
   // test if container still exits
   TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
   // clear the container
   storageStrategy.clearContainer(CONTAINER_NAME);
   // test if container still exits
   TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
 }
コード例 #3
0
  public void testCreateContainer() {
    boolean result;

    TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
    result = storageStrategy.createContainer(CONTAINER_NAME);
    assertTrue(result, "Container not created");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
  }
コード例 #4
0
  public void testDeleteContainer_EmptyContanier() {
    boolean result;
    blobStore.createContainerInLocation(null, CONTAINER_NAME);

    result = blobStore.containerExists(CONTAINER_NAME);
    assertTrue(result, "Container doesn't exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);

    // delete container
    blobStore.deleteContainer(CONTAINER_NAME);
    result = blobStore.containerExists(CONTAINER_NAME);
    assertFalse(result, "Container still exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
  }
コード例 #5
0
  /** Test of removeBlob method, with only one blob with a complex path as key */
  @Test
  public void testRemoveBlob_ComplexBlobKey() throws IOException {
    final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
    boolean result;

    // checks that blob doesn't exists
    blobStore.createContainerInLocation(null, CONTAINER_NAME);
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
    assertFalse(result, "Blob exists");
    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);

    // create the blob
    TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY);
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
    assertTrue(result, "Blob doesn't exist");

    // remove it
    blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
    assertFalse(result, "Blob still exists");
    // file removed
    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
    // also the entire directory structure was removed
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
  }
コード例 #6
0
  public void testDeleteContainer() throws IOException {
    final String BLOB_KEY1 = "blobName.jpg";
    final String BLOB_KEY2 =
        "aa"
            + FS
            + "bb"
            + FS
            + "cc"
            + FS
            + "dd"
            + FS
            + "ee"
            + FS
            + "ff"
            + FS
            + "23"
            + FS
            + "blobName.jpg";
    boolean result;

    result = storageStrategy.createContainer(CONTAINER_NAME);

    // put data inside the container
    TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {BLOB_KEY1, BLOB_KEY2});

    storageStrategy.deleteContainer(CONTAINER_NAME);
    assertTrue(result, "Cannot delete container");
    TestUtils.directoryExists(CONTAINER_NAME, false);
  }
コード例 #7
0
  public void testCreateDirectory() {
    storageStrategy.createDirectory(CONTAINER_NAME, null);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);

    storageStrategy.createDirectory(CONTAINER_NAME, "subdir");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir", true);

    storageStrategy.createDirectory(CONTAINER_NAME, "subdir1" + FS);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir1", true);

    storageStrategy.createDirectory(CONTAINER_NAME, FS + "subdir2");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir2", true);

    storageStrategy.createDirectory(CONTAINER_NAME, "subdir3" + FS + "subdir4");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir2", true);
  }
コード例 #8
0
  public void testDeleteDirectory() throws IOException {
    TestUtils.createContainerAsDirectory(CONTAINER_NAME);
    TestUtils.createBlobsInContainer(
        CONTAINER_NAME,
        new String[] {
          TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
          TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg")
        });

    // delete directory in different ways
    storageStrategy.deleteDirectory(CONTAINER_NAME, "lev1" + FS + "lev2" + FS + "lev4");
    TestUtils.directoryExists(
        TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2" + FS + "lev4", false);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2", true);

    storageStrategy.deleteDirectory(CONTAINER_NAME, "lev1" + FS + "lev2" + FS + "lev3" + FS);
    TestUtils.directoryExists(
        TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2" + FS + "lev3", false);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2", true);

    storageStrategy.deleteDirectory(CONTAINER_NAME, FS + "lev1");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1", false);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);

    // delete the directory and all the files inside
    TestUtils.createBlobsInContainer(
        CONTAINER_NAME,
        new String[] {
          TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
          TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg")
        });
    storageStrategy.deleteDirectory(CONTAINER_NAME, null);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
  }
コード例 #9
0
  public void testDeleteContainer_EmptyContainer() {
    boolean result;

    result = storageStrategy.createContainer(CONTAINER_NAME);
    assertTrue(result, "Cannot create container");

    storageStrategy.deleteContainer(CONTAINER_NAME);
    TestUtils.directoryExists(CONTAINER_NAME, false);
  }
コード例 #10
0
  public void testDeleteContainer() throws IOException {
    boolean result;
    String CONTAINER_NAME2 = "container-to-delete";
    String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
    blobStore.createContainerInLocation(null, CONTAINER_NAME);
    blobStore.createContainerInLocation(null, CONTAINER_NAME2);

    result = blobStore.containerExists(CONTAINER_NAME);
    assertTrue(result, "Container [" + CONTAINER_NAME + "] doesn't exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
    result = blobStore.containerExists(CONTAINER_NAME2);
    assertTrue(result, "Container [" + CONTAINER_NAME2 + "] doesn't exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);

    // create blobs inside container
    TestUtils.createBlobsInContainer(
        CONTAINER_NAME,
        TestUtils.createRandomBlobKey("testutils-", null),
        TestUtils.createRandomBlobKey("testutils-", null),
        TestUtils.createRandomBlobKey("ab123s" + File.separator + "testutils-", null));
    TestUtils.createBlobsInContainer(
        CONTAINER_NAME,
        TestUtils.createRandomBlobKey("testutils-", null),
        TestUtils.createRandomBlobKey("testutils-", null),
        TestUtils.createRandomBlobKey("asda123s" + File.separator + "testutils-", null),
        TestUtils.createRandomBlobKey("123-_3s" + File.separator + "testutils-", null));

    // delete first container
    blobStore.deleteContainer(CONTAINER_NAME);
    result = blobStore.containerExists(CONTAINER_NAME);
    assertFalse(result, "Container [" + CONTAINER_NAME + "] still exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
    result = blobStore.containerExists(CONTAINER_NAME2);
    assertTrue(result, "Container [" + CONTAINER_NAME2 + "] still exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
    // delete second container
    blobStore.deleteContainer(CONTAINER_NAME2);
    result = blobStore.containerExists(CONTAINER_NAME2);
    assertFalse(result, "Container [" + CONTAINER_NAME2 + "] still exists");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false);
  }
コード例 #11
0
  /**
   * Test of removeBlob method, with two blobs with a complex path as key and when first blob is
   * removed, not all of its key's path is removed, because it is shared with the second blob's key
   */
  @Test
  public void testRemoveBlob_TwoComplexBlobKeys() throws IOException {
    final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
    final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null);
    boolean result;

    blobStore.createContainerInLocation(null, CONTAINER_NAME);

    // checks that blob doesn't exist
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
    assertFalse(result, "Blob1 exists");
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
    assertFalse(result, "Blob2 exists");

    // create the blobs
    TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2);
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
    assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
    assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");

    // remove first blob
    blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
    assertFalse(result, "Blob still exists");
    // first file deleted, not the second
    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
    // only partial directory structure was removed, because it shares a path
    // with the second blob created
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb/cc/dd", false);
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb", true);
    // remove second blob
    blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
    result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
    assertFalse(result, "Blob still exists");
    TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
    // now all the directory structure is empty
    TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
  }
コード例 #12
0
  /** Test of createContainerInLocation method, of class FilesystemAsyncBlobStore. */
  public void testCreateContainerInLocation() throws IOException {
    final String CONTAINER_NAME2 = "funambol-test-2";
    final String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;

    boolean result;

    result = blobStore.containerExists(CONTAINER_NAME);
    assertFalse(result, "Container exists");
    result = blobStore.createContainerInLocation(null, CONTAINER_NAME);
    assertTrue(result, "Container not created");
    result = blobStore.containerExists(CONTAINER_NAME);
    assertTrue(result, "Container doesn't exist");
    TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);

    result = blobStore.containerExists(CONTAINER_NAME2);
    assertFalse(result, "Container exists");
    result = blobStore.createContainerInLocation(null, CONTAINER_NAME2);
    assertTrue(result, "Container not created");
    result = blobStore.containerExists(CONTAINER_NAME2);
    assertTrue(result, "Container doesn't exist");
    TestUtils.directoryExists(TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2, true);
  }