Search in sources :

Example 6 with BlobOutputStream

use of com.microsoft.azure.storage.blob.BlobOutputStream in project hadoop by apache.

the class TestContainerChecks method testContainerExistAfterDoesNotExist.

@Test
public void testContainerExistAfterDoesNotExist() throws Exception {
    testAccount = AzureBlobStorageTestAccount.create("", EnumSet.noneOf(CreateOptions.class));
    assumeNotNull(testAccount);
    CloudBlobContainer container = testAccount.getRealContainer();
    FileSystem fs = testAccount.getFileSystem();
    // Starting off with the container not there
    assertFalse(container.exists());
    // state to DoesNotExist
    try {
        fs.listStatus(new Path("/"));
        assertTrue("Should've thrown.", false);
    } catch (FileNotFoundException ex) {
        assertTrue("Unexpected exception: " + ex, ex.getMessage().contains("does not exist."));
    }
    assertFalse(container.exists());
    // Create a container outside of the WASB FileSystem
    container.create();
    // Add a file to the container outside of the WASB FileSystem
    CloudBlockBlob blob = testAccount.getBlobReference("foo");
    BlobOutputStream outputStream = blob.openOutputStream();
    outputStream.write(new byte[10]);
    outputStream.close();
    // Make sure the file is visible
    assertTrue(fs.exists(new Path("/foo")));
    assertTrue(container.exists());
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 7 with BlobOutputStream

use of com.microsoft.azure.storage.blob.BlobOutputStream in project hadoop by apache.

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_rename_rootLevelFiles.

// WASB must force explicit parent directories in create, delete, mkdirs, rename.
// scenario for this particular test described at MONARCH-HADOOP-764
@Test
public void outOfBandFolder_rename_rootLevelFiles() throws Exception {
    // NOTE: manual use of CloubBlockBlob targets working directory explicitly.
    // WASB driver methods prepend working directory implicitly.
    CloudBlockBlob blob = testAccount.getBlobReference("fileX");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    Path srcFilePath = new Path("/fileX");
    assertTrue(fs.exists(srcFilePath));
    Path destFilePath = new Path("/fileXrename");
    fs.rename(srcFilePath, destFilePath);
}
Also used : Path(org.apache.hadoop.fs.Path) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 8 with BlobOutputStream

use of com.microsoft.azure.storage.blob.BlobOutputStream in project hadoop by apache.

the class TestOutOfBandAzureBlobOperationsLive method outOfBandSingleFile_rename.

// Verify that you can rename a file which is the only file in an implicit folder in the
// WASB file system.
// scenario for this particular test described at MONARCH-HADOOP-892
@Test
public void outOfBandSingleFile_rename() throws Exception {
    //NOTE: manual use of CloubBlockBlob targets working directory explicitly.
    //       WASB driver methods prepend working directory implicitly.
    String workingDir = "user/" + UserGroupInformation.getCurrentUser().getShortUserName() + "/";
    CloudBlockBlob blob = testAccount.getBlobReference(workingDir + "testFolder5/a/input/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    Path srcFilePath = new Path("testFolder5/a/input/file");
    assertTrue(fs.exists(srcFilePath));
    Path destFilePath = new Path("testFolder5/file2");
    fs.rename(srcFilePath, destFilePath);
}
Also used : Path(org.apache.hadoop.fs.Path) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 9 with BlobOutputStream

use of com.microsoft.azure.storage.blob.BlobOutputStream in project hadoop by apache.

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_uncleMkdirs.

// scenario for this particular test described at MONARCH-HADOOP-764
// creating a file out-of-band would confuse mkdirs("<oobfilesUncleFolder>")
// eg oob creation of "user/<name>/testFolder/a/input/file"
// Then wasb creation of "user/<name>/testFolder/a/output" fails
@Test
public void outOfBandFolder_uncleMkdirs() throws Exception {
    // NOTE: manual use of CloubBlockBlob targets working directory explicitly.
    // WASB driver methods prepend working directory implicitly.
    String workingDir = "user/" + UserGroupInformation.getCurrentUser().getShortUserName() + "/";
    CloudBlockBlob blob = testAccount.getBlobReference(workingDir + "testFolder1/a/input/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    assertTrue(fs.exists(new Path("testFolder1/a/input/file")));
    Path targetFolder = new Path("testFolder1/a/output");
    assertTrue(fs.mkdirs(targetFolder));
}
Also used : Path(org.apache.hadoop.fs.Path) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Aggregations

BlobOutputStream (com.microsoft.azure.storage.blob.BlobOutputStream)9 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)9 Path (org.apache.hadoop.fs.Path)9 Test (org.junit.Test)9 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)1 FileNotFoundException (java.io.FileNotFoundException)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1