SysTester: use unique_ptr instead of plain pointers

This commit is contained in:
Vaidas Gasiunas 2022-02-23 16:51:48 +01:00
parent e4311ae661
commit 2fb8d6ac97
6 changed files with 19 additions and 18 deletions

View File

@ -18,6 +18,7 @@
* limitations under the License.
*/
#include "SysTestWorkload.h"
#include <memory>
#include <optional>
#include <iostream>
@ -73,8 +74,8 @@ private:
int numTxLeft;
};
IWorkload* createApiCorrectnessWorkload() {
return new ApiCorrectnessWorkload();
std::unique_ptr<IWorkload> createApiCorrectnessWorkload() {
return std::make_unique<ApiCorrectnessWorkload>();
}
} // namespace FDBSystemTester

View File

@ -20,6 +20,7 @@
#include "SysTestScheduler.h"
#include <memory>
#include <thread>
#include <cassert>
#include <boost/asio.hpp>
@ -56,9 +57,9 @@ private:
any_io_executor work;
};
IScheduler* createScheduler(int numThreads) {
std::unique_ptr<IScheduler> createScheduler(int numThreads) {
assert(numThreads > 0 && numThreads <= 1000);
return new AsioScheduler(numThreads);
return std::make_unique<AsioScheduler>(numThreads);
}
} // namespace FDBSystemTester

View File

@ -38,7 +38,7 @@ public:
virtual void join() = 0;
};
IScheduler* createScheduler(int numThreads);
std::unique_ptr<IScheduler> createScheduler(int numThreads);
} // namespace FDBSystemTester

View File

@ -21,6 +21,7 @@
#include "SysTestTransactionExecutor.h"
#include <iostream>
#include <cassert>
#include <memory>
#include <random>
namespace FDBSystemTester {
@ -176,8 +177,8 @@ private:
std::mt19937 random;
};
ITransactionExecutor* createTransactionExecutor() {
return new TransactionExecutor();
std::unique_ptr<ITransactionExecutor> createTransactionExecutor() {
return std::make_unique<TransactionExecutor>();
}
} // namespace FDBSystemTester

View File

@ -76,7 +76,7 @@ public:
virtual void release() = 0;
};
ITransactionExecutor* createTransactionExecutor();
std::unique_ptr<ITransactionExecutor> createTransactionExecutor();
} // namespace FDBSystemTester

View File

@ -23,6 +23,7 @@
#include "SysTestScheduler.h"
#include "SysTestTransactionExecutor.h"
#include <iostream>
#include <memory>
#include <thread>
#include "flow/SimpleOpt.h"
#include "bindings/c/foundationdb/fdb_c.h"
@ -219,7 +220,7 @@ void fdb_check(fdb_error_t e) {
}
} // namespace
IWorkload* createApiCorrectnessWorkload();
std::unique_ptr<IWorkload> createApiCorrectnessWorkload();
} // namespace FDBSystemTester
@ -243,18 +244,15 @@ void runApiCorrectness(TesterOptions& options) {
txExecOptions.blockOnFutures = options.blockOnFutures;
txExecOptions.numDatabases = options.numDatabases;
IScheduler* scheduler = createScheduler(options.numClientThreads);
ITransactionExecutor* txExecutor = createTransactionExecutor();
std::unique_ptr<IScheduler> scheduler = createScheduler(options.numClientThreads);
std::unique_ptr<ITransactionExecutor> txExecutor = createTransactionExecutor();
scheduler->start();
txExecutor->init(scheduler, options.clusterFile.c_str(), txExecOptions);
IWorkload* workload = createApiCorrectnessWorkload();
workload->init(txExecutor, scheduler, [scheduler]() { scheduler->stop(); });
txExecutor->init(scheduler.get(), options.clusterFile.c_str(), txExecOptions);
std::unique_ptr<IWorkload> workload = createApiCorrectnessWorkload();
IScheduler* schedPtr = scheduler.get();
workload->init(txExecutor.get(), schedPtr, [schedPtr]() { schedPtr->stop(); });
workload->start();
scheduler->join();
delete workload;
delete txExecutor;
delete scheduler;
}
int main(int argc, char** argv) {