use of com.microsoft.azure.storage.queue.CloudQueueMessage in project components by Talend.
the class AzureStorageQueueInputReaderTest method testStartPeekHandleDeletionError.
@Test
public void testStartPeekHandleDeletionError() {
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);
} 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 AzureStorageQueueInputReaderTest method testGetCurrentWhenNotAdvancable.
@Test(expected = NoSuchElementException.class)
public void testGetCurrentWhenNotAdvancable() {
try {
properties.peekMessages.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);
}
});
boolean startable = reader.start();
assertTrue(startable);
assertNotNull(reader.getCurrent());
boolean advancable = reader.advance();
assertFalse(advancable);
// should throw NoSuchElementException
reader.getCurrent();
} 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 AzureStorageQueueInputReaderTest method testAdvanceWhenNonStartble.
@Test
public void testAdvanceWhenNonStartble() {
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<>();
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();
assertFalse(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 AzureStorageQueueInputReaderTest method testStartPeekAndDeleteMessage.
@Test
public void testStartPeekAndDeleteMessage() {
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 {
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 AzureStorageQueueInputReaderTest method testAdvanceWithMessageDeletion.
@Test
public void testAdvanceWithMessageDeletion() {
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"));
messages.add(new CloudQueueMessage("message-2"));
messages.add(new CloudQueueMessage("message-3"));
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 {
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());
}
}
Aggregations