Skip to content

Commit

Permalink
removed flush of repositories (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Nov 23, 2016
1 parent e9bda57 commit ae6c2c8
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 67 deletions.
2 changes: 0 additions & 2 deletions src/Task/Runner/TaskRunner.php
Expand Up @@ -99,7 +99,5 @@ public function runTasks()
new TaskExecutionEvent($execution->getTask(), $execution)
);
}

$this->taskExecutionRepository->flush();
}
}
9 changes: 2 additions & 7 deletions src/Task/Scheduler/TaskScheduler.php
Expand Up @@ -79,11 +79,8 @@ public function addTask(TaskInterface $task)
{
$this->eventDispatcher->dispatch(Events::TASK_CREATE, new TaskEvent($task));

$this->taskRepository->persist($task);
$this->taskRepository->flush();

$this->taskRepository->save($task);
$this->scheduleTask($task);
$this->taskExecutionRepository->flush();

return $this;
}
Expand All @@ -97,8 +94,6 @@ public function scheduleTasks()
foreach ($tasks as $task) {
$this->scheduleTask($task);
}

$this->taskExecutionRepository->flush();
}

/**
Expand All @@ -119,7 +114,7 @@ protected function scheduleTask(TaskInterface $task)
new TaskExecutionEvent($task, $execution)
);

$this->taskExecutionRepository->persist($execution);
$this->taskExecutionRepository->save($execution);
}
}
}
Expand Up @@ -48,7 +48,7 @@ public function create(TaskInterface $task, \DateTime $scheduleTime)
/**
* {@inheritdoc}
*/
public function persist(TaskExecutionInterface $execution)
public function save(TaskExecutionInterface $execution)
{
$this->taskExecutionCollection->add($execution);

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Storage/ArrayStorage/ArrayTaskRepository.php
Expand Up @@ -59,7 +59,7 @@ public function create($handlerClass, $workload = null)
/**
* {@inheritdoc}
*/
public function persist(TaskInterface $task)
public function save(TaskInterface $task)
{
$this->taskCollection->add($task);

Expand Down
11 changes: 2 additions & 9 deletions src/Task/Storage/TaskExecutionRepositoryInterface.php
Expand Up @@ -30,13 +30,13 @@ interface TaskExecutionRepositoryInterface
public function create(TaskInterface $task, \DateTime $scheduleTime);

/**
* Persist task-execution.
* Save task-execution.
*
* @param TaskExecutionInterface $execution
*
* @return $this
*/
public function persist(TaskExecutionInterface $execution);
public function save(TaskExecutionInterface $execution);

/**
* Remove task-execution.
Expand All @@ -47,13 +47,6 @@ public function persist(TaskExecutionInterface $execution);
*/
public function remove(TaskExecutionInterface $execution);

/**
* Flush storage.
*
* @return $this
*/
public function flush();

/**
* Used to check whether a specific task has been scheduled at a specific time.
*
Expand Down
13 changes: 3 additions & 10 deletions src/Task/Storage/TaskRepositoryInterface.php
Expand Up @@ -38,26 +38,19 @@ public function findByUuid($uuid);
public function create($handlerClass, $workload = null);

/**
* Persist task.
* Save task.
*
* @param TaskInterface $task
*/
public function persist(TaskInterface $task);
public function save(TaskInterface $task);

/**
* Persist task.
* Remove task.
*
* @param TaskInterface $task
*/
public function remove(TaskInterface $task);

/**
* Flush storage.
*
* @return $this
*/
public function flush();

/**
* Returns all tasks.
*
Expand Down
4 changes: 0 additions & 4 deletions tests/Unit/Runner/TaskRunnerTest.php
Expand Up @@ -76,8 +76,6 @@ public function testRunTasks()
$this->initializeDispatcher($this->eventDispatcher, $executions[0]);
$this->initializeDispatcher($this->eventDispatcher, $executions[1]);

$this->taskExecutionRepository->flush()->shouldBeCalledTimes(1);

$this->taskRunner->runTasks();

$this->assertLessThanOrEqual(new \DateTime(), $executions[0]->getStartTime());
Expand Down Expand Up @@ -111,8 +109,6 @@ public function testRunTasksFailed()
$this->initializeDispatcher($this->eventDispatcher, $executions[0], Events::TASK_FAILED);
$this->initializeDispatcher($this->eventDispatcher, $executions[1]);

$this->taskExecutionRepository->flush()->shouldBeCalled();

$this->taskRunner->runTasks();

$this->assertLessThanOrEqual(new \DateTime(), $executions[0]->getStartTime());
Expand Down
11 changes: 4 additions & 7 deletions tests/Unit/Scheduler/TaskSchedulerTest.php
Expand Up @@ -111,13 +111,11 @@ function (TaskExecutionEvent $event) use ($task, $execution) {
)
)->shouldBeCalled();

$this->taskRepository->persist($task->reveal())->shouldBeCalled();
$this->taskRepository->flush()->shouldBeCalledTimes(1);
$this->taskRepository->save($task->reveal())->shouldBeCalled();

$this->taskExecutionRepository->findByStartTime($task, Argument::type(\DateTime::class))->willReturn(null);
$this->taskExecutionRepository->create($task, Argument::type(\DateTime::class))->willReturn($execution);
$this->taskExecutionRepository->persist($execution->reveal())->shouldBeCalledTimes(1);
$this->taskExecutionRepository->flush()->shouldBeCalledTimes(1);
$this->taskExecutionRepository->save($execution->reveal())->shouldBeCalledTimes(1);

$this->taskScheduler->addTask($task->reveal());
}
Expand Down Expand Up @@ -145,13 +143,12 @@ public function testScheduleTasks()
$this->taskExecutionRepository->create($tasks[1], $expression2->getNextRunDate())->willReturn(
$execution1->reveal()
);
$this->taskExecutionRepository->persist($execution1)->shouldBeCalled();
$this->taskExecutionRepository->flush()->shouldBeCalledTimes(1);
$this->taskExecutionRepository->save($execution1)->shouldBeCalled();

$execution2 = $this->prophesize(TaskExecutionInterface::class);
$execution2->setStatus(TaskStatus::PLANNED)->shouldBeCalled();
$this->taskExecutionRepository->create($tasks[2], $date)->willReturn($execution2->reveal());
$this->taskExecutionRepository->persist($execution2)->shouldBeCalled();
$this->taskExecutionRepository->save($execution2)->shouldBeCalled();

$this->eventDispatcher->dispatch(
Events::TASK_EXECUTION_CREATE,
Expand Down
Expand Up @@ -13,7 +13,6 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Prophecy\Argument;
use Task\Execution\TaskExecution;
use Task\Execution\TaskExecutionInterface;
use Task\Storage\ArrayStorage\ArrayTaskExecutionRepository;
Expand All @@ -25,7 +24,7 @@
*/
class ArrayTaskExecutionRepositoryTest extends \PHPUnit_Framework_TestCase
{
public function testPersist()
public function testSave()
{
$taskExecutionCollection = $this->prophesize(Collection::class);
$taskExecutionRepository = new ArrayTaskExecutionRepository($taskExecutionCollection->reveal());
Expand All @@ -36,7 +35,7 @@ public function testPersist()

$this->assertEquals(
$taskExecutionRepository,
$taskExecutionRepository->persist($execution->reveal())
$taskExecutionRepository->save($execution->reveal())
);
}

Expand All @@ -55,16 +54,6 @@ public function testRemove()
);
}

public function testFlush()
{
$taskExecutionCollection = $this->prophesize(Collection::class);
$taskExecutionRepository = new ArrayTaskExecutionRepository($taskExecutionCollection->reveal());

$taskExecutionCollection->add(Argument::any())->shouldNotBeCalled();

$this->assertEquals($taskExecutionRepository, $taskExecutionRepository->flush());
}

public function testFindByStartTime()
{
$task = new Task(\stdClass::class, 'Test 1', '123-123-123');
Expand Down
15 changes: 2 additions & 13 deletions tests/Unit/Storage/ArrayStorage/ArrayTaskRepositoryTest.php
Expand Up @@ -14,7 +14,6 @@
use Cron\CronExpression;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Prophecy\Argument;
use Task\Storage\ArrayStorage\ArrayTaskRepository;
use Task\Task;
use Task\TaskInterface;
Expand Down Expand Up @@ -50,7 +49,7 @@ public function testFindByUuidNotExisting()
$this->assertNull($repository->findByUuid('123-123-123'));
}

public function testPersist()
public function testSave()
{
$collection = $this->prophesize(Collection::class);
$repository = new ArrayTaskRepository($collection->reveal());
Expand All @@ -61,7 +60,7 @@ public function testPersist()

$this->assertEquals(
$repository,
$repository->persist($task->reveal())
$repository->save($task->reveal())
);
}

Expand All @@ -80,16 +79,6 @@ public function testRemove()
);
}

public function testFlush()
{
$collection = $this->prophesize(Collection::class);
$repository = new ArrayTaskRepository($collection->reveal());

$collection->add(Argument::any())->shouldNotBeCalled();

$this->assertEquals($repository, $repository->flush());
}

public function testFindAll()
{
$tasks = [
Expand Down

0 comments on commit ae6c2c8

Please sign in to comment.