/** * Downloads the queue's metadata and approximate message count value. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public void downloadAttributes() throws StorageException { this.downloadAttributes(null /* options */, null /* opContext */); }
/** * Downloads the queue's metadata and approximate message count value. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public void downloadAttributes() throws StorageException { this.downloadAttributes(null /* options */, null /* opContext */); }
@Override public long getLength() { try { // Download the approximate message count from the server. _queue.downloadAttributes(); // Retrieve the newly cached approximate message count. return _queue.getApproximateMessageCount(); } catch (Exception e) { e.printStackTrace(); return -1; } }
@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 @Category({ DevFabricTests.class, DevStoreTests.class }) public void testGetMetadata() throws StorageException { HashMap<String, String> metadata = new HashMap<String, String>(); metadata.put("ExistingMetadata", "ExistingMetadataValue"); this.queue.setMetadata(metadata); this.queue.uploadMetadata(); this.queue.downloadAttributes(); assertEquals(this.queue.getMetadata().get("ExistingMetadata"), "ExistingMetadataValue"); assertTrue(this.queue.getMetadata().containsKey("ExistingMetadata")); HashMap<String, String> empytMetadata = null; this.queue.setMetadata(empytMetadata); this.queue.uploadMetadata(); this.queue.downloadAttributes(); assertTrue(this.queue.getMetadata().size() == 0); }
@NotNull public Queue createQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException { try { CloudQueueClient client = getCloudQueueClient(storageAccount); CloudQueue cloudQueue = client.getQueueReference(queue.getName()); cloudQueue.createIfNotExists(); cloudQueue.downloadAttributes(); String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : ""; long approximateMessageCount = cloudQueue.getApproximateMessageCount(); queue.setUri(uri); queue.setApproximateMessageCount(approximateMessageCount); return queue; } catch (Throwable t) { throw new AzureCmdException("Error creating the Queue", t); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueDownloadAttributesNotFound() throws StorageException, URISyntaxException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); try { queue.downloadAttributes(); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueDownloadAttributes() throws StorageException, URISyntaxException { final CloudQueueMessage message1 = new CloudQueueMessage("messagetest1"); this.queue.addMessage(message1); final CloudQueueMessage message2 = new CloudQueueMessage("messagetest2"); this.queue.addMessage(message2); final HashMap<String, String> metadata = new HashMap<String, String>(5); int sum = 5; for (int i = 0; i < sum; i++) { metadata.put("key" + i, "value" + i); } this.queue.setMetadata(metadata); this.queue.uploadMetadata(); CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final CloudQueue queue2 = qClient.getQueueReference(this.queue.getName()); queue2.downloadAttributes(); assertEquals(sum, queue2.getMetadata().size()); }
this.queue.generateSharedAccessSignature(null, identifier))); identifierSasQueue.downloadAttributes(); identifierSasQueue.exists(); this.queue.generateSharedAccessSignature(policy1, null))); policySasQueue.exists(); policySasQueue.downloadAttributes();
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testGetApproximateMessageCount() throws StorageException { assertTrue(this.queue.getApproximateMessageCount() == 0); this.queue.addMessage(new CloudQueueMessage("message1")); this.queue.addMessage(new CloudQueueMessage("message2")); assertTrue(this.queue.getApproximateMessageCount() == 0); this.queue.downloadAttributes(); assertTrue(this.queue.getApproximateMessageCount() == 2); this.queue.delete(); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreate() throws URISyntaxException, StorageException { CloudQueue queue = QueueTestHelper.getRandomQueueReference(); OperationContext createQueueContext = new OperationContext(); try { queue.create(null, createQueueContext); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); try { HashMap<String, String> metadata1 = new HashMap<String, String>(); metadata1.put("ExistingMetadata1", "ExistingMetadataValue1"); queue.setMetadata(metadata1); queue.create(); fail(); } catch (StorageException e) { assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT); } queue.downloadAttributes(); OperationContext createQueueContext2 = new OperationContext(); queue.create(null, createQueueContext2); assertEquals(createQueueContext2.getLastResult().getStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } finally { queue.delete(); } }
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(); } }
queue.downloadAttributes(); assertEquals(value, queue.getMetadata().get(key));
@Test @Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class }) public void testQueueMaximumExecutionTime() throws URISyntaxException, StorageException { OperationContext opContext = new OperationContext(); setDelay(opContext, 2500); // set the maximum execution time QueueRequestOptions options = new QueueRequestOptions(); options.setMaximumExecutionTimeInMs(2000); // set the location mode to secondary, secondary request should fail // so set the timeout low to save time failing (or fail with a timeout) options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); options.setTimeoutIntervalInMs(1000); CloudQueueClient queueClient = TestHelper.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference(generateRandomName("queue")); try { // 1. download attributes will fail as the queue does not exist // 2. the executor will attempt to retry as it is accessing secondary // 3. maximum execution time should prevent the retry from being made queue.downloadAttributes(options, opContext); fail("Maximum execution time was reached but request did not fail."); } catch (StorageException e) { assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext = new OperationContext(); queue.create(null, createQueueContext); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); OperationContext deleteQueueContext = new OperationContext(); queue.delete(null, deleteQueueContext); assertEquals(deleteQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); try { queue.downloadAttributes(); fail(); } catch (StorageException ex) { assertEquals("Expected 404 Exception", ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } } finally { queue.deleteIfExists(); } }