Search in sources :

Example 1 with EventQueues

use of com.netflix.conductor.core.events.EventQueues in project conductor by Netflix.

the class TestEvent method setup.

@Before
public void setup() {
    Map<String, EventQueueProvider> providers = new HashMap<>();
    providers.put("sqs", new MockQueueProvider("sqs"));
    providers.put("conductor", new MockQueueProvider("conductor"));
    parametersUtils = new ParametersUtils();
    eventQueues = new EventQueues(providers, parametersUtils);
    testWorkflowDefinition = new WorkflowDef();
    testWorkflowDefinition.setName("testWorkflow");
    testWorkflowDefinition.setVersion(2);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) EventQueues(com.netflix.conductor.core.events.EventQueues) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) MockQueueProvider(com.netflix.conductor.core.events.MockQueueProvider) Before(org.junit.Before)

Example 2 with EventQueues

use of com.netflix.conductor.core.events.EventQueues 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 3 with EventQueues

use of com.netflix.conductor.core.events.EventQueues in project conductor by Netflix.

the class EventServiceTest method before.

@Before
public void before() {
    metadataService = Mockito.mock(MetadataService.class);
    eventProcessor = Mockito.mock(SimpleEventProcessor.class);
    eventQueues = Mockito.mock(EventQueues.class);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetadataService.class).toInstance(metadataService);
            bind(EventProcessor.class).toInstance(eventProcessor);
            bind(EventQueues.class).toInstance(eventQueues);
            install(new ValidationModule());
            bindInterceptor(Matchers.any(), Matchers.annotatedWith(Service.class), new ServiceInterceptor(getProvider(Validator.class)));
        }
    });
    eventService = injector.getInstance(EventServiceImpl.class);
}
Also used : Injector(com.google.inject.Injector) EventQueues(com.netflix.conductor.core.events.EventQueues) SimpleEventProcessor(com.netflix.conductor.core.events.SimpleEventProcessor) ServiceInterceptor(com.netflix.conductor.interceptors.ServiceInterceptor) ValidationModule(com.netflix.conductor.core.config.ValidationModule) Validator(javax.validation.Validator) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 4 with EventQueues

use of com.netflix.conductor.core.events.EventQueues in project conductor by Netflix.

the class TestEvent method testAsyncComplete.

@Test
public void testAsyncComplete() throws Exception {
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(testWorkflowDefinition);
    Task task = new Task();
    task.getInputData().put("sink", "conductor");
    task.getInputData().put("asyncComplete", true);
    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<List<String>>) invocation -> {
        String messageId = invocation.getArgument(1, String.class);
        if (publishedMessages.get(0).getId().equals(messageId)) {
            publishedMessages.remove(0);
            return Collections.singletonList(messageId);
        }
        return null;
    }).when(dao).remove(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(Status.IN_PROGRESS, 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());
}
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 5 with EventQueues

use of com.netflix.conductor.core.events.EventQueues in project conductor by Netflix.

the class MetadataServiceTest method before.

@Before
public void before() {
    metadataDAO = Mockito.mock(MetadataDAO.class);
    eventHandlerDAO = Mockito.mock(EventHandlerDAO.class);
    eventQueues = Mockito.mock(EventQueues.class);
    configuration = Mockito.mock(Configuration.class);
    when(configuration.isOwnerEmailMandatory()).thenReturn(true);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetadataDAO.class).toInstance(metadataDAO);
            bind(EventHandlerDAO.class).toInstance(eventHandlerDAO);
            bind(EventQueues.class).toInstance(eventQueues);
            bind(Configuration.class).toInstance(configuration);
            install(new ValidationModule());
            bindInterceptor(Matchers.any(), Matchers.annotatedWith(Service.class), new ServiceInterceptor(getProvider(Validator.class)));
        }
    });
    metadataService = injector.getInstance(MetadataServiceImpl.class);
}
Also used : Configuration(com.netflix.conductor.core.config.Configuration) Injector(com.google.inject.Injector) EventQueues(com.netflix.conductor.core.events.EventQueues) ServiceInterceptor(com.netflix.conductor.interceptors.ServiceInterceptor) ValidationModule(com.netflix.conductor.core.config.ValidationModule) EventHandlerDAO(com.netflix.conductor.dao.EventHandlerDAO) Validator(javax.validation.Validator) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Aggregations

EventQueues (com.netflix.conductor.core.events.EventQueues)5 Before (org.junit.Before)5 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)3 EventQueueProvider (com.netflix.conductor.core.events.EventQueueProvider)3 MockQueueProvider (com.netflix.conductor.core.events.MockQueueProvider)3 DynoEventQueueProvider (com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider)3 ParametersUtils (com.netflix.conductor.core.execution.ParametersUtils)3 HashMap (java.util.HashMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AbstractModule (com.google.inject.AbstractModule)2 Injector (com.google.inject.Injector)2 Task (com.netflix.conductor.common.metadata.tasks.Task)2 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)2 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)2 Workflow (com.netflix.conductor.common.run.Workflow)2 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)2 ValidationModule (com.netflix.conductor.core.config.ValidationModule)2 Message (com.netflix.conductor.core.events.queue.Message)2 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)2 TestConfiguration (com.netflix.conductor.core.execution.TestConfiguration)2