* dss * first pass at a client and tests * constructors work * working request, need to fix the response parsing * basic tests working for service client * refactored the constructors * testproxy and tests * format file * got client and one API working * list working * all apis recorded * new assets.json * assets.json regen * format json * adding word to cspell * fix build issues * fix one more break * typo * clangs * one more issue * more fixezez * regen recordings * try again * clangs * clangs again * new assets * new test proxy * regen tests based on new merge * hmmm * restore * add debug env for test proxy * resync cmake presets from main * gor get and set working * get stats * table client and create * delete * get/set acls * list tables * some cleanup * Create /update/merge/delete * upsert * query entities * generated tests * clangs * some fixes * some more errors * cspells * got transaction API working * transactions working , need to parse response * get data out of the response * clangs * batch1 * regen tests * part 2 * batch3 * batch4 * clangs * regen tests * regen tests * try again * live only * added some more tests for the transaction body * small refactor for tests * oops * some oter update * darn includes * sddfsd * erorr fix * key clients * sas * small cleanup * All tests passing * test recordings * clangs * missing ENV for test * attempt1 * retry * couple recordings * regen some tests * clangs * again * again * comments * comments * headers and footers * some cleanjup * Move folders step1 * revert assets and test resources in storage * revert to main * cspell * readme * comments * revert ci.yml * liveonly test * clangs * camke * ci2 * try again * fdssfs * fdsfsd * some cleanup * dasda * dsdsds * asda * assets * comments * a few more bits and pieces * some other updates for cspell * typo * more docs * spell * another doc error * clangs docs * docs * test cov * dasdas * hg * stress test * cspell * Update sdk/storage/azure-storage-common/test/ut/CMakeLists.txt Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/storage/azure-storage-common/test/ut/shared_key_policy_lite_test.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/CHANGELOG.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/CMakeLists.txt Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/test/stress/scenarios-matrix.yaml Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/test/stress/Dockerfile Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * PR comments * respurces cleanup * cleanup 2 * respurce fix * revddrt * weqq * oops * try again * Update sdk/tables/azure-data-tables/vcpkg/vcpkg.json Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * try * test fix * samples * readmes * readmes * readmes * api view settings * qualify friends * try * moving usings * refactor for API View tool * some more * clangs * Update sdk/tables/README.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/core/azure-core/inc/azure/core/http/http.hpp Co-authored-by: Ahson Khan <ahkha@microsoft.com> * Update sdk/core/azure-core/src/http/transport_policy.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/inc/azure/data/tables/rest_client.hpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/CHANGELOG.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/test/ut/CMakeLists.txt Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/src/rest_client.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * some comments * comments * comments part N * clang * try now * clang * comments * update file names * update test to check for the final signature * ccc * rename shared key policy lite * cleanup some includes * add a couple more tests * small update * clang * increase test limits * xml transition * service_version_policy * shared creds and key policy lite * switch to secondary policy * code done * remove last storage vestiges * put back some code * readme/changelog * Update sdk/tables/azure-data-tables/src/serializers.cpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Add the shared key policy for Larry * Larry comments * curlybracify the initializers * Update sdk/core/azure-core-xml/inc/azure/core/xml/dll_import_export.hpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Update sdk/core/azure-core-xml/vcpkg.json Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Update sdk/tables/azure-data-tables/inc/azure/data/tables.hpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Rick's comments one more namespace change for serializers * whiteline * typo * oops * includes and clangs * cleanup * jhfjdhjfd * hjkjdhf * daas * Anton's comments * clang * revert some changes * fdss * Update sdk/core/azure-core-xml/CHANGELOG.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * everything works * clangs and vcpkg test * test remove azure-core-xml * vcpkg json * remove the code * merge main * saa * wqw * last comments * clang --------- Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Co-authored-by: Ahson Khan <ahkha@microsoft.com> Co-authored-by: Rick Winter <rick.winter@microsoft.com>
189 lines
7.4 KiB
C++
189 lines
7.4 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
#include "transactions_test.hpp"
|
|
|
|
#include <chrono>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <thread>
|
|
using namespace Azure::Data::Tables;
|
|
|
|
namespace Azure { namespace Data { namespace Test {
|
|
const std::string url("someUrl");
|
|
const std::string tableName("someTableName");
|
|
const std::string partitionKey("somePartitionKey");
|
|
const std::string rowKey("someRowKey");
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionCreate)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
EXPECT_EQ(transaction.GetPartitionKey(), partitionKey);
|
|
EXPECT_EQ(transaction.GetBatchId().substr(0, 6), "batch_");
|
|
EXPECT_EQ(transaction.GetChangesetId().substr(0, 9), "changeset");
|
|
}
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionBodyInsertOp)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.RowKey = rowKey;
|
|
transaction.CreateEntity(entity);
|
|
EXPECT_EQ(transaction.GetSteps().size(), 1);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Action, Models::TransactionAction::InsertEntity);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.RowKey, rowKey);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.PartitionKey, partitionKey);
|
|
auto serialized = transaction.PreparePayload();
|
|
CheckTransactionBody(serialized, Models::TransactionAction::InsertEntity);
|
|
}
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionBodyDeleteOp)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.RowKey = rowKey;
|
|
transaction.DeleteEntity(entity);
|
|
EXPECT_EQ(transaction.GetSteps().size(), 1);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Action, Models::TransactionAction::DeleteEntity);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.RowKey, rowKey);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.PartitionKey, partitionKey);
|
|
auto serialized = transaction.PreparePayload();
|
|
CheckTransactionBody(serialized, Models::TransactionAction::DeleteEntity);
|
|
}
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionBodyMergeOp)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.RowKey = rowKey;
|
|
transaction.MergeEntity(entity);
|
|
EXPECT_EQ(transaction.GetSteps().size(), 1);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Action, Models::TransactionAction::MergeEntity);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.RowKey, rowKey);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.PartitionKey, partitionKey);
|
|
auto serialized = transaction.PreparePayload();
|
|
CheckTransactionBody(serialized, Models::TransactionAction::MergeEntity);
|
|
}
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionBodyUpdateOp)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.RowKey = rowKey;
|
|
transaction.UpdateEntity(entity);
|
|
EXPECT_EQ(transaction.GetSteps().size(), 1);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Action, Models::TransactionAction::UpdateEntity);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.RowKey, rowKey);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.PartitionKey, partitionKey);
|
|
auto serialized = transaction.PreparePayload();
|
|
CheckTransactionBody(serialized, Models::TransactionAction::UpdateEntity);
|
|
}
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionBodyInsertMergeOp)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.RowKey = rowKey;
|
|
transaction.InsertMergeEntity(entity);
|
|
EXPECT_EQ(transaction.GetSteps().size(), 1);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Action, Models::TransactionAction::MergeEntity);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.RowKey, rowKey);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.PartitionKey, partitionKey);
|
|
auto serialized = transaction.PreparePayload();
|
|
CheckTransactionBody(serialized, Models::TransactionAction::InsertMergeEntity);
|
|
}
|
|
|
|
TEST_F(TransactionsBodyTest, TransactionBodyInsertReplaceOp)
|
|
{
|
|
Tables::Transaction transaction(url, tableName, partitionKey);
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.RowKey = rowKey;
|
|
transaction.InsertReplaceEntity(entity);
|
|
EXPECT_EQ(transaction.GetSteps().size(), 1);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Action, Models::TransactionAction::UpdateEntity);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.RowKey, rowKey);
|
|
EXPECT_EQ(transaction.GetSteps()[0].Entity.PartitionKey, partitionKey);
|
|
auto serialized = transaction.PreparePayload();
|
|
CheckTransactionBody(serialized, Models::TransactionAction::InsertReplaceEntity);
|
|
}
|
|
|
|
void TransactionsBodyTest::CheckContentLines(
|
|
std::vector<std::string> const& lines,
|
|
Models::TransactionAction action)
|
|
{
|
|
EXPECT_EQ(lines[0], "--" + changeset);
|
|
EXPECT_EQ(lines[1], "Content-Type: application/http");
|
|
EXPECT_EQ(lines[2], "Content-Transfer-Encoding: binary");
|
|
switch (action)
|
|
{
|
|
case Models::TransactionAction::InsertEntity:
|
|
EXPECT_EQ(lines[4], "POST " + url + "/" + tableName + " HTTP/1.1");
|
|
break;
|
|
case Models::TransactionAction::DeleteEntity:
|
|
EXPECT_EQ(
|
|
lines[4],
|
|
"DELETE " + url + "/" + tableName + "(PartitionKey='" + partitionKey + "',RowKey='"
|
|
+ rowKey + "') HTTP/1.1");
|
|
break;
|
|
case Models::TransactionAction::MergeEntity:
|
|
EXPECT_EQ(
|
|
lines[4],
|
|
"MERGE " + url + "/" + tableName + "(PartitionKey='" + partitionKey + "',RowKey='"
|
|
+ rowKey + "') HTTP/1.1");
|
|
break;
|
|
case Models::TransactionAction::UpdateEntity:
|
|
EXPECT_EQ(
|
|
lines[4],
|
|
"PUT " + url + "/" + tableName + "(PartitionKey='" + partitionKey + "',RowKey='"
|
|
+ rowKey + "') HTTP/1.1");
|
|
break;
|
|
case Models::TransactionAction::InsertMergeEntity:
|
|
EXPECT_EQ(
|
|
lines[4],
|
|
"MERGE " + url + "/" + tableName + "(PartitionKey='" + partitionKey + "',RowKey='"
|
|
+ rowKey + "') HTTP/1.1");
|
|
break;
|
|
case Models::TransactionAction::InsertReplaceEntity:
|
|
EXPECT_EQ(
|
|
lines[4],
|
|
"PUT " + url + "/" + tableName + "(PartitionKey='" + partitionKey + "',RowKey='"
|
|
+ rowKey + "') HTTP/1.1");
|
|
break;
|
|
}
|
|
EXPECT_EQ(lines[lines.size() - 1], "--" + changeset + "--");
|
|
}
|
|
void TransactionsBodyTest::CheckTransactionBody(
|
|
std::string const& body,
|
|
Models::TransactionAction action)
|
|
{
|
|
(void)action;
|
|
std::stringstream ss(body);
|
|
std::string line;
|
|
std::getline(ss, line, '\n');
|
|
|
|
// line1
|
|
EXPECT_EQ(line.substr(0, 8), "--batch_");
|
|
EXPECT_EQ(line.size(), 44);
|
|
batch = line.substr(2, line.length() - 1);
|
|
// line2
|
|
std::getline(ss, line, '\n');
|
|
EXPECT_EQ(line.substr(0, 50), "Content-Type: multipart/mixed; boundary=changeset_");
|
|
EXPECT_EQ(line.size(), 86);
|
|
changeset = line.substr(40, line.length() - 1);
|
|
|
|
// line3
|
|
std::getline(ss, line, '\n');
|
|
EXPECT_EQ(line, "");
|
|
std::vector<std::string> contentLines;
|
|
std::getline(ss, line, '\n');
|
|
while (line != "--" + batch)
|
|
{
|
|
contentLines.push_back(line);
|
|
std::getline(ss, line, '\n');
|
|
}
|
|
CheckContentLines(contentLines, action);
|
|
EXPECT_EQ(line, "--" + batch);
|
|
}
|
|
}}} // namespace Azure::Data::Test
|