mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
+Added Freepascal version of Performance Test
This commit is contained in:
parent
76c37bfdc9
commit
c1e4cbf744
156
testLazarus/MainU.pas
Normal file
156
testLazarus/MainU.pas
Normal file
@ -0,0 +1,156 @@
|
||||
unit MainU;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
|
||||
procedure Main(serveraddress: string = 'localhost');
|
||||
procedure MainWithTransaction(serveraddress: string = 'localhost');
|
||||
procedure Test_Unicode_Chars(serveraddress: string = 'localhost');
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
dateutils,
|
||||
StompClient,
|
||||
StompTypes;
|
||||
|
||||
procedure Test_Unicode_Chars(serveraddress: string);
|
||||
var
|
||||
stomp: IStompClient;
|
||||
s: IStompFrame;
|
||||
const
|
||||
SERBO = 'Što je Unicode';
|
||||
SVEDESE = 'Vad är Unicode';
|
||||
ITALIANO = 'Cos''è Unicode';
|
||||
begin
|
||||
stomp := StompUtils.NewStomp(serveraddress);
|
||||
stomp.Subscribe('/topic/unicode');
|
||||
stomp.Send('/topic/unicode', ITALIANO);
|
||||
stomp.Send('/topic/unicode', SERBO);
|
||||
stomp.Send('/topic/unicode', SVEDESE);
|
||||
|
||||
s := stomp.Receive;
|
||||
assert(s <> nil);
|
||||
assert(s.GetBody = ITALIANO);
|
||||
|
||||
s := stomp.Receive;
|
||||
assert(s <> nil);
|
||||
assert(s.GetBody = SERBO);
|
||||
|
||||
s := stomp.Receive;
|
||||
assert(s <> nil);
|
||||
assert(s.GetBody = SVEDESE);
|
||||
end;
|
||||
|
||||
procedure MainWithTransaction(serveraddress: string);
|
||||
var
|
||||
stomp, recv: IStompClient;
|
||||
frame: IStompFrame;
|
||||
const
|
||||
TR = 'TRDANIELE';
|
||||
TOPIC = '/topic/mytopic'; // TOPIC = PUB/SUB, QUEUE = LOAD BALANCER
|
||||
BODY1 = 'Hello World 1';
|
||||
BODY2 = 'Hello World 2';
|
||||
BODY3 = 'Hello World 3';
|
||||
BODY4 = 'Hello World 4';
|
||||
begin
|
||||
stomp := StompUtils.NewStomp;
|
||||
recv := StompUtils.NewStomp;
|
||||
|
||||
stomp.Subscribe(TOPIC);
|
||||
recv.Subscribe(TOPIC);
|
||||
|
||||
stomp.BeginTransaction(TR);
|
||||
stomp.Send(TOPIC, BODY1, TR);
|
||||
stomp.Send(TOPIC, BODY2, TR);
|
||||
stomp.Send(TOPIC, BODY3, TR);
|
||||
stomp.Send(TOPIC, BODY4, TR);
|
||||
|
||||
// NON DEVCE TROVARE NULLA
|
||||
frame := recv.Receive;
|
||||
assert(frame = nil);
|
||||
stomp.CommitTransaction(TR);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.GetBody = BODY1);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.GetBody = BODY2);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.GetBody = BODY3);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.GetBody = BODY4);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame = nil);
|
||||
end;
|
||||
|
||||
procedure Main(serveraddress: string = 'localhost');
|
||||
var
|
||||
stomp: IStompClient;
|
||||
frame: IStompFrame;
|
||||
headers: IStompHeaders;
|
||||
i, c: Integer;
|
||||
msgcount: Cardinal;
|
||||
totaltime, partialtime: TDateTime;
|
||||
partial: Double;
|
||||
message_data: string;
|
||||
const
|
||||
MSG = 5000;
|
||||
MSG_SIZE = 300;
|
||||
begin
|
||||
totaltime:=now;
|
||||
message_data := StringOfChar('X', MSG_SIZE);
|
||||
WriteLn('TEST MESSAGE IS (', length(message_data) * sizeof(char), ' bytes):', #13#10, '"',
|
||||
message_data, '"'#13#10#13#10);
|
||||
stomp := StompUtils.NewStomp(serveraddress, DEFAULT_STOMP_PORT, '', 'Daniele', 'Teti');
|
||||
stomp.Subscribe('/topic/foo.bar');
|
||||
|
||||
for c := 1 to 6 do
|
||||
begin
|
||||
WriteLn;
|
||||
WriteLn('= STATS LOOP ', c, '=======================================');
|
||||
partialtime:=now;
|
||||
for i := 1 to MSG do
|
||||
begin
|
||||
headers:=StompUtils.NewHeaders;
|
||||
headers.Add(TStompHeaders.NewPersistentHeader(true));
|
||||
stomp.Send('/topic/foo.bar', message_data, headers);
|
||||
end;
|
||||
WriteLn('Queued ', MSG, ' messages in ', MilliSecondSpan(partialtime, now), ' ms');
|
||||
WriteLn('Now dequeuing...');
|
||||
|
||||
msgcount := 0;
|
||||
partialtime:=now;
|
||||
while msgcount < MSG do
|
||||
begin
|
||||
frame := stomp.Receive;
|
||||
if assigned(frame) then
|
||||
begin
|
||||
inc(msgcount);
|
||||
assert(frame.GetBody = message_data);
|
||||
frame := nil;
|
||||
end
|
||||
end;
|
||||
partial:=MilliSecondSpan(partialtime, now);
|
||||
WriteLn('Dequeued ', msgcount, ' stomp messages in ', partial, ' ms');
|
||||
WriteLn('Throughput: ',
|
||||
FormatFloat('###,##0.000', partial / msgcount), ' ms/msg (',
|
||||
FormatFloat('###,##0.000', msgcount / partial), ' msg/ms)');
|
||||
// WriteLn('= END LOOP ', c, '========================================='#13#10);
|
||||
end;
|
||||
stomp.Unsubscribe('/topic/foo.bar');
|
||||
stomp.Disconnect;
|
||||
WriteLn('SPEED TEST FINISHED IN ', FormatFloat('###,##0.000', MilliSecondSpan(totaltime, now) / 1000),
|
||||
' seconds');
|
||||
end;
|
||||
|
||||
end.
|
BIN
testLazarus/teststompclient.ico
Normal file
BIN
testLazarus/teststompclient.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
219
testLazarus/teststompclient.lpi
Normal file
219
testLazarus/teststompclient.lpi
Normal file
@ -0,0 +1,219 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<MainUnit Value="0"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<Icon Value="0"/>
|
||||
<ActiveEditorIndexAtStart Value="2"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="8">
|
||||
<Unit0>
|
||||
<Filename Value="teststompclient.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<CursorPos X="1" Y="10"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<UsageCount Value="21"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="MainU"/>
|
||||
<CursorPos X="52" Y="7"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="21"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="../StompClient.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="StompClient"/>
|
||||
<CursorPos X="1" Y="14"/>
|
||||
<TopLine Value="1"/>
|
||||
<UsageCount Value="21"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="../StompTypes.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="StompTypes"/>
|
||||
<CursorPos X="20" Y="100"/>
|
||||
<TopLine Value="84"/>
|
||||
<UsageCount Value="21"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<Filename Value="../../../../../../../../usr/share/fpcsrc/2.2.4/rtl/objpas/sysutils/datih.inc"/>
|
||||
<CursorPos X="1" Y="1"/>
|
||||
<TopLine Value="101"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
<Filename Value="../../../../../../../../usr/share/fpcsrc/2.2.4/rtl/inc/systemh.inc"/>
|
||||
<CursorPos X="22" Y="86"/>
|
||||
<TopLine Value="70"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit5>
|
||||
<Unit6>
|
||||
<Filename Value="../../../../../../../../usr/share/fpcsrc/2.2.4/rtl/objpas/dateutils.pp"/>
|
||||
<UnitName Value="dateutils"/>
|
||||
<CursorPos X="13" Y="1"/>
|
||||
<TopLine Value="1"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit6>
|
||||
<Unit7>
|
||||
<Filename Value="../../../../../../../../usr/share/fpcsrc/2.2.4/rtl/objpas/dateutil.inc"/>
|
||||
<CursorPos X="25" Y="275"/>
|
||||
<TopLine Value="261"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit7>
|
||||
</Units>
|
||||
<JumpHistory Count="23" HistoryIndex="22">
|
||||
<Position1>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="25" Column="27" TopLine="1"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="100" Column="18" TopLine="81"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="103" Column="9" TopLine="81"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="109" Column="5" TopLine="81"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="120" Column="7" TopLine="104"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="124" Column="48" TopLine="104"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="128" Column="7" TopLine="104"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="139" Column="7" TopLine="121"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="140" Column="61" TopLine="121"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="142" Column="36" TopLine="121"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="143" Column="47" TopLine="121"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="109" Column="5" TopLine="91"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="103" Column="32" TopLine="91"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="102" Column="16" TopLine="87"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="135" Column="50" TopLine="119"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="107" Column="33" TopLine="93"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="114" Column="20" TopLine="97"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="123" Column="35" TopLine="101"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="125" Column="33" TopLine="101"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="114" Column="41" TopLine="100"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="143" Column="33" TopLine="124"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="15" Column="6" TopLine="1"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="MainU.pas"/>
|
||||
<Caret Line="143" Column="11" TopLine="127"/>
|
||||
</Position23>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="8"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="../;$(ProjOutDir)/"/>
|
||||
<OtherUnitFiles Value="../../../;../lib/synapse/"/>
|
||||
<UnitOutputDirectory Value="output"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<UseExternalDbgSyms Value="True"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
27
testLazarus/teststompclient.lpr
Normal file
27
testLazarus/teststompclient.lpr
Normal file
@ -0,0 +1,27 @@
|
||||
program teststompclient;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
uses
|
||||
|
||||
{$IFDEF UNIX}
|
||||
cthreads,
|
||||
{$ENDIF}
|
||||
MainU in 'MainU.pas',
|
||||
SysUtils,
|
||||
StompClient in '../StompClient.pas',
|
||||
StompTypes in '../StompTypes.pas';
|
||||
|
||||
begin
|
||||
try
|
||||
Main;
|
||||
MainWithTransaction;
|
||||
// Test_Unicode_Chars; //Non passa
|
||||
Writeln('ALL TESTS OK');
|
||||
except
|
||||
on E: Exception do
|
||||
Writeln(E.Classname, ': ', E.message);
|
||||
end;
|
||||
|
||||
readln;
|
||||
end.
|
1
testLazarus/teststompclient.rc
Normal file
1
testLazarus/teststompclient.rc
Normal file
@ -0,0 +1 @@
|
||||
MAINICON ICON "teststompclient.ico"
|
Loading…
Reference in New Issue
Block a user