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);
}
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());
}
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);
}
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());
}
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);
}
Aggregations