private Map<String, Long> getSnapshotFileKeys(CloudBlobContainer container, String keyPrefix) { Map<String, Long> snapshotFiles = new HashMap<>(); try { for (ListBlobItem item : container.listBlobs(keyPrefix, true)) { if (item instanceof CloudPageBlob) { CloudPageBlob cloudBlob = (CloudPageBlob) item; snapshotFiles.put(cloudBlob.getName(), getOriginalFileSize(cloudBlob)); } } } catch (StorageException e) { logger.error("Unable to retrieve metadata.", e); // all or none snapshotFiles = new HashMap<>(); } return snapshotFiles; }
/** * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test public void testPageBlobNamePlusEncodingTest() throws StorageException, URISyntaxException, IOException, InterruptedException { final int length = 1 * 1024; final CloudPageBlob originalBlob = (CloudPageBlob) BlobTestHelper.uploadNewBlob(this.container, BlobType.PAGE_BLOB, "a+b.txt", length, null); final CloudPageBlob copyBlob = this.container.getPageBlobReference(originalBlob.getName() + "copyed"); copyBlob.startCopy(originalBlob); BlobTestHelper.waitForCopy(copyBlob); copyBlob.downloadAttributes(); }
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference("copy"); CloudPageBlob blob = (CloudPageBlob) blobItem; if (blob.getName().equals("copy") && blob.isSnapshot()) { incrementalCopyFound = true; else if (blob.getName().equals("copy")) { assertNotNull(blob.getCopyState().getCopyDestinationSnapshotID());
/** * Start copying a blob and then abort * * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test public void testCopyFromPageBlobAbortTest() throws StorageException, URISyntaxException, IOException { final int length = 512; CloudPageBlob originalBlob = (CloudPageBlob) BlobTestHelper.uploadNewBlob( this.container, BlobType.PAGE_BLOB, "originalBlob", length, null); CloudPageBlob copyBlob = this.container.getPageBlobReference(originalBlob.getName() + "copyed"); copyBlob.startCopy(originalBlob); try { copyBlob.abortCopy(copyBlob.getProperties().getCopyState().getCopyId()); } catch (StorageException e) { if (!e.getErrorCode().contains("NoPendingCopyOperation")) { throw e; } } }
final CloudPageBlob blobSnapshotUsingRootUri = this.container.getPageBlobReference(blockBlobRef.getName(), blobSnapshot.getSnapshotID()); outStream = new ByteArrayOutputStream(length);
private void testGetParent(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { CloudPageBlob blob = container.getPageBlobReference("Dir1" + delimiter + "Blob1"); blob.create(0); try { assertTrue(blob.exists()); assertEquals(blob.getName(), "Dir1" + delimiter + "Blob1"); CloudBlobDirectory parent = blob.getParent(); assertEquals("Dir1" + delimiter, parent.getPrefix()); } finally { blob.deleteIfExists(); } }
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference(BlobTestHelper.generateRandomBlobNameWithPrefix("copy"));
assertEquals(dir1.getServiceClient().getEndpoint().toString(), pageBlob.getServiceClient().getEndpoint() .toString()); assertEquals("Dir1" + delimiter + "PageBlob", pageBlob.getName()); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/Dir1" + delimiter + "PageBlob", null, null), pageBlob.getUri()); assertEquals(pageSnapshot.getName(), pageSnapshotDir1.getName()); assertEquals(dir1.getContainer().getName(), pageSnapshotDir1.getContainer().getName()); assertEquals(dir1.getServiceClient().getEndpoint().toString(), pageSnapshotDir1.getServiceClient()
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();
private void testDelimitersInARow(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { CloudPageBlob blob = container.getPageBlobReference(delimiter + delimiter + delimiter + "Blob1"); // Traverse from leaf to root CloudBlobDirectory directory1 = blob.getParent(); assertEquals(delimiter + delimiter + delimiter, directory1.getPrefix()); CloudBlobDirectory directory2 = directory1.getParent(); assertEquals(delimiter + delimiter, directory2.getPrefix()); CloudBlobDirectory directory3 = directory2.getParent(); assertEquals(delimiter, directory3.getPrefix()); // Traverse from root to leaf CloudBlobDirectory directory4 = container.getDirectoryReference(delimiter); CloudBlobDirectory directory5 = directory4.getDirectoryReference(delimiter); assertEquals(delimiter + delimiter, directory5.getPrefix()); CloudBlobDirectory directory6 = directory5.getDirectoryReference(delimiter); assertEquals(delimiter + delimiter + delimiter, directory6.getPrefix()); CloudPageBlob blob2 = directory6.getPageBlobReference("Blob1"); assertEquals(delimiter + delimiter + delimiter + "Blob1", blob2.getName()); assertEquals(blob.getUri(), blob2.getUri()); }