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());
}
}
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());
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations