private function doOneTimeSetup()
 {
     $table = TableServiceFunctionalTestData::$testTableNames[0];
     self::$entitiesInTable = self::getEntitiesToQueryOver();
     $parts = array();
     foreach (self::$entitiesInTable as $entity) {
         if (array_key_exists($entity->getPartitionKey(), $parts) === false) {
             $parts[$entity->getPartitionKey()] = array();
         }
         array_push($parts[$entity->getPartitionKey()], $entity);
     }
     foreach ($parts as $part) {
         $batch = new BatchOperations();
         foreach ($part as $entity) {
             $batch->addInsertEntity($table, $entity);
         }
         $this->restProxy->batch($batch);
     }
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $table = TableServiceFunctionalTestData::$TEST_TABLE_NAMES[0];
     self::$entitiesInTable = self::getEntitiesToQueryOver();
     $baseWithRestProxy = new FunctionalTestBase();
     $parts = array();
     foreach (self::$entitiesInTable as $entity) {
         if (array_key_exists($entity->getPartitionKey(), $parts) === false) {
             $parts[$entity->getPartitionKey()] = array();
         }
         array_push($parts[$entity->getPartitionKey()], $entity);
     }
     foreach ($parts as $part) {
         $batch = new BatchOperations();
         foreach ($part as $entity) {
             $batch->addInsertEntity($table, $entity);
         }
         $baseWithRestProxy->restProxy->batch($batch);
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function addToRollback($record)
 {
     if (!isset($this->backupOps)) {
         $this->backupOps = new BatchOperations();
     }
     switch ($this->getAction()) {
         case Verbs::POST:
             $this->backupOps->addDeleteEntity($this->transactionTable, $record->getPartitionKey(), $record->getRowKey());
             break;
         case Verbs::PUT:
         case Verbs::MERGE:
         case Verbs::PATCH:
         case Verbs::DELETE:
             $this->batchOps->addUpdateEntity($this->transactionTable, $record);
             break;
         default:
             break;
     }
     return true;
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::batch
  * @covers WindowsAzure\Table\TableRestProxy::_createBatchRequestBody
  * @covers WindowsAzure\Table\TableRestProxy::_getOperationContext
  * @covers WindowsAzure\Table\TableRestProxy::_createOperationsContexts
  * @covers WindowsAzure\Table\TableRestProxy::_constructPutOrMergeEntityContext
  * @covers WindowsAzure\Table\Internal\MimeReaderWriter::encodeMimeMultipart
  * @covers WindowsAzure\Table\Internal\MimeReaderWriter::decodeMimeMultipart
  * @covers WindowsAzure\Table\Models\BatchResult::create
  * @covers WindowsAzure\Table\Models\BatchResult::_constructResponses
  * @covers WindowsAzure\Table\Models\BatchResult::_compareUsingContentId
  * @covers WindowsAzure\Common\Internal\ServiceRestProxy::sendContext
  */
 public function testBatchWithDifferentPKFail()
 {
     // Setup
     $name = 'batchwithwithdifferentpkfail';
     $this->createTable($name);
     $partitionKey = '123';
     $rk1 = '456';
     $rk3 = '458';
     $delete = TestResources::getTestEntity($partitionKey, $rk1);
     $update = TestResources::getTestEntity($partitionKey, $rk3);
     $this->restProxy->insertEntity($name, $delete);
     $this->restProxy->insertEntity($name, $update);
     $result = $this->restProxy->queryEntities($name);
     $entities = $result->getEntities();
     $delete = $entities[0];
     $update = $entities[1];
     $update->addProperty('CustomerPlace', EdmType::STRING, 'Redmond');
     $operations = new BatchOperations();
     $operations->addUpdateEntity($name, $update);
     $operations->addDeleteEntity($name, '125', $delete->getRowKey(), $delete->getETag());
     // Test
     $result = $this->restProxy->batch($operations);
     // Assert
     $this->assertTrue(true);
 }
 /**
  *  @covers WindowsAzure\Table\Models\BatchOperations::addDeleteEntity
  *  @covers WindowsAzure\Table\Models\BatchOperations::addOperation
  *  @covers WindowsAzure\Table\Models\BatchOperations::getOperations
  */
 public function testAddDeleteEntity()
 {
     // Setup
     $table = 'mytable';
     $partitionKey = '123';
     $rowKey = '456';
     $etag = 'W/datetime:2009';
     $operations = new BatchOperations();
     // Test
     $operations->addDeleteEntity($table, $partitionKey, $rowKey, $etag);
     // Assert
     $this->assertCount(1, $operations->getOperations());
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::batch
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  * @covers WindowsAzure\Table\TableRestProxy::updateEntity
  */
 public function testBatchNegativeWorks()
 {
     // Arrange
     $table = self::$testTable8;
     $partitionKey = '001';
     // Insert an entity the modify it outside of the batch
     $entity1 = new Entity();
     $entity1->setPartitionKey($partitionKey);
     $entity1->setRowKey('batchNegativeWorks1');
     $entity1->addProperty('test', EdmType::INT32, 1);
     $entity2 = new Entity();
     $entity2->setPartitionKey($partitionKey);
     $entity2->setRowKey('batchNegativeWorks2');
     $entity2->addProperty('test', EdmType::INT32, 2);
     $entity3 = new Entity();
     $entity3->setPartitionKey($partitionKey);
     $entity3->setRowKey('batchNegativeWorks3');
     $entity3->addProperty('test', EdmType::INT32, 3);
     $entity1 = $this->restProxy->insertEntity($table, $entity1)->getEntity();
     $entity2 = $this->restProxy->insertEntity($table, $entity2)->getEntity();
     $entity2->addProperty('test', EdmType::INT32, -2);
     $this->restProxy->updateEntity($table, $entity2);
     // Act
     $batchOperations = new BatchOperations();
     // The $entity1 still has the original etag from the first submit,
     // so this update should fail, because another update was already made.
     $entity1->addProperty('test', EdmType::INT32, 3);
     $batchOperations->addDeleteEntity($table, $entity1->getPartitionKey(), $entity1->getRowKey(), $entity1->getETag());
     $batchOperations->addUpdateEntity($table, $entity2);
     $batchOperations->addInsertEntity($table, $entity3);
     $result = $this->restProxy->batch($batchOperations);
     // Assert
     $this->assertNotNull($result, '$result');
     $entries = $result->getEntries();
     $this->assertEquals(1, count($entries), 'count($result->getEntries())');
     $this->assertNotNull($entries[0], 'First $result should not be null');
     $this->assertTrue($entries[0] instanceof BatchError, 'First $result type');
     $error = $entries[0];
     $this->assertEquals(412, $error->getError()->getCode(), 'First $result status code');
 }