/** * @return ProcessingMetadata */ public function taskMetadata() { if (is_null($this->taskMetadata)) { $this->taskMetadata = ProcessingMetadata::fromArray($this->payload['task_metadata']); } return $this->taskMetadata; }
/** * @return Message */ public function startMessage() { if (is_null($this->startMessage)) { $processingType = $this->payload['start_message']['processing_type']; $this->startMessage = Message::emulateProcessingWorkflowMessage(MessageType::fromString($this->payload['start_message']['message_type']), $processingType::prototype(), ProcessingMetadata::fromArray($this->payload['start_message']['metadata'])); } return $this->startMessage; }
/** * @test */ function it_returns_a_emulated_process_data_message_when_its_type_is_process_data() { $messageHandler = $this->getArticleImporterMessageHandler(); $task = Task::setUp($messageHandler, Task\TaskType::processData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])); $message = $task->emulateWorkflowMessage(); $this->assertInstanceOf(Message::class, $message); $this->assertTrue($message->messageType()->isProcessDataMessage()); $this->assertEquals($task->processingType()->of(), $message->processingType()->of()); $this->assertEquals($task->metadata()->toArray(), $message->processingMetadata()->toArray()); }
/** * @return Message */ public function startMessage() { $startMessage = $this->payload['start_message']; if (isset($startMessage['metadata'])) { $metadata = ProcessingMetadata::fromArray($startMessage['metadata']); } else { $metadata = ProcessingMetadata::noData(); } $processingType = $startMessage['processing_type']; return Message::emulateProcessingWorkflowMessage(MessageType::fromString($startMessage['message_type']), $processingType::prototype(), $metadata); }
function provideStartScenarios() { return [[Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK]]; }
/** * @param bool $singleItemMode * @return MessageHandler */ protected function getArticleImporterMessageHandler($singleItemMode = false) { $supportedProcessingType = $singleItemMode ? Article::prototype() : ArticleCollection::prototype(); return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Importer', NodeName::defaultName(), MessageHandler\HandlerType::connector(), MessageHandler\DataDirection::target(), MessageHandler\ProcessingTypes::support([$supportedProcessingType]), ProcessingMetadata::fromArray(['chunk_support' => true]), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon'); }
/** * @test * @dataProvider provideNonValidMetadata * @expectedException \InvalidArgumentException */ function it_does_not_allow_non_scalar_and_non_array_values($metadata) { ProcessingMetadata::fromArray($metadata); }
/** * @test */ function it_is_equal_to_a_similar_message() { $message1 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data'])); $message2 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data'])); $this->assertTrue($message1->equals($message2)); }
/** * @return ProcessingMetadata */ public function processingMetadata() { return ProcessingMetadata::fromArray($this->payload['processing_metadata']); }
/** * @param $dataDirection * @param null|string $handlerType * @param null|array $metadata * @return MessageHandler */ private function getMessageHandler($dataDirection, $handlerType = null, array $metadata = null) { if (!is_null($handlerType)) { $handlerType = MessageHandler\HandlerType::fromString($handlerType); } else { $handlerType = MessageHandler\HandlerType::connector(); } if (!is_null($metadata)) { $metadata = ProcessingMetadata::fromArray($metadata); } else { $metadata = ProcessingMetadata::noData(); } return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Export', NodeName::defaultName(), $handlerType, MessageHandler\DataDirection::fromString($dataDirection), MessageHandler\ProcessingTypes::support([ArticleCollection::prototype(), Article::prototype()]), $metadata, 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', Article::prototype(), MessageHandler\ProcessingId::fromString('sqlconnector:::example')); }