Browse Source

Explicitly close fedora flysystem connections (#852)

* Explicitly close fedora flysystem connections

* fixing tests
pull/853/head
Seth Shaw 3 years ago committed by GitHub
parent
commit
01f22b717f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/Flysystem/Adapter/FedoraAdapter.php
  2. 26
      tests/src/Kernel/FedoraAdapterTest.php

13
src/Flysystem/Adapter/FedoraAdapter.php

@ -50,7 +50,7 @@ class FedoraAdapter implements AdapterInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function has($path) { public function has($path) {
$response = $this->fedora->getResourceHeaders($path); $response = $this->fedora->getResourceHeaders($path, ['Connection' => 'close']);
return $response->getStatusCode() == 200; return $response->getStatusCode() == 200;
} }
@ -77,7 +77,7 @@ class FedoraAdapter implements AdapterInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function readStream($path) { public function readStream($path) {
$response = $this->fedora->getResource($path); $response = $this->fedora->getResource($path, ['Connection' => 'close']);
if ($response->getStatusCode() != 200) { if ($response->getStatusCode() != 200) {
return FALSE; return FALSE;
@ -96,7 +96,7 @@ class FedoraAdapter implements AdapterInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getMetadata($path) { public function getMetadata($path) {
$response = $this->fedora->getResourceHeaders($path); $response = $this->fedora->getResourceHeaders($path, ['Connection' => 'close']);
if ($response->getStatusCode() != 200) { if ($response->getStatusCode() != 200) {
return FALSE; return FALSE;
@ -184,7 +184,10 @@ class FedoraAdapter implements AdapterInterface {
return []; return [];
} }
// Get the resource from Fedora. // Get the resource from Fedora.
$response = $this->fedora->getResource($normalized, ['Accept' => 'application/ld+json']); $response = $this->fedora->getResource($normalized, [
'Accept' => 'application/ld+json',
'Connection' => 'close',
]);
$jsonld = (string) $response->getBody(); $jsonld = (string) $response->getBody();
$graph = json_decode($jsonld, TRUE); $graph = json_decode($jsonld, TRUE);
@ -379,7 +382,7 @@ class FedoraAdapter implements AdapterInterface {
* NULL if no tombstone, TRUE if tombstone deleted, FALSE otherwise. * NULL if no tombstone, TRUE if tombstone deleted, FALSE otherwise.
*/ */
private function deleteTombstone($path) { private function deleteTombstone($path) {
$response = $this->fedora->getResourceHeaders($path); $response = $this->fedora->getResourceHeaders($path, ['Connection' => 'close']);
$return = NULL; $return = NULL;
if ($response->getStatusCode() == 410) { if ($response->getStatusCode() == 410) {
$return = FALSE; $return = FALSE;

26
tests/src/Kernel/FedoraAdapterTest.php

@ -51,8 +51,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$prophecy = $this->prophesize(IFedoraApi::class); $prophecy = $this->prophesize(IFedoraApi::class);
$prophecy->getResourceHeaders('')->willReturn($response); $prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($response);
$prophecy->getResource('')->willReturn($response); $prophecy->getResource('', ['Connection' => 'close'])->willReturn($response);
$api = $prophecy->reveal(); $api = $prophecy->reveal();
$mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)
@ -69,8 +69,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$prophecy = $this->prophesize(IFedoraApi::class); $prophecy = $this->prophesize(IFedoraApi::class);
$prophecy->getResourceHeaders('')->willReturn($response); $prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($response);
$prophecy->getResource('')->willReturn($response); $prophecy->getResource('', ['Connection' => 'close'])->willReturn($response);
$api = $prophecy->reveal(); $api = $prophecy->reveal();
$mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)
@ -95,7 +95,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$prophecy = $this->prophesize(IFedoraApi::class); $prophecy = $this->prophesize(IFedoraApi::class);
$prophecy->getResourceHeaders('')->willReturn($response); $prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($response);
$api = $prophecy->reveal(); $api = $prophecy->reveal();
$mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)
@ -122,7 +122,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$prophecy = $this->createAdapterBase(); $prophecy = $this->createAdapterBase();
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $fedora_prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($prophecy->reveal());
$api = $fedora_prophecy->reveal(); $api = $fedora_prophecy->reveal();
@ -139,7 +139,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$fedora_prophecy = $this->prophesize(IFedoraApi::class); $fedora_prophecy = $this->prophesize(IFedoraApi::class);
$prophecy = $this->prophesize(Response::class); $prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(500); $prophecy->getStatusCode()->willReturn(500);
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $fedora_prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class); $prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(500); $prophecy->getStatusCode()->willReturn(500);
@ -176,7 +176,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
'<http://www.w3.org/ns/ldp#RDFSource>;rel="type"', '<http://www.w3.org/ns/ldp#RDFSource>;rel="type"',
]); ]);
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $fedora_prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($prophecy->reveal());
$api = $fedora_prophecy->reveal(); $api = $fedora_prophecy->reveal();
@ -196,7 +196,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$prophecy->getStatusCode()->willReturn(204); $prophecy->getStatusCode()->willReturn(204);
$fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal()); $fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal());
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $fedora_prophecy->getResourceHeaders('', ['Connection' => 'close'])->willReturn($prophecy->reveal());
$api = $fedora_prophecy->reveal(); $api = $fedora_prophecy->reveal();
$mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class) $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)
@ -242,7 +242,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$tombstone_prophecy->getStatusCode()->willReturn(204); $tombstone_prophecy->getStatusCode()->willReturn(204);
$fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal()); $fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal());
$fedora_prophecy->getResourceHeaders('') $fedora_prophecy->getResourceHeaders('', ['Connection' => 'close'])
->willReturn($head_prophecy->reveal()); ->willReturn($head_prophecy->reveal());
$fedora_prophecy->deleteResource('some-path-to-a-tombstone') $fedora_prophecy->deleteResource('some-path-to-a-tombstone')
->willReturn($tombstone_prophecy->reveal()); ->willReturn($tombstone_prophecy->reveal());
@ -273,7 +273,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$tombstone_prophecy->getStatusCode()->willReturn(500); $tombstone_prophecy->getStatusCode()->willReturn(500);
$fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal()); $fedora_prophecy->deleteResource('')->willReturn($prophecy->reveal());
$fedora_prophecy->getResourceHeaders('') $fedora_prophecy->getResourceHeaders('', ['Connection' => 'close'])
->willReturn($head_prophecy->reveal()); ->willReturn($head_prophecy->reveal());
$fedora_prophecy->deleteResource('some-path-to-a-tombstone') $fedora_prophecy->deleteResource('some-path-to-a-tombstone')
->willReturn($tombstone_prophecy->reveal()); ->willReturn($tombstone_prophecy->reveal());
@ -606,7 +606,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$fedora_prophecy = $this->prophesize(IFedoraApi::class); $fedora_prophecy = $this->prophesize(IFedoraApi::class);
$fedora_prophecy->getResource(Argument::any())->willReturn($response); $fedora_prophecy->getResource(Argument::any(), ['Connection' => 'close'])->willReturn($response);
$prophecy = $this->prophesize(Response::class); $prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201); $prophecy->getStatusCode()->willReturn(201);
@ -633,7 +633,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]);
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$fedora_prophecy->getResourceHeaders(Argument::any()) $fedora_prophecy->getResourceHeaders(Argument::any(), ['Connection' => 'close'])
->willReturn($response); ->willReturn($response);
$prophecy = $this->prophesize(Response::class); $prophecy = $this->prophesize(Response::class);

Loading…
Cancel
Save