Search in sources :

Example 31 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project components by Talend.

the class AzureStorageQueueListReaderTest method testStartAsNonStartable.

@Test
public void testStartAsNonStartable() {
    AzureStorageQueueSource source = new AzureStorageQueueSource();
    ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
    assertNotNull(vr);
    assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
    reader = (AzureStorageQueueListReader) source.createReader(getDummyRuntimeContiner());
    reader.queueService = queueService;
    final List<CloudQueue> list = new ArrayList<>();
    try {
        when(queueService.listQueues()).thenReturn(new Iterable<CloudQueue>() {

            @Override
            public Iterator<CloudQueue> iterator() {
                return new DummyCloudQueueIterator(list);
            }
        });
        assertFalse(reader.start());
    } catch (InvalidKeyException | URISyntaxException | IOException e) {
        fail("should not throw " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ValidationResult(org.talend.daikon.properties.ValidationResult) InvalidKeyException(java.security.InvalidKeyException) Iterator(java.util.Iterator) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) AzureBaseTest(org.talend.components.azurestorage.AzureBaseTest) Test(org.junit.Test)

Example 32 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project components by Talend.

the class AzureStorageQueueListReaderTest method testAdvanceAsAdvancable.

@Test
public void testAdvanceAsAdvancable() {
    AzureStorageQueueSource source = new AzureStorageQueueSource();
    ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
    assertNotNull(vr);
    assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
    reader = (AzureStorageQueueListReader) source.createReader(getDummyRuntimeContiner());
    reader.queueService = queueService;
    final List<CloudQueue> list = new ArrayList<>();
    try {
        list.add(new CloudQueue(new URI("https://storagesample.queue.core.windows.net/queue-1"), dummyCredential));
        list.add(new CloudQueue(new URI("https://storagesample.queue.core.windows.net/queue-2"), dummyCredential));
        when(queueService.listQueues()).thenReturn(new Iterable<CloudQueue>() {

            @Override
            public Iterator<CloudQueue> iterator() {
                return new DummyCloudQueueIterator(list);
            }
        });
        assertTrue(reader.start());
        assertTrue(reader.advance());
    } catch (InvalidKeyException | URISyntaxException | StorageException | IOException e) {
        fail("should not throw " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ValidationResult(org.talend.daikon.properties.ValidationResult) InvalidKeyException(java.security.InvalidKeyException) URI(java.net.URI) Iterator(java.util.Iterator) StorageException(com.microsoft.azure.storage.StorageException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) AzureBaseTest(org.talend.components.azurestorage.AzureBaseTest) Test(org.junit.Test)

Example 33 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project components by Talend.

the class AzureStorageQueueListReaderTest method testGetCurrentWhenNotStartable.

@Test(expected = NoSuchElementException.class)
public void testGetCurrentWhenNotStartable() {
    AzureStorageQueueSource source = new AzureStorageQueueSource();
    ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
    assertNotNull(vr);
    assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
    reader = (AzureStorageQueueListReader) source.createReader(getDummyRuntimeContiner());
    reader.queueService = queueService;
    final List<CloudQueue> list = new ArrayList<>();
    try {
        when(queueService.listQueues()).thenReturn(new Iterable<CloudQueue>() {

            @Override
            public Iterator<CloudQueue> iterator() {
                return new DummyCloudQueueIterator(list);
            }
        });
        assertFalse(reader.start());
        reader.getCurrent();
    } catch (InvalidKeyException | URISyntaxException | IOException e) {
        fail("should not throw " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ValidationResult(org.talend.daikon.properties.ValidationResult) InvalidKeyException(java.security.InvalidKeyException) Iterator(java.util.Iterator) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) AzureBaseTest(org.talend.components.azurestorage.AzureBaseTest) Test(org.junit.Test)

Example 34 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getQueueMessages.

@NotNull
public List<QueueMessage> getQueueMessages(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
    List<QueueMessage> qmList = new ArrayList<QueueMessage>();
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        String queueName = queue.getName();
        CloudQueue cloudQueue = client.getQueueReference(queueName);
        for (CloudQueueMessage cqm : cloudQueue.peekMessages(32)) {
            String id = Strings.nullToEmpty(cqm.getId());
            String content = Strings.nullToEmpty(cqm.getMessageContentAsString());
            Calendar insertionTime = new GregorianCalendar();
            if (cqm.getInsertionTime() != null) {
                insertionTime.setTime(cqm.getInsertionTime());
            }
            Calendar expirationTime = new GregorianCalendar();
            if (cqm.getExpirationTime() != null) {
                expirationTime.setTime(cqm.getExpirationTime());
            }
            int dequeueCount = cqm.getDequeueCount();
            qmList.add(new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount));
        }
        return qmList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Queue Message list", t);
    }
}
Also used : QueueMessage(com.microsoft.tooling.msservices.model.storage.QueueMessage) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 35 with CloudQueue

use of com.microsoft.azure.storage.queue.CloudQueue in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getQueues.

@NotNull
public List<Queue> getQueues(@NotNull StorageAccount storageAccount) throws AzureCmdException {
    List<Queue> qList = new ArrayList<Queue>();
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        for (CloudQueue cloudQueue : client.listQueues(null, QueueListingDetails.ALL, null, null)) {
            String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
            qList.add(new Queue(Strings.nullToEmpty(cloudQueue.getName()), uri, cloudQueue.getApproximateMessageCount()));
        }
        return qList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Queue list", t);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Queue(com.microsoft.tooling.msservices.model.storage.Queue) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)37 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)14 Test (org.junit.Test)13 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)9 IOException (java.io.IOException)9 URISyntaxException (java.net.URISyntaxException)9 InvalidKeyException (java.security.InvalidKeyException)9 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)9 AzureBaseTest (org.talend.components.azurestorage.AzureBaseTest)9 ValidationResult (org.talend.daikon.properties.ValidationResult)9 StorageException (com.microsoft.azure.storage.StorageException)7 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)7 URI (java.net.URI)7 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)4 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)3 JndiRegistry (org.apache.camel.impl.JndiRegistry)3 QueueMessage (com.microsoft.tooling.msservices.model.storage.QueueMessage)2 MessageUpdateFields (com.microsoft.azure.storage.queue.MessageUpdateFields)1 QueueListingDetails (com.microsoft.azure.storage.queue.QueueListingDetails)1