use of com.microsoft.azure.storage.blob.CloudBlockBlob in project hadoop by apache.
the class TestBlobDataValidation method testStoreBlobMd5.
private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception {
assumeNotNull(testAccount);
// Write a test file.
String testFileKey = "testFile";
Path testFilePath = new Path("/" + testFileKey);
OutputStream outStream = testAccount.getFileSystem().create(testFilePath);
outStream.write(new byte[] { 5, 15 });
outStream.close();
// Check that we stored/didn't store the MD5 field as configured.
CloudBlockBlob blob = testAccount.getBlobReference(testFileKey);
blob.downloadAttributes();
String obtainedMd5 = blob.getProperties().getContentMD5();
if (expectMd5Stored) {
assertNotNull(obtainedMd5);
} else {
assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5);
}
// Mess with the content so it doesn't match the MD5.
String newBlockId = Base64.encode(new byte[] { 55, 44, 33, 22 });
blob.uploadBlock(newBlockId, new ByteArrayInputStream(new byte[] { 6, 45 }), 2);
blob.commitBlockList(Arrays.asList(new BlockEntry[] { new BlockEntry(newBlockId, BlockSearchMode.UNCOMMITTED) }));
// Now read back the content. If we stored the MD5 for the blob content
// we should get a data corruption error.
InputStream inStream = testAccount.getFileSystem().open(testFilePath);
try {
byte[] inBuf = new byte[100];
while (inStream.read(inBuf) > 0) {
//nothing;
}
inStream.close();
if (expectMd5Stored) {
fail("Should've thrown because of data corruption.");
}
} catch (IOException ex) {
if (!expectMd5Stored) {
throw ex;
}
StorageException cause = (StorageException) ex.getCause();
assertNotNull(cause);
assertTrue("Unexpected cause: " + cause, cause.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MD5));
}
}
use of com.microsoft.azure.storage.blob.CloudBlockBlob in project hadoop by apache.
the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_rootFileDelete.
@Test
public void outOfBandFolder_rootFileDelete() throws Exception {
CloudBlockBlob blob = testAccount.getBlobReference("fileY");
BlobOutputStream s = blob.openOutputStream();
s.close();
assertTrue(fs.exists(new Path("/fileY")));
assertTrue(fs.delete(new Path("/fileY"), true));
}
use of com.microsoft.azure.storage.blob.CloudBlockBlob in project hadoop by apache.
the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_parentDelete.
// scenario for this particular test described at MONARCH-HADOOP-764
@Test
public void outOfBandFolder_parentDelete() 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 + "testFolder2/a/input/file");
BlobOutputStream s = blob.openOutputStream();
s.close();
assertTrue(fs.exists(new Path("testFolder2/a/input/file")));
Path targetFolder = new Path("testFolder2/a/input");
assertTrue(fs.delete(targetFolder, true));
}
use of com.microsoft.azure.storage.blob.CloudBlockBlob 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());
}
use of com.microsoft.azure.storage.blob.CloudBlockBlob in project elasticsearch by elastic.
the class AzureStorageServiceImpl method getOutputStream.
@Override
public OutputStream getOutputStream(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
logger.trace("writing container [{}], blob [{}]", container, blob);
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlockBlob blockBlobReference = client.getContainerReference(container).getBlockBlobReference(blob);
return SocketAccess.doPrivilegedException(blockBlobReference::openOutputStream);
}
Aggregations