use of com.azure.storage.blob.models.BlobProperties in project ambry by linkedin.
the class AzureBlobDataAccessorTest method setupMockBlobClient.
static BlockBlobClient setupMockBlobClient(BlobServiceClient mockServiceClient) {
BlobContainerClient mockContainerClient = mock(BlobContainerClient.class);
BlobClient mockBlobClient = mock(BlobClient.class);
BlockBlobClient mockBlockBlobClient = mock(BlockBlobClient.class);
when(mockServiceClient.getBlobContainerClient(anyString())).thenReturn(mockContainerClient);
when(mockContainerClient.getBlobClient(anyString())).thenReturn(mockBlobClient);
when(mockContainerClient.exists()).thenReturn(false);
when(mockBlobClient.getBlockBlobClient()).thenReturn(mockBlockBlobClient);
// Rest is to mock getPropertiesWithResponse and not needed everywhere
BlobProperties mockBlobProperties = mock(BlobProperties.class);
Map<String, String> metadataMap = new HashMap<>();
lenient().when(mockBlobProperties.getMetadata()).thenReturn(metadataMap);
Response<BlobProperties> mockPropertiesResponse = mock(Response.class);
lenient().when(mockPropertiesResponse.getValue()).thenReturn(mockBlobProperties);
lenient().when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenReturn(mockPropertiesResponse);
return mockBlockBlobClient;
}
use of com.azure.storage.blob.models.BlobProperties in project ambry by linkedin.
the class AzureCloudDestinationTest method testGetOneMetadata.
/**
* Test to make sure that getting metadata for single blob calls ABS when not vcr and Cosmos when vcr.
*/
@Test
public void testGetOneMetadata() throws Exception {
//
// Test 1: isVcr = false (already setup)
//
// Get for existing blob
Response<BlobProperties> mockResponse = mock(Response.class);
BlobProperties mockProperties = mock(BlobProperties.class);
CloudBlobMetadata blobMetadata = new CloudBlobMetadata(blobId, 0, -1, 0, null);
Map<String, String> propertyMap = blobMetadata.toMap();
when(mockProperties.getMetadata()).thenReturn(propertyMap);
when(mockResponse.getValue()).thenReturn(mockProperties);
when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenReturn(mockResponse);
List<BlobId> singleBlobList = Collections.singletonList(blobId);
Map<String, CloudBlobMetadata> metadataMap = azureDest.getBlobMetadata(singleBlobList);
assertEquals("Expected map of one", 1, metadataMap.size());
verify(mockBlockBlobClient).getPropertiesWithResponse(any(), any(), any());
verifyZeroInteractions(mockumentClient);
// Get for nonexistent blob
BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND);
when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex);
metadataMap = azureDest.getBlobMetadata(singleBlobList);
assertTrue("Expected empty map", metadataMap.isEmpty());
verify(mockBlockBlobClient, times(2)).getPropertiesWithResponse(any(), any(), any());
verifyZeroInteractions(mockumentClient);
//
// Test 2: isVcr = true
//
azureDest.close();
azureDest = new AzureCloudDestination(mockServiceClient, mockBlobBatchClient, mockumentClient, "foo", "bar", clusterName, azureMetrics, defaultAzureReplicationFeedType, clusterMap, true, configProps);
// Existing blob
List<Document> docList = Collections.singletonList(createDocumentFromCloudBlobMetadata(blobMetadata));
Observable<FeedResponse<Document>> feedResponse = mock(Observable.class);
mockObservableForQuery(docList, feedResponse);
when(mockumentClient.queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class))).thenReturn(feedResponse);
metadataMap = azureDest.getBlobMetadata(singleBlobList);
assertEquals("Expected map of one", 1, metadataMap.size());
verify(mockumentClient).queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class));
verify(mockBlockBlobClient, times(2)).getPropertiesWithResponse(any(), any(), any());
}
use of com.azure.storage.blob.models.BlobProperties in project carina by qaprosoft.
the class CarinaListener method updateAzureAppPath.
/**
* Method to update MOBILE_APP path in case if apk is located in Azure storage.
*/
private static void updateAzureAppPath() {
Pattern AZURE_CONTAINER_PATTERN = Pattern.compile("\\/\\/([a-z0-9]{3,24})\\.blob.core.windows.net\\/(?:(\\$root|(?:[a-z0-9](?!.*--)[a-z0-9-]{1,61}[a-z0-9]))\\/)?(.{1,1024})");
String mobileAppPath = Configuration.getMobileApp();
Matcher matcher = AZURE_CONTAINER_PATTERN.matcher(mobileAppPath);
LOGGER.info("Analyzing if mobile app is located on Azure...");
if (matcher.find()) {
LOGGER.info("app artifact is located on Azure...");
String accountName = matcher.group(1);
String containerName = matcher.group(2) == null ? "$root" : matcher.group(2);
String remoteFilePath = matcher.group(3);
LOGGER.info("Account: " + accountName + "\n" + "Container: " + containerName + "\n" + "RemotePath: " + remoteFilePath + "\n");
R.CONFIG.put(Parameter.AZURE_ACCOUNT_NAME.getKey(), accountName);
BlobProperties blobProperties = AzureManager.getInstance().get(containerName, remoteFilePath);
String azureLocalStorage = Configuration.get(Parameter.AZURE_LOCAL_STORAGE);
String localFilePath = azureLocalStorage + File.separator + StringUtils.substringAfterLast(remoteFilePath, "/");
File file = new File(localFilePath);
try {
// verify requested artifact by checking the checksum
if (file.exists() && FileManager.getFileChecksum(FileManager.Checksum.MD5, file).equals(Base64.encodeBase64String(blobProperties.getContentMd5()))) {
LOGGER.info("build artifact with the same checksum already downloaded: " + file.getAbsolutePath());
} else {
LOGGER.info(String.format("Following data was extracted: container: %s, remotePath: %s, local file: %s", containerName, remoteFilePath, file.getAbsolutePath()));
AzureManager.getInstance().download(containerName, remoteFilePath, file);
}
} catch (Exception exception) {
LOGGER.error("Azure app path update exception detected!", exception);
}
Configuration.setMobileApp(file.getAbsolutePath());
// try to redefine app_version if it's value is latest or empty
String appVersion = Configuration.get(Parameter.APP_VERSION);
if (appVersion.equals("latest") || appVersion.isEmpty()) {
Configuration.setBuild(file.getName());
}
}
}
use of com.azure.storage.blob.models.BlobProperties in project carina by qaprosoft.
the class AzureClientTest method testGetPropsNull.
@Test(expectedExceptions = { RuntimeException.class, IOException.class, NoSuchAlgorithmException.class })
public void testGetPropsNull() throws IOException, NoSuchAlgorithmException {
String localPath = Configuration.get(Configuration.Parameter.AZURE_LOCAL_STORAGE);
BlobProperties value = AzureManager.getInstance().get("resources", "apk-StableDev.apk");
String remoteFileMD5 = Base64.encodeBase64String(value.getContentMd5());
File file = new File("./apk-StableDev.apk");
String localFileMD5 = FileManager.getFileChecksum(FileManager.Checksum.MD5, file);
System.out.println(remoteFileMD5);
System.out.println(localFileMD5);
System.out.println(remoteFileMD5.equals(localFileMD5));
Assert.fail("Key verification doesn't work!");
}
Aggregations