@Override
    public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException {
        try {
            final BlobRequestOptions options = new BlobRequestOptions();
            if(containerService.isContainer(file)) {
                final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName());
                container.setMetadata(new HashMap<>(status.getMetadata()));
                container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context);
            }
            else {
                final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName())
                        .getBlobReferenceFromServer(containerService.getKey(file));
                // Populates the blob properties and metadata
                blob.downloadAttributes();
                // Replace metadata
                final HashMap<String, String> pruned = new HashMap<>();
                for(Map.Entry<String, String> m : status.getMetadata().entrySet()) {
                    final BlobProperties properties = blob.getProperties();
                    if(HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) {
                        // Update properties
                        properties.setCacheControl(m.getValue());
                        continue;
                    }
                    if(HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) {
                        // Update properties
                        properties.setContentType(m.getValue());
                        continue;
                    }
                    pruned.put(m.getKey(), m.getValue());
                }
                blob.setMetadata(pruned);
                blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context);
                blob.uploadProperties();
            }
        }
        catch(URISyntaxException e) {
            throw new NotfoundException(e.getMessage(), e);
        }
        catch(StorageException e) {
            throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
    }
@Test
    public void testSetMetadata() throws Exception {
        final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
        final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        new AzureTouchFeature(session, null).touch(test, new TransferStatus());
        final String v = new AlphanumericRandomStringService().random();
        new AzureMetadataFeature(session, null).setMetadata(test, Collections.singletonMap("Test", v));
        final Map<String, String> metadata = new AzureMetadataFeature(session, null).getMetadata(test);
        assertFalse(metadata.isEmpty());
        assertTrue(metadata.containsKey("Test"));
        assertEquals(v, metadata.get("Test"));
        new AzureDeleteFeature(session, null).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }