/** * @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::addInsertEntity * @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::addOperation * @covers MicrosoftAzure\Storage\Table\Models\BatchOperations::getOperations */ public function testAddInsertEntity() { // Setup $table = 'mytable'; $entity = new Entity(); $operations = new BatchOperations(); // Test $operations->addInsertEntity($table, $entity); // Assert $this->assertCount(1, $operations->getOperations()); }
function batchInsertEntitiesSample($tableClient) { $batchOp = new BatchOperations(); for ($i = 2; $i < 10; ++$i) { $entity = new Entity(); $entity->setPartitionKey("pk"); $entity->setRowKey('' . $i); $entity->addProperty("PropertyName", EdmType::STRING, "Sample" . $i); $batchOp->addInsertEntity("mytable", $entity); } try { $tableClient->batch($batchOp); } catch (ServiceException $e) { $code = $e->getCode(); $error_message = $e->getMessage(); echo $code . ": " . $error_message . PHP_EOL; } }
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); } }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::batch * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity * @covers MicrosoftAzure\Storage\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'); }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::batch * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_createBatchRequestBody * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_getOperationContext * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_createOperationsContexts * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_constructPutOrMergeEntityContext * @covers MicrosoftAzure\Storage\Table\Internal\MimeReaderWriter::encodeMimeMultipart * @covers MicrosoftAzure\Storage\Table\Internal\MimeReaderWriter::decodeMimeMultipart * @covers MicrosoftAzure\Storage\Table\Models\BatchResult::create * @covers MicrosoftAzure\Storage\Table\Models\BatchResult::_constructResponses * @covers MicrosoftAzure\Storage\Table\Models\BatchResult::_compareUsingContentId * @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::sendContext */ public function testBatchWithMultipleOperations() { // Setup $name = 'batchwithwithmultipleoperations'; $this->createTable($name); $partitionKey = '123'; $rk1 = '456'; $rk2 = '457'; $rk3 = '458'; $delete = TestResources::getTestEntity($partitionKey, $rk1); $insert = TestResources::getTestEntity($partitionKey, $rk2); $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->addInsertEntity($name, $insert); $operations->addUpdateEntity($name, $update); $operations->addDeleteEntity($name, $delete->getPartitionKey(), $delete->getRowKey(), $delete->getETag()); // Test $result = $this->restProxy->batch($operations); // Assert $this->assertTrue(true); }