use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputReaderTest method testAdvanceAsNonAdvancable.
@Test
public void testAdvanceAsNonAdvancable() {
try {
properties.peekMessages.setValue(true);
properties.deleteMessages.setValue(true);
AzureStorageQueueSource source = new AzureStorageQueueSource();
ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
assertNotNull(vr);
assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
reader = (AzureStorageQueueInputReader) source.createReader(getDummyRuntimeContiner());
// inject mocked service
reader.queueService = queueService;
final List<CloudQueueMessage> messages = new ArrayList<>();
messages.add(new CloudQueueMessage("message-1"));
when(queueService.peekMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {
@Override
public Iterator<CloudQueueMessage> iterator() {
return new DummyCloudQueueMessageIterator(messages);
}
});
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
throw new StorageException("code", "message-1 can't be deleted", new RuntimeException());
}
}).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));
boolean startable = reader.start();
assertTrue(startable);
boolean advancable = reader.advance();
assertFalse(advancable);
} catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
fail("sould not throw " + e.getMessage());
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputLoopReaderTest method testStartAsStartable.
@Test
public void testStartAsStartable() {
try {
AzureStorageQueueSource source = new AzureStorageQueueSource();
ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
assertNotNull(vr);
assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
reader = (AzureStorageQueueInputLoopReader) source.createReader(getDummyRuntimeContiner());
// inject mocked service
reader.queueService = queueService;
final List<CloudQueueMessage> messages = new ArrayList<>();
messages.add(new CloudQueueMessage("message-1"));
when(queueService.retrieveMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {
@Override
public Iterator<CloudQueueMessage> iterator() {
return new DummyCloudQueueMessageIterator(messages);
}
});
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));
boolean startable = reader.start();
assertTrue(startable);
} catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
fail("sould not throw " + e.getMessage());
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputLoopReaderTest method testGetReturnValues.
@Test
public void testGetReturnValues() {
try {
AzureStorageQueueSource source = new AzureStorageQueueSource();
ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
assertNotNull(vr);
assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
reader = (AzureStorageQueueInputLoopReader) source.createReader(getDummyRuntimeContiner());
// inject mocked service
reader.queueService = queueService;
final List<CloudQueueMessage> messages = new ArrayList<>();
messages.add(new CloudQueueMessage("message-1"));
messages.add(new CloudQueueMessage("message-2"));
messages.add(new CloudQueueMessage("message-3"));
when(queueService.retrieveMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {
@Override
public Iterator<CloudQueueMessage> iterator() {
return new DummyCloudQueueMessageIterator(messages);
}
});
boolean startable = reader.start();
assertTrue(startable);
int i = 1;
while (reader.advance()) {
// read all messages to init the returned values at the end
i++;
if (i == 3) {
break;
}
}
Map<String, Object> returnedValues = reader.getReturnValues();
assertNotNull(returnedValues);
assertEquals("some-queue-name", returnedValues.get(AzureStorageQueueDefinition.RETURN_QUEUE_NAME));
assertEquals(3, returnedValues.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
} catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
fail("sould not throw " + e.getMessage());
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputLoopReaderTest method testAdvanceAsAdvancable.
@Test
public void testAdvanceAsAdvancable() {
try {
AzureStorageQueueSource source = new AzureStorageQueueSource();
ValidationResult vr = source.initialize(getDummyRuntimeContiner(), properties);
assertNotNull(vr);
assertEquals(ValidationResult.OK.getStatus(), vr.getStatus());
reader = (AzureStorageQueueInputLoopReader) source.createReader(getDummyRuntimeContiner());
// inject mocked service
reader.queueService = queueService;
final List<CloudQueueMessage> messages = new ArrayList<>();
messages.add(new CloudQueueMessage("message-1"));
messages.add(new CloudQueueMessage("message-2"));
messages.add(new CloudQueueMessage("message-3"));
when(queueService.retrieveMessages(anyString(), anyInt())).thenReturn(new Iterable<CloudQueueMessage>() {
@Override
public Iterator<CloudQueueMessage> iterator() {
return new DummyCloudQueueMessageIterator(messages);
}
});
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(queueService).deleteMessage(anyString(), any(CloudQueueMessage.class));
boolean startable = reader.start();
assertTrue(startable);
boolean advancable = reader.advance();
assertTrue(advancable);
} catch (IOException | InvalidKeyException | URISyntaxException | StorageException e) {
fail("sould not throw " + e.getMessage());
}
}
use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueOutputWriterTestIT method testWriteSimpleMessage.
@Test
public void testWriteSimpleMessage() throws Throwable {
queue.clear();
//
TAzureStorageQueueOutputProperties properties = new TAzureStorageQueueOutputProperties("tests");
properties = (TAzureStorageQueueOutputProperties) setupConnectionProperties((AzureStorageProvideConnectionProperties) properties);
properties.setupProperties();
properties.queueName.setValue(TEST_QUEUE_NAME);
Writer<?> writer = createWriter(properties);
writer.open("test-uid");
for (String m : messages) {
IndexedRecord entity = new GenericData.Record(properties.schema.schema.getValue());
entity.put(0, m + "SIMPLE");
writer.write(entity);
}
writer.close();
queue.downloadAttributes();
assertEquals(3, queue.getApproximateMessageCount());
for (CloudQueueMessage msg : queue.retrieveMessages(3)) {
assertNotNull(msg.getMessageContentAsString());
assertTrue(msg.getMessageContentAsString().indexOf("SIMPLE") > 0);
}
}
Aggregations