Search in sources :

Example 26 with CloudQueue

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

the class AzureStorageQueueService method retrieveMessages.

public Iterable<CloudQueueMessage> retrieveMessages(String queueName, int numberOfMessages) throws InvalidKeyException, URISyntaxException, StorageException {
    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.retrieveMessages(numberOfMessages);
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 27 with CloudQueue

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

the class AzureStorageQueueService method deleteQueueIfExists.

public boolean deleteQueueIfExists(String queueName) throws InvalidKeyException, URISyntaxException, StorageException {
    CloudQueueClient client = connection.getCloudStorageAccount().createCloudQueueClient();
    CloudQueue queueRef = client.getQueueReference(queueName);
    return queueRef.deleteIfExists();
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 28 with CloudQueue

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

the class AzureStorageQueueListReaderTest method testAdvanceAsNonAdvancable.

@Test
public void testAdvanceAsNonAdvancable() {
    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));
        when(queueService.listQueues()).thenReturn(new Iterable<CloudQueue>() {

            @Override
            public Iterator<CloudQueue> iterator() {
                return new DummyCloudQueueIterator(list);
            }
        });
        assertTrue(reader.start());
        assertFalse(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 29 with CloudQueue

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

the class AzureStorageQueueListReaderTest method testGetCurrent.

@Test
public void testGetCurrent() {
    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));
        when(queueService.listQueues()).thenReturn(new Iterable<CloudQueue>() {

            @Override
            public Iterator<CloudQueue> iterator() {
                return new DummyCloudQueueIterator(list);
            }
        });
        assertTrue(reader.start());
        IndexedRecord current = reader.getCurrent();
        assertNotNull(current);
        assertEquals("queue-1", current.get(0));
    } catch (InvalidKeyException | URISyntaxException | StorageException | IOException e) {
        fail("should not throw " + e.getMessage());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) 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 30 with CloudQueue

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

the class AzureStorageQueueListReaderTest method testGetReturnValues.

@Test
public void testGetReturnValues() {
    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));
        list.add(new CloudQueue(new URI("https://storagesample.queue.core.windows.net/queue-3"), dummyCredential));
        when(queueService.listQueues()).thenReturn(new Iterable<CloudQueue>() {

            @Override
            public Iterator<CloudQueue> iterator() {
                return new DummyCloudQueueIterator(list);
            }
        });
        assertTrue(reader.start());
        while (reader.advance()) {
        // read all records
        }
        Map<String, Object> returnedValues = reader.getReturnValues();
        assertNotNull(returnedValues);
        assertEquals(3, returnedValues.get(TAzureStorageQueueListDefinition.RETURN_NB_QUEUE));
    } 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)

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