/**
  * @param RemoteMessage $message
  * @return LogMessage|WorkflowMessage|StartSubProcess|SubProcessFinished
  * @throws \InvalidArgumentException
  */
 public function translateToProcessingMessage(RemoteMessage $message)
 {
     if (MessageNameUtils::isWorkflowMessage($message->name())) {
         return WorkflowMessage::fromServiceBusMessage($message);
     } else {
         if (MessageNameUtils::isProcessingLogMessage($message->name())) {
             return LogMessage::fromServiceBusMessage($message);
         } else {
             if (StartSubProcess::MSG_NAME === $message->name()) {
                 return StartSubProcess::fromServiceBusMessage($message);
             } else {
                 if (SubProcessFinished::MSG_NAME === $message->name()) {
                     return SubProcessFinished::fromServiceBusMessage($message);
                 }
             }
         }
     }
     throw new \InvalidArgumentException(sprintf('Message with name %s can not be translated. Unknown type provided.', $message->name()));
 }
 public function provideMessages()
 {
     $localTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $remoteTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::fromString("remote-system"), ProcessId::generate()), 1);
     $wfMessageWithoutTaskListPosition = WorkflowMessage::collectDataOf(TestUser::prototype(), 'test-case', 'localhost');
     $expectedDataWfMessageWithoutTaskListPosition = ['message_id' => $wfMessageWithoutTaskListPosition->uuid()->toString(), 'message_name' => $wfMessageWithoutTaskListPosition->messageName(), 'version' => $wfMessageWithoutTaskListPosition->version(), 'task_list_position' => null, 'process_id' => null, 'status' => MessageStatus::PENDING, 'failure_msg' => null];
     $wfMessageWithTaskListPosition = WorkflowMessage::collectDataOf(TestUser::prototype(), 'test-case', 'localhost');
     $wfMessageWithTaskListPosition->connectToProcessTask($localTaskListPosition);
     $expectedDataWfMessageWithTaskListPosition = ['message_id' => $wfMessageWithTaskListPosition->uuid()->toString(), 'message_name' => $wfMessageWithTaskListPosition->messageName(), 'version' => $wfMessageWithTaskListPosition->version(), 'task_list_position' => $wfMessageWithTaskListPosition->processTaskListPosition()->toString(), 'process_id' => $wfMessageWithTaskListPosition->processTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null];
     $logMessage = LogMessage::logDebugMsg("Log message", $wfMessageWithTaskListPosition);
     $expectedDataLogMessage = ['message_id' => $logMessage->uuid()->toString(), 'message_name' => $logMessage->messageName(), 'version' => 1, 'task_list_position' => $logMessage->processTaskListPosition()->toString(), 'process_id' => $logMessage->processTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null];
     $startSubProcess = StartSubProcess::at($localTaskListPosition, ["process_type" => "faked"], false, "remote-system");
     $expectedDataStartSubProcess = ['message_id' => $startSubProcess->uuid()->toString(), 'message_name' => $startSubProcess->messageName(), 'version' => $startSubProcess->version(), 'task_list_position' => $startSubProcess->parentTaskListPosition()->toString(), 'process_id' => $startSubProcess->parentTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null];
     $wfMessageWithRemoteTaskListPosition = WorkflowMessage::collectDataOf(TestUser::prototype(), 'test-case', 'localhost');
     $wfMessageWithRemoteTaskListPosition->connectToProcessTask($remoteTaskListPosition);
     $logMessageSubProcess = LogMessage::logErrorMsg("Faked error", $wfMessageWithRemoteTaskListPosition);
     $subProcessFinished = SubProcessFinished::record(NodeName::fromString("remote-system"), $remoteTaskListPosition->taskListId()->processId(), false, $logMessageSubProcess, $localTaskListPosition);
     $expectedDataSubProcessFinished = ['message_id' => $subProcessFinished->uuid()->toString(), 'message_name' => $subProcessFinished->messageName(), 'version' => $subProcessFinished->version(), 'task_list_position' => $logMessageSubProcess->processTaskListPosition()->toString(), 'process_id' => $logMessageSubProcess->processTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null];
     return [[$wfMessageWithoutTaskListPosition, $expectedDataWfMessageWithoutTaskListPosition], [$wfMessageWithoutTaskListPosition->toServiceBusMessage(), $expectedDataWfMessageWithoutTaskListPosition], [$wfMessageWithTaskListPosition, $expectedDataWfMessageWithTaskListPosition], [$wfMessageWithTaskListPosition->toServiceBusMessage(), $expectedDataWfMessageWithTaskListPosition], [$logMessage, $expectedDataLogMessage], [$logMessage->toServiceBusMessage(), $expectedDataLogMessage], [$startSubProcess, $expectedDataStartSubProcess], [$startSubProcess->toServiceBusMessage(), $expectedDataStartSubProcess], [$subProcessFinished, $expectedDataSubProcessFinished], [$subProcessFinished->toServiceBusMessage(), $expectedDataSubProcessFinished]];
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function it_translates_to_service_bus_message_and_back()
 {
     $nodeName = NodeName::fromString('other_machine');
     $subProcessId = ProcessId::generate();
     $parentTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $wfMessage = $this->getUserDataCollectedTestMessage();
     $wfMessage->connectToProcessTask(TaskListPosition::at(TaskListId::linkWith($nodeName, $subProcessId), 1));
     $message = LogMessage::logDebugMsg("Processing finished", $wfMessage);
     $event = SubProcessFinished::record($nodeName, $subProcessId, true, $message, $parentTaskListPosition);
     $sbMessage = $event->toServiceBusMessage();
     $this->assertInstanceOf('Prooph\\Common\\Messaging\\RemoteMessage', $sbMessage);
     $copyOfEvent = SubProcessFinished::fromServiceBusMessage($sbMessage);
     $this->assertInstanceOf('Prooph\\Processing\\Processor\\Event\\SubProcessFinished', $copyOfEvent);
     $this->assertTrue($nodeName->equals($copyOfEvent->processorNodeName()));
     $this->assertTrue($parentTaskListPosition->equals($copyOfEvent->parentTaskListPosition()));
     $this->assertEquals($parentTaskListPosition->taskListId()->nodeName()->toString(), $copyOfEvent->target());
     $this->assertTrue($subProcessId->equals($copyOfEvent->subProcessId()));
     $this->assertTrue($copyOfEvent->succeed());
     $this->assertEquals($message->technicalMsg(), $copyOfEvent->lastMessage()->technicalMsg());
 }
 /**
  * @test
  */
 public function it_sends_a_sub_process_finished_event_via_message_dispatcher_to_a_handler()
 {
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $wfMessage = $this->getUserDataCollectedTestMessage();
     $wfMessage->connectToProcessTask($taskListPosition);
     $logMessage = LogMessage::logDebugMsg("Just a fake event", $wfMessage);
     $subProcessFinished = SubProcessFinished::record(NodeName::defaultName(), $taskListPosition->taskListId()->processId(), true, $logMessage, $taskListPosition);
     $eventBus = new EventBus();
     $eventRouter = new EventRouter();
     $eventRouter->route(SubProcessFinished::MSG_NAME)->to($this->messageDispatcher);
     $eventBus->utilize($eventRouter);
     $eventBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new FromProcessingMessageTranslator()));
     $eventBus->dispatch($subProcessFinished);
     /** @var $receivedMessage SubProcessFinished */
     $receivedMessage = $this->receivedMessage;
     $this->assertInstanceOf(get_class($subProcessFinished), $receivedMessage);
     $this->assertTrue($taskListPosition->taskListId()->processId()->equals($receivedMessage->subProcessId()));
     $this->assertTrue($taskListPosition->equals($receivedMessage->parentTaskListPosition()));
     $this->assertTrue($subProcessFinished->uuid()->equals($receivedMessage->uuid()));
     $this->assertTrue($logMessage->uuid()->equals($receivedMessage->lastMessage()->uuid()));
     $this->assertEquals($logMessage->technicalMsg(), $receivedMessage->lastMessage()->technicalMsg());
     $this->assertEquals($subProcessFinished->createdAt()->format('Y-m-d H:i:s'), $receivedMessage->createdAt()->format('Y-m-d H:i:s'));
 }
