From d727d6a0d479795cd9402c0896b076e8d6d081fc Mon Sep 17 00:00:00 2001 From: coderstephen Date: Mon, 24 Aug 2015 23:23:42 -0500 Subject: [PATCH] Fix parcel method name errors and tests --- src/Sync/Parcel.php | 2 +- src/Sync/PosixSemaphore.php | 16 ++--- .../{SharedObjectTest.php => ParcelTest.php} | 58 +++++++++---------- 3 files changed, 38 insertions(+), 38 deletions(-) rename tests/Sync/{SharedObjectTest.php => ParcelTest.php} (58%) diff --git a/src/Sync/Parcel.php b/src/Sync/Parcel.php index 812f3ed..6c55f29 100644 --- a/src/Sync/Parcel.php +++ b/src/Sync/Parcel.php @@ -210,7 +210,7 @@ class Parcel implements ParcelInterface, \Serializable return [ 'id' => $this->key, - 'object' => $this->deref(), + 'object' => $this->unwrap(), 'freed' => false, ]; } diff --git a/src/Sync/PosixSemaphore.php b/src/Sync/PosixSemaphore.php index e4f4527..1460924 100644 --- a/src/Sync/PosixSemaphore.php +++ b/src/Sync/PosixSemaphore.php @@ -46,7 +46,7 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable throw new SemaphoreException('Failed to create the semaphore.'); } - $this->data = new SharedObject([ + $this->data = new Parcel([ 'locks' => (int)$maxLocks, 'waitQueue' => [], ]); @@ -62,7 +62,7 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable $this->lock(); try { - $data = $this->data->deref(); + $data = $this->data->unwrap(); // Attempt to acquire a lock from the semaphore. If no locks are // available immediately, we have a lot of work to do... @@ -73,7 +73,7 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable // thread that has been waiting longer than us. $id = mt_rand(); $data['waitQueue'][] = $id; - $this->data->set($data); + $this->data->wrap($data); // Sleep for a while, giving a chance for other threads to release // their locks. After we finish sleeping, we can check again to see @@ -82,7 +82,7 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable $this->unlock(); yield Coroutine\sleep(self::LATENCY_TIMEOUT); $this->lock(); - $data = $this->data->deref(); + $data = $this->data->unwrap(); } while ($data['locks'] <= 0 || $data['waitQueue'][0] !== $id); } @@ -90,10 +90,10 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable // semaphore is available for us to use, so decrement the lock count // to mark it as taken, and return a lock object that represents the // lock just acquired. - $data = $this->data->deref(); + $data = $this->data->unwrap(); --$data['locks']; $data['waitQueue'] = array_slice($data['waitQueue'], 1); - $this->data->set($data); + $this->data->wrap($data); yield new Lock(function (Lock $lock) { $this->release(); @@ -149,9 +149,9 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable { $this->lock(); - $data = $this->data->deref(); + $data = $this->data->unwrap(); ++$data['locks']; - $this->data->set($data); + $this->data->wrap($data); $this->unlock(); } diff --git a/tests/Sync/SharedObjectTest.php b/tests/Sync/ParcelTest.php similarity index 58% rename from tests/Sync/SharedObjectTest.php rename to tests/Sync/ParcelTest.php index 00f6ea2..d3ae8ad 100644 --- a/tests/Sync/SharedObjectTest.php +++ b/tests/Sync/ParcelTest.php @@ -1,54 +1,54 @@ assertInternalType('object', $object->deref()); + $object = new Parcel(new \stdClass()); + $this->assertInternalType('object', $object->unwrap()); $object->free(); } - public function testDerefIsOfCorrectType() + public function testUnwrapIsOfCorrectType() { - $object = new SharedObject(new \stdClass()); - $this->assertInstanceOf('stdClass', $object->deref()); + $object = new Parcel(new \stdClass()); + $this->assertInstanceOf('stdClass', $object->unwrap()); $object->free(); } - public function testDerefIsEqual() + public function testUnwrapIsEqual() { $object = new \stdClass(); - $shared = new SharedObject($object); - $this->assertEquals($object, $shared->deref()); + $shared = new Parcel($object); + $this->assertEquals($object, $shared->unwrap()); $shared->free(); } public function testNewObjectIsNotFreed() { - $object = new SharedObject(new \stdClass()); + $object = new Parcel(new \stdClass()); $this->assertFalse($object->isFreed()); $object->free(); } public function testFreeReleasesObject() { - $object = new SharedObject(new \stdClass()); + $object = new Parcel(new \stdClass()); $object->free(); $this->assertTrue($object->isFreed()); } - public function testSet() + public function testWrap() { - $shared = new SharedObject(3); - $this->assertEquals(3, $shared->deref()); + $shared = new Parcel(3); + $this->assertEquals(3, $shared->unwrap()); - $shared->set(4); - $this->assertEquals(4, $shared->deref()); + $shared->wrap(4); + $this->assertEquals(4, $shared->unwrap()); $shared->free(); } @@ -56,21 +56,21 @@ class SharedObjectTest extends TestCase /** * @expectedException \Icicle\Concurrent\Exception\SharedMemoryException */ - public function testDerefThrowsErrorIfFreed() + public function testUnwrapThrowsErrorIfFreed() { - $object = new SharedObject(new \stdClass()); + $object = new Parcel(new \stdClass()); $object->free(); - $object->deref(); + $object->unwrap(); } public function testCloneIsNewObject() { $object = new \stdClass(); - $shared = new SharedObject($object); + $shared = new Parcel($object); $clone = clone $shared; $this->assertNotSame($shared, $clone); - $this->assertNotSame($object, $clone->deref()); + $this->assertNotSame($object, $clone->unwrap()); $this->assertNotEquals($shared->__debugInfo()['id'], $clone->__debugInfo()['id']); $clone->free(); @@ -79,10 +79,10 @@ class SharedObjectTest extends TestCase public function testObjectOverflowMoved() { - $object = new SharedObject('hi', 14); - $object->set('hello world'); + $object = new Parcel('hi', 14); + $object->wrap('hello world'); - $this->assertEquals('hello world', $object->deref()); + $this->assertEquals('hello world', $object->unwrap()); $object->free(); } @@ -91,13 +91,13 @@ class SharedObjectTest extends TestCase */ public function testSetInSeparateProcess() { - $object = new SharedObject(42); + $object = new Parcel(42); $this->doInFork(function () use ($object) { - $object->set(43); + $object->wrap(43); }); - $this->assertEquals(43, $object->deref()); + $this->assertEquals(43, $object->unwrap()); $object->free(); } @@ -106,7 +106,7 @@ class SharedObjectTest extends TestCase */ public function testFreeInSeparateProcess() { - $object = new SharedObject(42); + $object = new Parcel(42); $this->doInFork(function () use ($object) { $object->free();