public function testUsesCallbackForWaiter() { $total = 0; $f = function () use(&$total) { return ++$total == 3; }; $w = new CallableWaiter(); $w->setCallable($f); $w->wait(); $this->assertEquals(3, $total); }
public function testUsesCallbackForWaiter() { $total = 0; $f = function ($attempts, $data) use(&$total) { $data['object']->value = 2; return ++$total == 3; }; $o = new \StdClass(); $o->value = 1; $c = array('object' => $o); $w = new CallableWaiter(); $w->setCallable($f); $w->setContext($c); $w->wait(); $this->assertEquals(3, $total); $this->assertEquals(2, $o->value); }
/** * @depends testCreatesTable */ public function testIteratesOverScan() { self::log('Adding 3 items to the table'); $this->client->putItem(array('TableName' => $this->table, 'Item' => Item::fromArray(array('foo' => 'Bar', 'bar' => 10)))); self::log('Added 1 item'); $this->client->putItem(array('TableName' => $this->table, 'Item' => Item::fromArray(array('foo' => 'Bar', 'bar' => 20)))); self::log('Added 2 items'); $this->client->putItem(array('TableName' => $this->table, 'Item' => Item::fromArray(array('foo' => 'Bar', 'bar' => 30)))); self::log('Added 3 items'); self::log('Waiting until at least 3 items are in the table'); $client = $this->client; $table = $this->table; $waiter = new CallableWaiter(); $waiter->setCallable(function () use($client, $table) { $result = $client->scan(array('TableName' => $table)); return count($result['Items']) >= 3; })->setMaxAttempts(10)->setInterval(1); $iterator = $client->getIterator('Scan', array('TableName' => $this->table, 'Limit' => 2, 'ScanFilter' => array('bar' => array('AttributeValueList' => array(array('N' => '5')), 'ComparisonOperator' => 'GT')))); $items = $iterator->toArray(); $this->assertTrue(count($items) >= 3, 'Expected 3 items, got ' . count($items)); $this->assertTrue($iterator->getRequestCount() >= 2); $mustMatch = $this->rangeKeyValues; foreach ($items as $item) { if (false !== ($pos = array_search($item['bar']['N'], $mustMatch))) { unset($mustMatch[$pos]); if (empty($mustMatch)) { break; } } } if (!empty($mustMatch)) { $this->fail('All known items were not found in scan: ' . var_export($mustMatch, true) . ' - found: ' . var_export($items, true)); } return $mustMatch; }