Exemplo n.º 5
0
 /**
  * @param \Prooph\Processing\Processor\Event\SubProcessFinished $subProcessFinished
  * @throws \RuntimeException
  */
 private function continueParentProcess(SubProcessFinished $subProcessFinished)
 {
     $parentProcess = $this->processRepository->get($subProcessFinished->parentTaskListPosition()->taskListId()->processId());
     if (is_null($parentProcess)) {
         throw new \RuntimeException(sprintf("Sub process %s contains unknown parent processId. A process with id %s cannot be found!", $subProcessFinished->subProcessId()->toString(), $subProcessFinished->parentTaskListPosition()->taskListId()->processId()->toString()));
     }
     $lastAnswerReceivedForSubProcess = $subProcessFinished->lastMessage()->reconnectToProcessTask($subProcessFinished->parentTaskListPosition());
     $this->continueProcessAt($subProcessFinished->parentTaskListPosition(), $lastAnswerReceivedForSubProcess);
 }
 /**
  * @param SubProcessFinished $message
  * @return MessageLogEntry
  */
 public static function logSubProcessFinished(SubProcessFinished $message)
 {
     return self::createFromMessageProps($message->uuid(), $message->messageName(), $message->version(), $message->lastMessage()->processTaskListPosition());
 }
 /**
  * @test
  */
 public function it_dispatches_a_sub_process_finished_event()
 {
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $wfMessage = $this->getUserDataCollectedTestMessage();
     $wfMessage->connectToProcessTask($taskListPosition);
     $logMessage = LogMessage::logDebugMsg("Just a fake event", $wfMessage);
     $subProcessFinished = SubProcessFinished::record(NodeName::defaultName(), $taskListPosition->taskListId()->processId(), true, $logMessage, $taskListPosition);
     $this->workflowEngine->dispatch($subProcessFinished);
     $this->assertSame($subProcessFinished, $this->receivedMessage);
 }