private boolean validateIOStreams(FileSystem fs, Path filePath) throws IOException { // Create and write a file OutputStream outputStream = fs.create(filePath); outputStream.write(new byte[FILE_SIZE]); outputStream.close(); // Return true if the the count is equivalent to the file size. return (FILE_SIZE == readInputStream(fs, filePath)); }
private int readInputStream(Path filePath) throws IOException { // Capture the file system from the test account. FileSystem fs = testAccount.getFileSystem(); return readInputStream(fs, filePath); }
@Test public void testConnectUsingAnonymous() throws Exception { // Create test account with anonymous credentials testAccount = AzureBlobStorageTestAccount.createAnonymous("testWasb.txt", FILE_SIZE); assumeNotNull(testAccount); // Read the file from the public folder using anonymous credentials. assertEquals(FILE_SIZE, readInputStream(new Path("/testWasb.txt"))); }
public void testConnectToRoot() throws Exception { // Set up blob names. final String blobPrefix = String.format("wasbtests-%s-%tQ-blob", System.getProperty("user.name"), new Date()); final String inblobName = blobPrefix + "_In" + ".txt"; final String outblobName = blobPrefix + "_Out" + ".txt"; // Create test account with default root access. testAccount = AzureBlobStorageTestAccount.createRoot(inblobName, FILE_SIZE); assumeNotNull(testAccount); // Read the file from the default container. assertEquals(FILE_SIZE, readInputStream(new Path(PATH_DELIMITER + inblobName))); try { // Capture file system. FileSystem fs = testAccount.getFileSystem(); // Create output path and open an output stream to the root folder. Path outputPath = new Path(PATH_DELIMITER + outblobName); OutputStream outputStream = fs.create(outputPath); fail("Expected an AzureException when writing to root folder."); outputStream.write(new byte[FILE_SIZE]); outputStream.close(); } catch (AzureException e) { assertTrue(true); } catch (Exception e) { String errMsg = String.format( "Expected AzureException but got %s instead.", e); assertTrue(errMsg, false); } }