private void checkCredentials(QueueServiceConfiguration cfg) { CloudQueue client = cfg.getAzureQueueClient(); StorageCredentials creds = client == null ? cfg.getCredentials() : client.getServiceClient().getCredentials(); if (creds == null) { throw new IllegalArgumentException("Credentials must be specified."); } } }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String queueName = this.getName(); return String.format("/%s/%s/%s", SR.QUEUE, accountName, queueName); }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String queueName = this.getName(); return String.format("/%s/%s/%s", SR.QUEUE, accountName, queueName); }
private void listQueues(Exchange exchange) throws Exception { CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration()); QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange); QueueListingDetails details = (QueueListingDetails)exchange.getIn().getHeader(QueueServiceConstants.QUEUE_LISTING_DETAILS); if (details == null) { details = QueueListingDetails.ALL; } Iterable<CloudQueue> list = client.getServiceClient().listQueues( getConfiguration().getQueuePrefix(), details, opts.getRequestOpts(), opts.getOpContext()); ExchangeUtil.getMessageForResponse(exchange).setBody(list); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadataClearExisting() throws URISyntaxException, StorageException { CloudQueue queueForGet = this.queue.getServiceClient().getQueueReference(this.queue.getName()); HashMap<String, String> metadata1 = new HashMap<String, String>(); String key = "ExistingMetadata1" + UUID.randomUUID().toString().replace("-", ""); metadata1.put(key, "ExistingMetadataValue1"); this.queue.setMetadata(metadata1); queueForGet.downloadAttributes(); assertFalse(queueForGet.getMetadata().containsKey(key)); HashMap<String, String> metadata2 = new HashMap<String, String>(); this.queue.setMetadata(metadata2); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().size() == 0); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadata() throws URISyntaxException, StorageException { CloudQueue queueForGet = this.queue.getServiceClient().getQueueReference(this.queue.getName()); HashMap<String, String> metadata1 = new HashMap<String, String>(); metadata1.put("ExistingMetadata1", "ExistingMetadataValue1"); this.queue.setMetadata(metadata1); queueForGet.downloadAttributes(); assertFalse(queueForGet.getMetadata().containsKey("ExistingMetadata1")); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().containsKey("ExistingMetadata1")); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadMetadataNullInput() throws URISyntaxException, StorageException { CloudQueue queueForGet = this.queue.getServiceClient().getQueueReference(this.queue.getName()); HashMap<String, String> metadata1 = new HashMap<String, String>(); String key = "ExistingMetadata1" + UUID.randomUUID().toString().replace("-", ""); metadata1.put(key, "ExistingMetadataValue1"); this.queue.setMetadata(metadata1); queueForGet.downloadAttributes(); assertFalse(queueForGet.getMetadata().containsKey(key)); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().containsKey(key)); this.queue.setMetadata(null); this.queue.uploadMetadata(); queueForGet.downloadAttributes(); assertTrue(queueForGet.getMetadata().size() == 0); }
@Test public void testQueueClientConstructor() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue1 = qClient.getQueueReference(queueName); assertEquals(queueName, queue1.getName()); assertTrue(queue1.getUri().toString().endsWith(queueName)); assertEquals(qClient, queue1.getServiceClient()); CloudQueue queue2 = new CloudQueue(new URI(QueueTestHelper.appendQueueName(qClient.getEndpoint(), queueName)), qClient.getCredentials()); assertEquals(queueName, queue2.getName()); assertEquals(qClient.getCredentials(), queue2.getServiceClient().getCredentials()); }
@Test public void testQueueTypesWithStorageUri() throws URISyntaxException, StorageException { CloudQueueClient queueClient = TestHelper.createCloudQueueClient(); StorageUri endpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); CloudQueueClient client = new CloudQueueClient(endpoint, queueClient.getCredentials()); assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint()); StorageUri queueUri = new StorageUri(new URI(endpoint.getPrimaryUri() + "/queue"), new URI( endpoint.getSecondaryUri() + "/queue")); CloudQueue queue = client.getQueueReference("queue"); assertEquals(queueUri, queue.getStorageUri()); assertEquals(queueUri.getPrimaryUri(), queue.getUri()); assertEquals(endpoint, queue.getServiceClient().getStorageUri()); queue = new CloudQueue(queueUri, client.getCredentials()); assertEquals(queueUri, queue.getStorageUri()); assertEquals(queueUri.getPrimaryUri(), queue.getUri()); assertEquals(endpoint, queue.getServiceClient().getStorageUri()); }
private static void testQueueDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudQueueClient client = TestHelper.createCloudQueueClient(); CloudQueue queue = client.getQueueReference(QueueTestHelper.generateRandomQueueName()); MultiLocationTestHelper helper = new MultiLocationTestHelper(queue.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); queue.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); QueueRequestOptions options = new QueueRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { queue.downloadAttributes(options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } }
assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient() .getCredentials().getClass().toString()); CloudQueueClient queueClient = policySasQueue.getServiceClient(); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), queueFromUri.getServiceClient() .getCredentials().getClass().toString());