use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class TestEvent method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(testWorkflowDefinition);
Task task = new Task();
task.getInputData().put("sink", "conductor");
task.setReferenceTaskName("task0");
task.setTaskId("task_id_0");
QueueDAO dao = mock(QueueDAO.class);
String[] publishedQueue = new String[1];
List<Message> publishedMessages = new LinkedList<>();
doAnswer((Answer<Void>) invocation -> {
String queueName = invocation.getArgument(0, String.class);
System.out.println(queueName);
publishedQueue[0] = queueName;
List<Message> messages = invocation.getArgument(1, List.class);
publishedMessages.addAll(messages);
return null;
}).when(dao).push(any(), any());
doAnswer((Answer<Boolean>) invocation -> {
String messageId = invocation.getArgument(1, String.class);
if (publishedMessages.get(0).getId().equals(messageId)) {
publishedMessages.remove(0);
return true;
}
return null;
}).when(dao).ack(any(), any());
Map<String, EventQueueProvider> providers = new HashMap<>();
providers.put("conductor", new DynoEventQueueProvider(dao, new TestConfiguration(), Schedulers.from(Executors.newSingleThreadExecutor())));
eventQueues = new EventQueues(providers, parametersUtils);
Event event = new Event(eventQueues, parametersUtils, objectMapper);
event.start(workflow, task, null);
assertEquals(Task.Status.COMPLETED, task.getStatus());
assertNotNull(task.getOutputData());
assertEquals("conductor:" + workflow.getWorkflowName() + ":" + task.getReferenceTaskName(), task.getOutputData().get("event_produced"));
assertEquals(task.getOutputData().get("event_produced"), "conductor:" + publishedQueue[0]);
assertEquals(1, publishedMessages.size());
assertEquals(task.getTaskId(), publishedMessages.get(0).getId());
assertNotNull(publishedMessages.get(0).getPayload());
event.cancel(workflow, task, null);
assertTrue(publishedMessages.isEmpty());
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class TestElasticSearchRestDAOV7 method shouldAddMessage.
@Test
public void shouldAddMessage() {
String queue = "queue";
Message message1 = new Message(uuid(), "payload1", null);
Message message2 = new Message(uuid(), "payload2", null);
indexDAO.addMessage(queue, message1);
indexDAO.addMessage(queue, message2);
List<Message> indexedMessages = tryFindResults(() -> indexDAO.getMessages(queue), 2);
assertEquals(2, indexedMessages.size());
assertTrue("Not all messages was indexed", indexedMessages.containsAll(Arrays.asList(message1, message2)));
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class TestSimpleEventProcessor method setup.
@Before
public void setup() {
event = "sqs:arn:account090:sqstest1";
queueURI = "arn:account090:sqstest1";
metadataService = mock(MetadataService.class);
executionService = mock(ExecutionService.class);
workflowExecutor = mock(WorkflowExecutor.class);
actionProcessor = mock(SimpleActionProcessor.class);
parametersUtils = new ParametersUtils();
jsonUtils = new JsonUtils();
EventQueueProvider provider = mock(EventQueueProvider.class);
queue = mock(ObservableQueue.class);
Message[] messages = new Message[1];
messages[0] = new Message("t0", "{\"Type\":\"Notification\",\"MessageId\":\"7e4e6415-01e9-5caf-abaa-37fd05d446ff\",\"Message\":\"{\\n \\\"testKey1\\\": \\\"level1\\\",\\n \\\"metadata\\\": {\\n \\\"testKey2\\\": 123456 }\\n }\",\"Timestamp\":\"2018-08-10T21:22:05.029Z\",\"SignatureVersion\":\"1\"}", "t0");
Observable<Message> msgObservable = Observable.from(messages);
when(queue.observe()).thenReturn(msgObservable);
when(queue.getURI()).thenReturn(queueURI);
when(queue.getName()).thenReturn(queueURI);
when(queue.getType()).thenReturn("sqs");
when(provider.getQueue(queueURI)).thenReturn(queue);
Map<String, EventQueueProvider> providers = new HashMap<>();
providers.put("sqs", provider);
eventQueues = new EventQueues(providers, parametersUtils);
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class ElasticSearchRestDAOV6 method mapGetMessagesResponse.
private List<Message> mapGetMessagesResponse(SearchResponse response) throws IOException {
SearchHit[] hits = response.getHits().getHits();
TypeFactory factory = TypeFactory.defaultInstance();
MapType type = factory.constructMapType(HashMap.class, String.class, String.class);
List<Message> messages = new ArrayList<>(hits.length);
for (SearchHit hit : hits) {
String source = hit.getSourceAsString();
Map<String, String> mapSource = objectMapper.readValue(source, type);
Message msg = new Message(mapSource.get("messageId"), mapSource.get("payload"), null);
messages.add(msg);
}
return messages;
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class TestElasticSearchRestDAOV5 method addMessage.
@Test
public void addMessage() {
String messageId = "some-message-id";
Message message = new Message();
message.setId(messageId);
message.setPayload("some-payload");
message.setReceipt("some-receipt");
indexDAO.addMessage("some-queue", message);
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
SearchResponse searchResponse = searchObjectIdsViaExpression(LOG_INDEX_PREFIX + "*", "messageId='" + messageId + "'", 0, 10000, null, "*", MSG_DOC_TYPE);
assertTrue("should return 1 or more search results", searchResponse.getHits().getTotalHits() > 0);
SearchHit searchHit = searchResponse.getHits().getAt(0);
String resourcePath = String.format("/%s/%s/%s", searchHit.getIndex(), MSG_DOC_TYPE, searchHit.getId());
Response response = restClient.performRequest(HttpMethod.GET, resourcePath);
String responseBody = IOUtils.toString(response.getEntity().getContent());
logger.info("responseBody: {}", responseBody);
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
};
Map<String, Object> responseMap = objectMapper.readValue(responseBody, typeRef);
Map<String, Object> source = (Map<String, Object>) responseMap.get("_source");
assertEquals("indexed message id should match", messageId, source.get("messageId"));
assertEquals("indexed payload should match", "some-payload", source.get("payload"));
});
List<Message> messages = indexDAO.getMessages("some-queue");
assertEquals(1, messages.size());
assertEquals(message.getId(), messages.get(0).getId());
assertEquals(message.getPayload(), messages.get(0).getPayload());
}
Aggregations