Skip to content

Commit 317f920

Browse files
Fix uninitialized transaction UUID
1 parent f4182d1 commit 317f920

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/etp/AbstractSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ std::string AbstractSession::startTransaction(std::vector<std::string> dataspace
312312
throw std::logic_error("You did not register any transaction protocol handlers.");
313313
}
314314
if (handlers->isInAnActiveTransaction()) {
315-
throw std::logic_error("You cannot start a transaction before the current transaction is rolled back or committed. ETP1.2 intentionally supports a single open transaction on a session.");
315+
throw std::logic_error("You cannot start a transaction before the current transaction is rolled back or committed. ETP1.2 intentionally supports a single opened transaction on a session.");
316316
}
317317

318318
Energistics::Etp::v12::Protocol::Transaction::StartTransaction startTransactionMsg;

src/etp/EtpMessages.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ namespace Energistics {
19461946
namespace v12 {
19471947
namespace Datatypes {
19481948
struct Uuid{
1949-
std::array<uint8_t, 16> array;
1949+
std::array<uint8_t, 16> array{};
19501950
};
19511951
}
19521952
}

test/unitTest.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ std::shared_ptr<ETP_NS::AbstractSession> connect()
5757
session->setStoreProtocolHandlers(std::make_shared<ETP_NS::StoreHandlers>(session.get()));
5858
session->setDataArrayProtocolHandlers(std::make_shared<ETP_NS::DataArrayHandlers>(session.get()));
5959
session->setDataspaceProtocolHandlers(std::make_shared<ETP_NS::DataspaceHandlers>(session.get()));
60+
session->setTransactionProtocolHandlers(std::make_shared<ETP_NS::TransactionHandlers>(session.get()));
6061

6162
#ifdef WITH_ETP_SSL
6263
if (std::string(ETP_SERVER_URL).find("wss://") == 0) {
@@ -132,9 +133,9 @@ TEST_CASE("Put a DataArray", "[DataArray]")
132133
const size_t xyzPointCount = 333000;
133134
std::unique_ptr<double[]> xyzPoints(new double[xyzPointCount * 3]);
134135
for (size_t ptIdx = 0; ptIdx < xyzPointCount; ptIdx++) {
135-
xyzPoints[ptIdx * 3] = ptIdx;
136-
xyzPoints[ptIdx * 3 + 1] = ptIdx;
137-
xyzPoints[ptIdx * 3 + 2] = ptIdx;
136+
xyzPoints[ptIdx * 3] = (double)ptIdx;
137+
xyzPoints[ptIdx * 3 + 1] = (double)ptIdx;
138+
xyzPoints[ptIdx * 3 + 2] = (double)ptIdx;
138139
}
139140
std::cout << "size of the array : " << xyzPointCount * 3 * 8 << " bytes." << std::endl;
140141
auto t_start = std::chrono::high_resolution_clock::now();
@@ -168,5 +169,25 @@ TEST_CASE("Put a DataArray", "[DataArray]")
168169
REQUIRE(receivedXyzPoints[xyzPointIndex * 3 + 1] == xyzPointIndex);
169170
REQUIRE(receivedXyzPoints[xyzPointIndex * 3 + 2] == xyzPointIndex);
170171
}
172+
}
173+
174+
TEST_CASE("Start and Commit a transaction", "[DataArray]")
175+
{
176+
std::shared_ptr<ETP_NS::AbstractSession> session = connect();
177+
//session->setVerbose(true);
178+
const std::string dataspaceUri = putDataspace(session);
179+
REQUIRE(dataspaceUri.size() > 0);
180+
181+
// Start an ETP transaction to not pollute server if an error occurs during transfer
182+
std::vector<std::string> dataspaceUris;
183+
dataspaceUris.push_back(dataspaceUri);
184+
std::string transactionFailure = session->startTransaction(dataspaceUris, false);
185+
REQUIRE(transactionFailure.empty());
186+
187+
transactionFailure = session->commitTransaction();
188+
REQUIRE(transactionFailure.empty());
171189

190+
// Cleaning
191+
deleteDataspace(session, dataspaceUri);
192+
session->close();
172193
}

0 commit comments

Comments
 (0)