Search in sources :

Example 1 with Message

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) Task(com.netflix.conductor.common.metadata.tasks.Task) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Answer(org.mockito.stubbing.Answer) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Schedulers(rx.schedulers.Schedulers) LinkedList(java.util.LinkedList) Before(org.junit.Before) Message(com.netflix.conductor.core.events.queue.Message) MockQueueProvider(com.netflix.conductor.core.events.MockQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventQueues(com.netflix.conductor.core.events.EventQueues) Executors(java.util.concurrent.Executors) QueueDAO(com.netflix.conductor.dao.QueueDAO) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Task(com.netflix.conductor.common.metadata.tasks.Task) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Workflow(com.netflix.conductor.common.run.Workflow) LinkedList(java.util.LinkedList) QueueDAO(com.netflix.conductor.dao.QueueDAO) EventQueues(com.netflix.conductor.core.events.EventQueues) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 2 with Message

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)));
}
Also used : Message(com.netflix.conductor.core.events.queue.Message) Test(org.junit.Test)

Example 3 with Message

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);
}
Also used : Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) ExecutionService(com.netflix.conductor.service.ExecutionService) MetadataService(com.netflix.conductor.service.MetadataService) JsonUtils(com.netflix.conductor.core.utils.JsonUtils) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Before(org.junit.Before)

Example 4 with Message

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;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Message(com.netflix.conductor.core.events.queue.Message) ArrayList(java.util.ArrayList) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) MapType(com.fasterxml.jackson.databind.type.MapType)

Example 5 with Message

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());
}
Also used : SearchResponse(org.elasticsearch.action.search.SearchResponse) Response(org.elasticsearch.client.Response) Message(com.netflix.conductor.core.events.queue.Message) SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) HashMap(java.util.HashMap) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Aggregations

Message (com.netflix.conductor.core.events.queue.Message)42 ArrayList (java.util.ArrayList)18 Test (org.junit.Test)16 LinkedList (java.util.LinkedList)12 List (java.util.List)11 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)10 HashMap (java.util.HashMap)10 Collections (java.util.Collections)9 Map (java.util.Map)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Connection (java.sql.Connection)7 Executors (java.util.concurrent.Executors)7 Task (com.netflix.conductor.common.metadata.tasks.Task)6 TimeUnit (java.util.concurrent.TimeUnit)6 Workflow (com.netflix.conductor.common.run.Workflow)5 QueueDAO (com.netflix.conductor.dao.QueueDAO)5 Collectors (java.util.stream.Collectors)5 SearchHit (org.elasticsearch.search.SearchHit)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5