|
13 | 13 | use ScriptFUSION\Porter\Collection\MappedRecords; |
14 | 14 | use ScriptFUSION\Porter\Collection\PorterRecords; |
15 | 15 | use ScriptFUSION\Porter\Collection\ProviderRecords; |
| 16 | +use ScriptFUSION\Porter\Connector\RecoverableConnectorException; |
16 | 17 | use ScriptFUSION\Porter\ImportException; |
17 | 18 | use ScriptFUSION\Porter\Porter; |
18 | 19 | use ScriptFUSION\Porter\Provider\Provider; |
|
22 | 23 | use ScriptFUSION\Porter\ProviderNotFoundException; |
23 | 24 | use ScriptFUSION\Porter\Specification\ImportSpecification; |
24 | 25 | use ScriptFUSION\Porter\Specification\StaticDataImportSpecification; |
| 26 | +use ScriptFUSION\Retry\ExceptionHandler\ExponentialBackoffExceptionHandler; |
25 | 27 | use ScriptFUSION\Retry\FailingTooHardException; |
26 | 28 | use ScriptFUSIONTest\MockFactory; |
27 | 29 |
|
@@ -211,19 +213,11 @@ public function testImportTaggedResource() |
211 | 213 | self::assertSame($output, $records->current()); |
212 | 214 | } |
213 | 215 |
|
214 | | - public function testOneTry() |
215 | | - { |
216 | | - $this->setExpectedException(FailingTooHardException::class, '1'); |
217 | | - |
218 | | - $this->provider->shouldReceive('fetch')->once()->andThrow(\Exception::class); |
219 | | - $this->porter->setMaxFetchAttempts(1)->import($this->specification); |
220 | | - } |
221 | | - |
222 | | - public function testDefaultTries() |
| 216 | + public function testImportFailure() |
223 | 217 | { |
224 | | - $this->setExpectedException(FailingTooHardException::class, (string)Porter::DEFAULT_FETCH_ATTEMPTS); |
| 218 | + $this->provider->shouldReceive('fetch')->andReturn(null); |
225 | 219 |
|
226 | | - $this->provider->shouldReceive('fetch')->times(Porter::DEFAULT_FETCH_ATTEMPTS)->andThrow(\Exception::class); |
| 220 | + $this->setExpectedException(ImportException::class, get_class($this->provider)); |
227 | 221 | $this->porter->import($this->specification); |
228 | 222 | } |
229 | 223 |
|
@@ -258,6 +252,58 @@ public function testImportOneOfMany() |
258 | 252 |
|
259 | 253 | #endregion |
260 | 254 |
|
| 255 | + #region Durability |
| 256 | + |
| 257 | + public function testOneTry() |
| 258 | + { |
| 259 | + $this->provider->shouldReceive('fetch')->once()->andThrow(RecoverableConnectorException::class); |
| 260 | + |
| 261 | + $this->setExpectedException(FailingTooHardException::class, '1'); |
| 262 | + $this->porter->setMaxFetchAttempts(1)->import($this->specification); |
| 263 | + } |
| 264 | + |
| 265 | + public function testDerivedRecoverableException() |
| 266 | + { |
| 267 | + $this->provider->shouldReceive('fetch')->once()->andThrow(\Mockery::mock(RecoverableConnectorException::class)); |
| 268 | + |
| 269 | + $this->setExpectedException(FailingTooHardException::class); |
| 270 | + $this->porter->setMaxFetchAttempts(1)->import($this->specification); |
| 271 | + } |
| 272 | + |
| 273 | + public function testDefaultTries() |
| 274 | + { |
| 275 | + $this->provider->shouldReceive('fetch')->times(Porter::DEFAULT_FETCH_ATTEMPTS) |
| 276 | + ->andThrow(RecoverableConnectorException::class); |
| 277 | + |
| 278 | + $this->setExpectedException(FailingTooHardException::class, (string)Porter::DEFAULT_FETCH_ATTEMPTS); |
| 279 | + $this->porter->import($this->specification); |
| 280 | + } |
| 281 | + |
| 282 | + public function testUnrecoverableException() |
| 283 | + { |
| 284 | + $this->provider->shouldReceive('fetch')->once()->andThrow(\Exception::class); |
| 285 | + |
| 286 | + $this->setExpectedException(\Exception::class); |
| 287 | + $this->porter->import($this->specification); |
| 288 | + } |
| 289 | + |
| 290 | + public function testCustomFetchExceptionHandler() |
| 291 | + { |
| 292 | + $this->porter->setFetchExceptionHandler( |
| 293 | + \Mockery::mock(ExponentialBackoffExceptionHandler::class) |
| 294 | + ->shouldReceive('__invoke') |
| 295 | + ->times(Porter::DEFAULT_FETCH_ATTEMPTS - 1) |
| 296 | + ->getMock() |
| 297 | + ); |
| 298 | + $this->provider->shouldReceive('fetch')->times(Porter::DEFAULT_FETCH_ATTEMPTS) |
| 299 | + ->andThrow(RecoverableConnectorException::class); |
| 300 | + |
| 301 | + $this->setExpectedException(FailingTooHardException::class); |
| 302 | + $this->porter->import($this->specification); |
| 303 | + } |
| 304 | + |
| 305 | + #endregion |
| 306 | + |
261 | 307 | public function testFilter() |
262 | 308 | { |
263 | 309 | $this->provider->shouldReceive('fetch')->andReturn(new \ArrayIterator(range(1, 10))); |
|
0 commit comments