138 lines
4.2 KiB
Plaintext
138 lines
4.2 KiB
Plaintext
program Main;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
{$R *.res}
|
|
|
|
uses
|
|
System.SysUtils,
|
|
System.Math,
|
|
ZConnection,
|
|
ZDataset,
|
|
DatabaseTestExecutor in 'DatabaseTestExecutor.pas',
|
|
DataGenerator in 'DataGenerator.pas';
|
|
|
|
var
|
|
LConnection: TZConnection;
|
|
|
|
begin
|
|
LConnection := TZConnection.Create(nil);
|
|
LConnection.LibraryLocation := ExtractFilePath(ParamStr(0)) + 'libpq.dll';
|
|
|
|
try
|
|
LConnection.Protocol := 'postgresql';
|
|
LConnection.HostName := 'localhost';
|
|
LConnection.Port := 5433;
|
|
LConnection.Database := 'test_db';
|
|
LConnection.User := 'postgres';
|
|
LConnection.Password := 'postgres';
|
|
|
|
Writeln('Connecting to PostgreSQL...');
|
|
LConnection.Connect;
|
|
Writeln('Connected successfully!');
|
|
Writeln('-------------------------');
|
|
|
|
var DatabaseManager: TDatabaseManager;
|
|
DatabaseManager := TDatabaseManager.Create(LConnection, 1234);
|
|
|
|
try
|
|
var SetupSuccess: Boolean;
|
|
SetupSuccess := DatabaseManager.SetupDatabase();
|
|
|
|
if SetupSuccess then
|
|
begin
|
|
Writeln('Done setting up database!');
|
|
end
|
|
else
|
|
begin
|
|
Writeln('Failed to setup database connection!');
|
|
end;
|
|
Writeln('-------------------------');
|
|
|
|
var LNumActions: Integer;
|
|
LNumActions := 10000;
|
|
|
|
WriteLn('Testing Database Inserts');
|
|
var LInsertTimes: TArray<Double>;
|
|
LInsertTimes := DatabaseManager.TestInserts(LNumActions);
|
|
|
|
var LMeanInsertTime: Double;
|
|
LMeanInsertTime := Mean(LInsertTimes);
|
|
|
|
if Length(LInsertTimes) <> LNumActions then
|
|
begin
|
|
WriteLn('All inserts did not complete, got=' + Length(LInsertTimes).ToString + ' expected=' + LNumActions.ToString);
|
|
end
|
|
else
|
|
begin
|
|
WriteLn(LNumActions.ToString + ' inserts completed, average time ' + LMeanInsertTime.ToString + 'ms');
|
|
end;
|
|
|
|
Writeln('-------------------------');
|
|
WriteLn('Testing reading back each record by primary key');
|
|
|
|
var LReadTimes: TArray<Double>;
|
|
LReadTimes := TArray<Double>.Create();
|
|
LReadTimes := DatabaseManager.TestReads(LNumActions);
|
|
|
|
var LMeanReadTime: Double;
|
|
LMeanReadTime := Mean(LReadTimes);
|
|
|
|
if Length(LReadTimes) <> LNumActions then
|
|
begin
|
|
WriteLn('All reads did not complete, got=' + Length(LReadTimes).ToString + ' expected=' + LNumActions.ToString);
|
|
end
|
|
else
|
|
begin
|
|
WriteLn(LNumActions.ToString + ' reads completed, average time ' + LMeanReadTime.ToString + 'ms');
|
|
end;
|
|
|
|
Writeln('-------------------------');
|
|
WriteLn('Testing reading back each record by email');
|
|
|
|
var LReadByEmailTimes: TArray<Double>;
|
|
LReadByEmailTimes := DatabaseManager.TestReadsByEmail();
|
|
|
|
var LMeanReadByEmailTime: Double;
|
|
LMeanReadByEmailTime := Mean(LReadByEmailTimes);
|
|
|
|
if Length(LReadByEmailTimes) <> LNumActions then
|
|
begin
|
|
WriteLn('All reads by email did not complete, got=' + Length(LReadByEmailTimes).ToString + ' expected=' + LNumActions.ToString);
|
|
end
|
|
else
|
|
begin
|
|
WriteLn(LNumActions.ToString + ' reads by email completed, average time ' + LMeanReadByEmailTime.ToString + 'ms');
|
|
end;
|
|
|
|
Writeln('-------------------------');
|
|
WriteLn('Testing reading back each record by social security number');
|
|
|
|
var LReadBySocialTimes: TArray<Double>;
|
|
LReadBySocialTimes := DatabaseManager.TestReadsBySocial();
|
|
|
|
var LMeanReadBySocialTime: Double;
|
|
LMeanReadBySocialTime := Mean(LReadBySocialTimes);
|
|
|
|
if Length(LReadBySocialTimes) <> LNumActions then
|
|
begin
|
|
WriteLn('All reads by social did not complete, got=' + Length(LReadBySocialTimes).ToString + ' expected=' + LNumActions.ToString);
|
|
end
|
|
else
|
|
begin
|
|
WriteLn(LNumActions.ToString + ' reads by social completed, average time ' + LMeanReadBySocialTime.ToString + 'ms');
|
|
end;
|
|
|
|
finally
|
|
DatabaseManager.Free;
|
|
end;
|
|
|
|
finally
|
|
FreeAndNil(LConnection);
|
|
end;
|
|
|
|
Writeln('-------------------------');
|
|
Writeln('Press Enter to exit...');
|
|
Readln;
|
|
end.
|