protected function setUp()
 {
     $this->workflowMessageHandler = new AbstractWorkflowMessageHandlerMock();
     $eventBus = new EventBus();
     $eventRouter = new EventRouter();
     $eventRouter->route(MessageNameUtils::LOG_MESSAGE_NAME)->to(function (LogMessage $logMessage) {
         $this->lastProcessingMessage = $logMessage;
     });
     $eventBus->utilize($eventRouter);
     $eventBus->utilize(new CallbackStrategy());
     $workflowEngine = new RegistryWorkflowEngine();
     $workflowEngine->registerEventBus($eventBus, [AbstractWorkflowEngine::LOCAL_CHANNEL, NodeName::defaultName()->toString()]);
     $this->workflowMessageHandler->useWorkflowEngine($workflowEngine);
 }
Ejemplo n.º 2
0
 protected function setUpOtherMachine()
 {
     $this->otherMachineWorkflowMessageHandler = new TestWorkflowMessageHandler();
     $commandBus = new CommandBus();
     $this->otherMachineCommandRouter = new CommandRouter();
     $this->otherMachineCommandRouter->route(MessageNameUtils::getCollectDataCommandName('Prooph\\ProcessingTest\\Mock\\UserDictionaryS2'))->to($this->otherMachineWorkflowMessageHandler);
     $this->otherMachineCommandRouter->route(MessageNameUtils::getProcessDataCommandName('Prooph\\ProcessingTest\\Mock\\TargetUserDictionary'))->to($this->otherMachineWorkflowMessageHandler);
     $commandBus->utilize($this->otherMachineCommandRouter);
     $commandBus->utilize(new HandleWorkflowMessageInvokeStrategy());
     $commandBus->utilize(new WorkflowProcessorInvokeStrategy());
     $commandBus->utilize(new ToProcessingMessageTranslator());
     $this->otherMachineWorkflowEngine = new RegistryWorkflowEngine();
     $this->otherMachineWorkflowEngine->registerCommandBus($commandBus, ['test-case', 'test-target', 'other_machine']);
     //Add second command bus to local workflow engine to forward StartSubProcess command to message dispatcher
     $this->otherMachineMessageDispatcher = new InMemoryRemoteMessageDispatcher($commandBus, new EventBus());
     $parentNodeCommandBus = new CommandBus();
     $parentCommandRouter = new CommandRouter();
     $parentCommandRouter->route(StartSubProcess::MSG_NAME)->to($this->otherMachineMessageDispatcher);
     $parentNodeCommandBus->utilize($parentCommandRouter);
     $parentNodeCommandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new FromProcessingMessageTranslator()));
     $this->workflowEngine->registerCommandBus($parentNodeCommandBus, ['other_machine']);
     $this->getOtherMachineWorkflowProcessor();
     //Add event buses to handle SubProcessFinished event
     $parentNodeEventBus = new EventBus();
     $parentNodeEventRouter = new EventRouter();
     $parentNodeEventBus->utilize(new SingleTargetMessageRouter($this->getTestWorkflowProcessor()));
     $parentNodeEventBus->utilize(new ToProcessingMessageTranslator());
     $parentNodeEventBus->utilize(new WorkflowProcessorInvokeStrategy());
     $otherMachineEventBus = new EventBus();
     $toParentNodeMessageDispatcher = new InMemoryRemoteMessageDispatcher(new CommandBus(), $parentNodeEventBus);
     $otherMachineEventBus->utilize(new SingleTargetMessageRouter($toParentNodeMessageDispatcher));
     $otherMachineEventBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new FromProcessingMessageTranslator()));
     $this->otherMachineWorkflowEngine->registerEventBus($otherMachineEventBus, [Definition::DEFAULT_NODE_NAME]);
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     $this->messageReceiver = new StupidWorkflowProcessorMock();
     $this->commandBus = new CommandBus();
     $this->commandBus->utilize(new SingleTargetMessageRouter($this->messageReceiver));
     $this->commandBus->utilize(new WorkflowProcessorInvokeStrategy());
     $this->eventBus = new EventBus();
     $this->eventBus->utilize(new SingleTargetMessageRouter($this->messageReceiver));
     $this->eventBus->utilize(new WorkflowProcessorInvokeStrategy());
     $locationTranslator = new LocationTranslator(['temp' => sys_get_temp_dir(), 'testdata' => $this->getTestDataPath()]);
     $this->fileGateway = new FileGateway(Bootstrap::getServiceManager()->get('prooph.link.fileconnector.file_type_adapter_manager'), Bootstrap::getServiceManager()->get('prooph.link.fileconnector.filename_renderer'), $locationTranslator);
     $workflowEngine = new RegistryWorkflowEngine();
     $workflowEngine->registerCommandBus($this->commandBus, [NodeName::defaultName()->toString(), 'file-connector']);
     $workflowEngine->registerEventBus($this->eventBus, [NodeName::defaultName()->toString(), 'file-connector']);
     $this->fileGateway->useWorkflowEngine($workflowEngine);
     $this->tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR;
 }
