mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
This commit is contained in:
parent
c9c02094d9
commit
88568a8494
138
test/MainU.pas
138
test/MainU.pas
@ -13,21 +13,20 @@ uses
|
||||
dateutils,
|
||||
StompClient,
|
||||
StompTypes,
|
||||
StopWatch;
|
||||
Diagnostics;
|
||||
|
||||
function NewStomp(serveraddress: string = 'localhost'): TStompClient;
|
||||
begin
|
||||
Result := TStompClient.Create;
|
||||
Result.UserName := 'guest';
|
||||
Result.Password := 'guest';
|
||||
Result.SetUserName('guest');
|
||||
Result.SetPassword('guest');
|
||||
Result.Connect(serveraddress);
|
||||
end;
|
||||
|
||||
|
||||
procedure Test_Unicode_Chars(serveraddress: string);
|
||||
var
|
||||
stomp: TStompClient;
|
||||
s: TStompFrame;
|
||||
s: IStompFrame;
|
||||
const
|
||||
SERBO = 'Što je Unicode';
|
||||
SVEDESE = 'Vad är Unicode';
|
||||
@ -41,16 +40,16 @@ begin
|
||||
stomp.Send('/topic/unicode', SVEDESE);
|
||||
|
||||
s := stomp.Receive;
|
||||
assert(s<>nil);
|
||||
assert(s.Body = ITALIANO);
|
||||
assert(s <> nil);
|
||||
assert(s.GetBody = ITALIANO);
|
||||
|
||||
s := stomp.Receive;
|
||||
assert(s<>nil);
|
||||
assert(s.Body = SERBO);
|
||||
assert(s <> nil);
|
||||
assert(s.GetBody = SERBO);
|
||||
|
||||
s := stomp.Receive;
|
||||
assert(s<>nil);
|
||||
assert(s.Body = SVEDESE);
|
||||
assert(s <> nil);
|
||||
assert(s.GetBody = SVEDESE);
|
||||
finally
|
||||
stomp.Free;
|
||||
end;
|
||||
@ -59,7 +58,7 @@ end;
|
||||
procedure MainWithTransaction(serveraddress: string);
|
||||
var
|
||||
stomp, recv: TStompClient;
|
||||
frame: TStompFrame;
|
||||
frame: IStompFrame;
|
||||
m: Integer;
|
||||
const
|
||||
TR = 'TRDANIELE';
|
||||
@ -77,45 +76,31 @@ begin
|
||||
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);
|
||||
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);
|
||||
|
||||
// ORA DEVE LEGGERE I MESSAGGI
|
||||
// m := 0;
|
||||
// while true do
|
||||
// begin
|
||||
// frame := recv.Receive;
|
||||
// if frame <> nil then
|
||||
// begin
|
||||
// inc(m);
|
||||
// writeln(frame.output);
|
||||
// if m = 4 then
|
||||
// break;
|
||||
// end;
|
||||
// end;
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.GetBody = BODY1);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.Body = BODY1);
|
||||
assert(frame.GetBody = BODY2);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.Body = BODY2);
|
||||
assert(frame.GetBody = BODY3);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.Body = BODY3);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame <> nil);
|
||||
assert(frame.Body = BODY4);
|
||||
assert(frame.GetBody = BODY4);
|
||||
|
||||
frame := recv.Receive;
|
||||
assert(frame = nil);
|
||||
@ -130,7 +115,7 @@ end;
|
||||
procedure Main(serveraddress: string = 'localhost');
|
||||
var
|
||||
stomp: TStompClient;
|
||||
frame: TStompFrame;
|
||||
frame: IStompFrame;
|
||||
i, c: Integer;
|
||||
msgcount: Cardinal;
|
||||
sw: TStopWatch;
|
||||
@ -142,56 +127,49 @@ begin
|
||||
message_data := StringOfChar('X', MSG_SIZE);
|
||||
WriteLn('TEST MESSAGE (', length(message_data) * sizeof(char), ' bytes):', #13#10, '"', message_data,
|
||||
'"'#13#10#13#10);
|
||||
sw := TStopWatch.Create;
|
||||
stomp := TStompClient.Create;
|
||||
try
|
||||
stomp := TStompClient.Create;
|
||||
try
|
||||
stomp.EnableReceipts := false;
|
||||
stomp.UserName := 'Daniele';
|
||||
stomp.Password := 'Paperino';
|
||||
stomp.Connect(serveraddress);
|
||||
stomp.Subscribe('/topic/foo.bar');
|
||||
stomp.SetUserName('Daniele');
|
||||
stomp.SetPassword('Paperino');
|
||||
stomp.Connect(serveraddress);
|
||||
stomp.Subscribe('/topic/foo.bar');
|
||||
|
||||
for c := 1 to 10 do
|
||||
for c := 1 to 10 do
|
||||
begin
|
||||
WriteLn;
|
||||
WriteLn('= STATS LOOP ', c, '=======================================');
|
||||
for i := 1 to MSG do
|
||||
begin
|
||||
WriteLn;
|
||||
WriteLn('= STATS LOOP ', c, '=======================================');
|
||||
for i := 1 to MSG do
|
||||
begin
|
||||
stomp.send('/topic/foo.bar', message_data, StompUtils.StompHeaders.Add(shPersistent)
|
||||
// '01234567890123456789012345678901234567890123456789'
|
||||
);
|
||||
if i mod 1000 = 0 then
|
||||
WriteLn('Queued ', i, ' messages');
|
||||
end;
|
||||
|
||||
msgcount := 0;
|
||||
sw.start;
|
||||
while msgcount < MSG do
|
||||
begin
|
||||
frame := stomp.Receive;
|
||||
if assigned(frame) then
|
||||
begin
|
||||
inc(msgcount);
|
||||
frame.Free;
|
||||
end
|
||||
end;
|
||||
sw.Stop;
|
||||
WriteLn(msgcount, ' in ', sw.ElapsedMiliseconds, ' milliseconds and ', sw.ElapsedTicks, ' ticks');
|
||||
WriteLn('Throughput: ');
|
||||
WriteLn(FormatFloat('###,##0.000', sw.ElapsedMiliseconds / msgcount), ' ms/msg');
|
||||
WriteLn(FormatFloat('###,##0.000', msgcount / sw.ElapsedMiliseconds), ' msg/ms');
|
||||
WriteLn('= END LOOP ', c, '========================================='#13#10);
|
||||
stomp.Send('/topic/foo.bar', message_data, StompUtils.NewHeaders.Add(TStompHeaders.NewPersistentHeader(true)));
|
||||
// '01234567890123456789012345678901234567890123456789'
|
||||
if i mod 1000 = 0 then
|
||||
WriteLn('Queued ', i, ' messages');
|
||||
end;
|
||||
|
||||
stomp.Unsubscribe('/topic/foo.bar');
|
||||
stomp.Disconnect;
|
||||
write('test finished...');
|
||||
finally
|
||||
stomp.Free;
|
||||
msgcount := 0;
|
||||
sw.start;
|
||||
while msgcount < MSG do
|
||||
begin
|
||||
frame := stomp.Receive;
|
||||
if assigned(frame) then
|
||||
begin
|
||||
inc(msgcount);
|
||||
frame := Nil;
|
||||
end
|
||||
end;
|
||||
sw.Stop;
|
||||
WriteLn(msgcount, ' in ', sw.ElapsedMilliseconds, ' milliseconds and ', sw.ElapsedTicks, ' ticks');
|
||||
WriteLn('Throughput: ');
|
||||
WriteLn(FormatFloat('###,##0.000', sw.ElapsedMilliseconds / msgcount), ' ms/msg');
|
||||
WriteLn(FormatFloat('###,##0.000', msgcount / sw.ElapsedMilliseconds), ' msg/ms');
|
||||
WriteLn('= END LOOP ', c, '========================================='#13#10);
|
||||
end;
|
||||
|
||||
stomp.Unsubscribe('/topic/foo.bar');
|
||||
stomp.Disconnect;
|
||||
write('test finished...');
|
||||
finally
|
||||
sw.Free;
|
||||
stomp.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -3,11 +3,10 @@ program teststompclient;
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
StompTypes in 'StompTypes.pas',
|
||||
StompClient in 'StompClient.pas',
|
||||
MainU in 'MainU.pas',
|
||||
SysUtils,
|
||||
StopWatch in 'StopWatch.pas';
|
||||
StompClient in '..\StompClient.pas',
|
||||
StompTypes in '..\StompTypes.pas';
|
||||
|
||||
begin
|
||||
try
|
||||
|
@ -101,10 +101,9 @@
|
||||
<DelphiCompile Include="teststompclient.dpr">
|
||||
<MainSource>MainSource</MainSource>
|
||||
</DelphiCompile>
|
||||
<DCCReference Include="StompTypes.pas"/>
|
||||
<DCCReference Include="StompClient.pas"/>
|
||||
<DCCReference Include="MainU.pas"/>
|
||||
<DCCReference Include="StopWatch.pas"/>
|
||||
<DCCReference Include="..\StompClient.pas"/>
|
||||
<DCCReference Include="..\StompTypes.pas"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
|
Loading…
Reference in New Issue
Block a user