Skip to content

Commit

Permalink
refactor: rename ConsumerException to ProcessorException
Browse files Browse the repository at this point in the history
  • Loading branch information
ngodinhloc committed Sep 5, 2022
1 parent 7a11cd5 commit 574c695
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class TaskApp
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand Down
2 changes: 1 addition & 1 deletion samples/TaskService/TaskApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Broker $broker = null)
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Micronative\EventSchema\Exceptions;

class ConsumerException extends ServiceSchemaException
class ProcessorException extends ServiceSchemaException
{
const FAILED_TO_CREATE_MESSAGE = "Failed to create message from json string: ";
const EMPTY_EVENT_NAME = "Event name is empty.";
Expand Down
22 changes: 11 additions & 11 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Micronative\EventSchema\Config\Consumer\ServiceConfigRegister;
use Micronative\EventSchema\Event\AbstractEvent;
use Micronative\EventSchema\Event\EventValidator;
use Micronative\EventSchema\Exceptions\ConsumerException;
use Micronative\EventSchema\Exceptions\ProcessorException;
use Micronative\EventSchema\Json\JsonReader;
use Micronative\EventSchema\Service\RollbackInterface;
use Micronative\EventSchema\Service\ServiceFactory;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct(
* @param \Micronative\EventSchema\Event\AbstractEvent|null $event
* @param array|null $filteredEvents
* @return bool
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand Down Expand Up @@ -83,7 +83,7 @@ public function process(?AbstractEvent $event = null, ?array $filteredEvents = n
* @param \Micronative\EventSchema\Event\AbstractEvent $event
* @param array|null $filteredEvents
* @return bool
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand Down Expand Up @@ -122,32 +122,32 @@ private function loadConfigs()
/**
* @param \Micronative\EventSchema\Event\AbstractEvent $event
* @param array|null $filteredEvents
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
*/
private function checkFilteredEvents(AbstractEvent $event, ?array $filteredEvents = null)
{
if(empty($event->getName())){
throw new ConsumerException(ConsumerException::EMPTY_EVENT_NAME);
throw new ProcessorException(ProcessorException::EMPTY_EVENT_NAME);
}

if (!empty($filteredEvents) && !in_array($event->getName(), $filteredEvents)) {
throw new ConsumerException(ConsumerException::FILTERED_EVENT_ONLY . JsonReader::encode($filteredEvents));
throw new ProcessorException(ProcessorException::FILTERED_EVENT_ONLY . JsonReader::encode($filteredEvents));
}
}

/**
* @param \Micronative\EventSchema\Event\AbstractEvent $event
* @return string[]
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
*/
private function retrieveServiceClasses(AbstractEvent $event)
{
/** @var \Micronative\EventSchema\Config\Consumer\EventConfig $eventConfig */
$eventConfig = $this->eventConfigRegister->retrieveEventConfig($event->getName(), $event->getVersion());
if (empty($eventConfig)) {
throw new ConsumerException(
sprintf(ConsumerException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion())
throw new ProcessorException(
sprintf(ProcessorException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion())
);
}

Expand All @@ -156,8 +156,8 @@ private function retrieveServiceClasses(AbstractEvent $event)
*/
$event->setSchemaFile($eventConfig->getSchemaFile());
if (empty($serviceClasses = $eventConfig->getServiceClasses())) {
throw new ConsumerException(
sprintf(ConsumerException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion())
throw new ProcessorException(
sprintf(ProcessorException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion())
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ProcessorInterface
* @return bool
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
*/
public function process(AbstractEvent $event, array $filteredEvents = null);

Expand All @@ -21,7 +21,7 @@ public function process(AbstractEvent $event, array $filteredEvents = null);
* @param array|null $filteredEvents
* @return bool
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
*/
public function rollback(AbstractEvent $event, array $filteredEvents = null);
}
48 changes: 24 additions & 24 deletions tests/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Micronative\EventSchema\Processor;
use Micronative\EventSchema\Event\AbstractEvent;
use Micronative\EventSchema\Event\EventValidator;
use Micronative\EventSchema\Exceptions\ConsumerException;
use Micronative\EventSchema\Exceptions\ProcessorException;
use Micronative\EventSchema\Exceptions\ValidatorException;
use Micronative\EventSchema\Json\JsonReader;
use Micronative\EventSchema\Service\ServiceFactory;
Expand Down Expand Up @@ -36,7 +36,7 @@ public function setUp(): void
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -54,7 +54,7 @@ public function testProcess()
/**
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
*/
public function testProcessFailed()
{
Expand All @@ -68,7 +68,7 @@ public function testProcessFailed()
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -79,13 +79,13 @@ public function testProcessWithFilteredEvent()
JsonReader::read($this->testDir . "/assets/events/Users.Created.event.json")
);
$event = new SampleEvent($data->name, null, $data->id, (array)$data->payload);
$this->expectException(ConsumerException::class);
$this->expectExceptionMessageMatches('%' . ConsumerException::FILTERED_EVENT_ONLY . '%');
$this->expectException(ProcessorException::class);
$this->expectExceptionMessageMatches('%' . ProcessorException::FILTERED_EVENT_ONLY . '%');
$this->consumer->process($event, ['EventOne', 'EventTwo']);
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -94,15 +94,15 @@ public function testProcessWithNoneRegisteredEvent()
{
$data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/None.Registered.Event.json"));
$event = new SampleEvent($data->name, null, $data->id ?? null, (array)$data->payload);
$this->expectException(ConsumerException::class);
$this->expectException(ProcessorException::class);
$this->expectExceptionMessage(
sprintf(ConsumerException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion())
sprintf(ProcessorException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion())
);
$this->consumer->process($event);
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -111,15 +111,15 @@ public function testProcessWithEmptyServiceEvent()
{
$data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/Empty.Service.Event.json"));
$event = new SampleEvent('Empty.Service.Event', null, $data->id ?? null, (array)$data->payload);
$this->expectException(ConsumerException::class);
$this->expectException(ProcessorException::class);
$this->expectExceptionMessage(
sprintf(ConsumerException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion())
sprintf(ProcessorException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion())
);
$this->consumer->process($event);
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -134,7 +134,7 @@ public function testProcessWithNoneExistingServiceEvent()
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -149,7 +149,7 @@ public function testProcessWithInvalidServiceClass()
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -167,7 +167,7 @@ public function testRollback()
/**
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
*/
public function testRollbackWithInvalidValidation()
{
Expand All @@ -181,7 +181,7 @@ public function testRollbackWithInvalidValidation()
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -196,7 +196,7 @@ public function testRollbackWithInvalidServiceClass()
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -211,7 +211,7 @@ public function testRollbackWithNoneExistingServiceEvent()
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -220,15 +220,15 @@ public function testRollbackWithEmptyServiceEvent()
{
$data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/Empty.Service.Event.json"));
$event = new SampleEvent($data->name, null, $data->id ?? null, (array)$data->payload);
$this->expectException(ConsumerException::class);
$this->expectException(ProcessorException::class);
$this->expectExceptionMessage(
sprintf(ConsumerException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion())
sprintf(ProcessorException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion())
);
$this->consumer->rollback($event);
}

/**
* @throws \Micronative\EventSchema\Exceptions\ConsumerException
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
Expand All @@ -237,9 +237,9 @@ public function testRollbackWithNoneRegisteredEvent()
{
$data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/None.Registered.Event.json"));
$event = new SampleEvent($data->name, null, $data->id, (array)$data->payload);
$this->expectException(ConsumerException::class);
$this->expectException(ProcessorException::class);
$this->expectExceptionMessage(
sprintf(ConsumerException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion())
sprintf(ProcessorException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion())
);
$this->consumer->rollback($event);
}
Expand Down

0 comments on commit 574c695

Please sign in to comment.