Ejemplo n.º 4
0
 /**
  * @test
  */
 public function it_performs_next_task_after_receiving_answer_for_previous_task()
 {
     $task1 = CollectData::from('test-case', UserDictionary::prototype());
     $task2 = ProcessData::address('test-target', ['Prooph\\ProcessingTest\\Mock\\UserDictionary']);
     $process = LinearProcess::setUp(NodeName::defaultName(), [$task1, $task2]);
     $wfm = WorkflowMessage::collectDataOf(UserDictionary::prototype(), NodeName::defaultName(), 'test-case');
     $answer1 = $wfm->answerWith(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']]));
     $this->workflowMessageHandler->setNextAnswer($answer1);
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 2);
     //Fake follow up task execution
     $processDataMessage = $answer1->prepareDataProcessing($taskListPosition, 'test-handler');
     //Remove TaskListPosition again
     $ref = new \ReflectionClass($processDataMessage);
     $taskListPositionProp = $ref->getProperty('processTaskListPosition');
     $taskListPositionProp->setAccessible(true);
     $taskListPositionProp->setValue($processDataMessage, null);
     $this->commandRouter->route($processDataMessage->messageName())->to($this->workflowMessageHandler);
     $answer2 = $processDataMessage->answerWithDataProcessingCompleted();
     $eventBus = new EventBus();
     $eventRouter = new EventRouter([$answer1->messageName() => [function (WorkflowMessage $answer) use($process, $answer2) {
         $this->workflowMessageHandler->setNextAnswer($answer2);
         $process->receiveMessage($answer, $this->workflowEngine);
     }], $answer2->messageName() => [function (WorkflowMessage $answer) use($process) {
         $process->receiveMessage($answer, $this->workflowEngine);
     }]]);
     $eventBus->utilize($eventRouter)->utilize(new CallbackStrategy());
     $workflowEngine = new RegistryWorkflowEngine();
     $workflowEngine->registerEventBus($eventBus, [NodeName::defaultName()->toString()]);
     $this->workflowMessageHandler->useWorkflowEngine($workflowEngine);
     $process->perform($this->workflowEngine);
     $this->assertTrue($process->isFinished());
     $this->assertTrue($process->isSuccessfulDone());
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function it_queues_incoming_messages_during_active_transaction_to_avoid_nested_transactions()
 {
     $wfMessage = $this->getUserDataCollectedTestMessage();
     $eventBus = new EventBus();
     $eventBus->utilize(new SingleTargetMessageRouter($this->getTestWorkflowProcessor()));
     $eventBus->utilize(new WorkflowProcessorInvokeStrategy());
     $workflowEngine = new RegistryWorkflowEngine();
     $workflowEngine->registerEventBus($eventBus, [NodeName::defaultName()->toString()]);
     $this->workflowMessageHandler->useWorkflowEngine($workflowEngine);
     $nextAnswer = $wfMessage->prepareDataProcessing(TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1), NodeName::defaultName())->answerWithDataProcessingCompleted();
     $ref = new \ReflectionClass($nextAnswer);
     $refProp = $ref->getProperty('processTaskListPosition');
     $refProp->setAccessible(true);
     $refProp->setValue($nextAnswer, null);
     $this->workflowMessageHandler->setNextAnswer($nextAnswer);
     //Without queueing incoming messages an exception will be thrown, cause the WorkflowMessageHandler answers
     //during active transaction and the WorkflowProcessor would try to load the not yet persisted process.
     $this->getTestWorkflowProcessor()->receiveMessage($wfMessage);
     $this->assertNotNull($this->lastPostCommitEvent);
     $recordedEvents = $this->lastPostCommitEvent->getRecordedEvents();
     $eventNames = [];
     foreach ($recordedEvents as $recordedEvent) {
         $eventNames[] = $recordedEvent->messageName();
     }
     $expectedEventNames = ['Prooph\\Processing\\Processor\\Task\\Event\\TaskEntryMarkedAsDone'];
     $this->assertEquals($expectedEventNames, $eventNames);
 }
 /**
  * @return RegistryWorkflowEngine
  */
 protected function getTestWorkflowEngine()
 {
     $workflowEngine = new RegistryWorkflowEngine();
     $commandBus = new CommandBus();
     $workflowEngine->registerCommandBus($commandBus, ['crm', 'online-shop']);
     $eventBus = new EventBus();
     $workflowEngine->registerEventBus($eventBus, ['crm', 'wawi']);
     return $workflowEngine;
 }