Re: [stomp-scm] [82] trunk/Delphi: add failover support

View: New views
1 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: [stomp-scm] [82] trunk/Delphi: add failover support

by James.Strachan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Awesome! :)

On 16 May 2007 07:47:06 -0000, pdv@... <pdv@...> wrote:

>
>
>  Revision 82 Author pdv Date 2007-05-16 02:47:05 -0500 (Wed, 16 May 2007)
> Log Message add failover support
>
> Modified Paths
>
> trunk/Delphi/README.txt
> trunk/Delphi/example/untMain.dfm
> trunk/Delphi/example/untMain.pas
> trunk/Delphi/source/StompClient.pas
> Added Paths
>
> trunk/Delphi/unit_test/
> trunk/Delphi/unit_test/TestStomp.dpr
> trunk/Delphi/unit_test/dunit.ini
> trunk/Delphi/unit_test/untTestStomp.pas
>
> Diff
> Modified: trunk/Delphi/README.txt (81 => 82) --- trunk/Delphi/README.txt
> 2007-05-09 19:49:19 UTC (rev 81)
> +++ trunk/Delphi/README.txt 2007-05-16 07:47:05 UTC (rev 82)
> @@ -7,3 +7,7 @@
>  Have fun!
>
>  Dingwen Yuan
> +
> +v0.1 basic stomp client
> +v0.2 stomp client that support failover in round robin mode between
> multiple brokers.
> + to disable it, set "TestConnection" property to false before "open"
> operation.
>
>
> Modified: trunk/Delphi/example/untMain.dfm (81 => 82) ---
> trunk/Delphi/example/untMain.dfm 2007-05-09 19:49:19 UTC
> (rev 81)
> +++ trunk/Delphi/example/untMain.dfm 2007-05-16 07:47:05
> UTC (rev 82)
> @@ -3,7 +3,7 @@
>  Top = 114
>  Width = 696
>  Height = 480
> - Caption = 'Form1'
> + Caption = 'i'
>  Color = clBtnFace
>  Font.Charset = DEFAULT_CHARSET
>  Font.Color = clWindowText
> @@ -35,22 +35,15 @@
>  Top = 56
>  Width = 22
>  Height = 13
> - Caption = 'Host'
> + Caption = 'Addr'
>  end
>  object Label4: TLabel
> - Left = 208
> - Top = 56
> + Left = 64
> + Top = 112
>  Width = 48
>  Height = 13
>  Caption = 'Username'
>  end
> - object Label2: TLabel
> - Left = 64
> - Top = 112
> - Width = 19
> - Height = 13
> - Caption = 'Port'
> - end
>  object Label3: TLabel
>  Left = 208
>  Top = 112
> @@ -75,32 +68,24 @@
>  object edHost: TEdit
>  Left = 64
>  Top = 80
> - Width = 129
> + Width = 241
>  Height = 21
>  TabOrder = 0
> - Text = '127.0.0.1'
> + Text = '127.0.0.1:61613;128.64.7.111:61613'
>  end
>  object edUsername: TEdit
> - Left = 208
> - Top = 80
> - Width = 129
> - Height = 21
> - TabOrder = 1
> - end
> - object edPort: TEdit
>  Left = 64
>  Top = 136
>  Width = 129
>  Height = 21
> - TabOrder = 2
> - Text = '61613'
> + TabOrder = 1
>  end
>  object edPasscode: TEdit
>  Left = 208
>  Top = 136
>  Width = 129
>  Height = 21
> - TabOrder = 3
> + TabOrder = 2
>  end
>  object btOpen: TButton
>  Left = 48
> @@ -108,7 +93,7 @@
>  Width = 129
>  Height = 25
>  Caption = 'Open connection'
> - TabOrder = 4
> + TabOrder = 3
>  OnClick = btOpenClick
>  end
>  object btClose: TButton
> @@ -117,7 +102,7 @@
>  Width = 129
>  Height = 25
>  Caption = 'Close connection'
> - TabOrder = 5
> + TabOrder = 4
>  OnClick = btCloseClick
>  end
>  object btSendQ: TButton
> @@ -126,7 +111,7 @@
>  Width = 121
>  Height = 25
>  Caption = 'send hello to queue A'
> - TabOrder = 6
> + TabOrder = 5
>  OnClick = btSendQClick
>  end
>  object Button1: TButton
> @@ -135,7 +120,7 @@
>  Width = 121
>  Height = 25
>  Caption = 'send hello to topic B'
> - TabOrder = 7
> + TabOrder = 6
>  OnClick = Button1Click
>  end
>  object edQueueA: TEdit
> @@ -143,7 +128,7 @@
>  Top = 200
>  Width = 129
>  Height = 21
> - TabOrder = 8
> + TabOrder = 7
>  Text = 'A'
>  end
>  end
> @@ -156,13 +141,15 @@
>  Text = 'B'
>  end
>  object StompClient: TStompClient
> - Port = 61613
> + ServerAddr = '127.0.0.1:61613'
>  OnConnect = StompClientConnect
>  OnDisconnect = StompClientDisconnect
> - OnTransportError = StompClientTransportError
>  OnError = StompClientError
>  OnMessage = StompClientMessage
>  OnReceipt = StompClientReceipt
> + OnSetOtherConnectHeaders =
> StompClientSetOtherConnectHeaders
> + TestConnection = True
> + TestInterval = 1000
>  Left = 24
>  Top = 96
>  end
>
>
> Modified: trunk/Delphi/example/untMain.pas (81 => 82) ---
> trunk/Delphi/example/untMain.pas 2007-05-09 19:49:19 UTC
> (rev 81)
> +++ trunk/Delphi/example/untMain.pas 2007-05-16 07:47:05
> UTC (rev 82)
> @@ -14,8 +14,6 @@
>  edHost: TEdit;
>  Label4: TLabel;
>  edUsername: TEdit;
> - edPort: TEdit;
> - Label2: TLabel;
>  Label3: TLabel;
>  edPasscode: TEdit;
>  btOpen: TButton;
> @@ -39,6 +37,8 @@
>  procedure btSendQClick(Sender: TObject);
>  procedure Button1Click(Sender: TObject);
>  procedure StompClientConnect(Client: TStompClient; Frame: TStompFrame);
> + procedure StompClientSetOtherConnectHeaders(Host: String;
> + Port: Integer; var ConnectFrame: TStompFrame);
>  private
>  { Private declarations }
>  FQueueA: string;
> @@ -66,18 +66,8 @@
>  procedure TForm1.btOpenClick(Sender: TObject);
>  begin
>
> - self.StompClient.Host:= edHost.Text;
> - self.StompClient.Port:= StrToInt(edPort.Text);
> -
> - CONN_HEADERS:= nil;
> - setLength(CONN_HEADERS, 2);
> - CONN_HEADERS[0].Key:= 'login';
> - CONN_HEADERS[0].Value:= 'me';
> - CONN_HEADERS[1].Key:= 'passcode';
> - CONN_HEADERS[1].Value:= 'pass';
> - //set various other headers.
> - StompClient.ClearAndSetConnectHeaders(CONN_HEADERS);
> -
> + self.StompClient.ServerAddr:= edHost.Text;
> +
>  Memo.Lines.Add('open stomp client');
>  StompClient.Open;
>  end;
> @@ -143,5 +133,12 @@
>  Frame.Free;
>  end;
>
> +procedure TForm1.StompClientSetOtherConnectHeaders(Host:
> String;
> + Port: Integer; var ConnectFrame: TStompFrame);
> +begin
> + Memo.Lines.Add('On Set Other Connect Headers for
> '+Host+':'+IntToStr(Port));
> + ConnectFrame.Add('hello', 'hello');
> +end;
> +
>  end.
>
> \ No newline at end of file
>
>
> Modified: trunk/Delphi/source/StompClient.pas (81 => 82)
> --- trunk/Delphi/source/StompClient.pas 2007-05-09 19:49:19
> UTC (rev 81)
> +++ trunk/Delphi/source/StompClient.pas 2007-05-16 07:47:05
> UTC (rev 82)
> @@ -1,13 +1,13 @@
>  unit StompClient;
>
>  // Author: Dingwen Yuan pdvyuan@...
> -// Version: 0.1
> +// Version: 0.2
>
>
>  interface
>
>  uses
> - Windows, Messages, SysUtils, Classes, ScktComp;
> + Windows, Messages, SysUtils, Classes, ScktComp, ExtCtrls;
>
>  const
>  LINE_SEP: char = #10;
> @@ -49,6 +49,15 @@
>  function GetHeader(i: Integer): PItem;
>  end;
>
> + TAddress = record
> + Host: String;
> + Port: Integer;
> + UserName: String;
> + PassCode: String;
> + end;
> +
> + TAddresses = array of TAddress;
> +
>  //process message in the buffer
>  //return TFrame, when there is no complete frame in the buffer, return nil.
>  //buf contains what left after processing.
> @@ -62,6 +71,7 @@
>  TStompDisconnectNotifyEvent = procedure (Client: TStompClient) of object;
>  TStompErrorNotifyEvent = procedure (Client: TStompClient; Msg: String;
> Content: String) of object;
>  TStompReceiptNotifyEvent = procedure (Client: TStompClient; ReceiptID:
> String) of object;
> + TSetOtherConnectHeaders = procedure (Host: String; Port: Integer; var
> ConnectFrame: TStompFrame) of object;
>
>  //Frame should be removed by client
>  TStompMessageNotifyEvent = procedure (Client: TStompClient; Frame:
> TStompFrame) of object;
> @@ -74,6 +84,10 @@
>  TStompClient = class(TComponent)
>  private
>  { Private declarations }
> + FServerAddrs: TAddresses;
> + FNextConnect: Integer;
> + FTestConnection: boolean;
> + FServerAddr: String;
>  FTransport: TClientSocket;
>  FConnected: Boolean;
>  FOnConnect: TStompConnectNotifyEvent;
> @@ -81,36 +95,50 @@
>  //error message
>  FOnError: TStompErrorNotifyEvent;
>  FOnDisconnect: TStompDisconnectNotifyEvent;
> - FOnTransportError: TSocketErrorEvent;
>  FOnReceipt: TStompReceiptNotifyEvent;
> -
> + FOnSetOtherConnectHeaders: TSetOtherConnectHeaders;
> + FTimer: TTimer;
>  FConnectFrame: TStompFrame;
>  //Read message buffer
>  FBuf: String;
> - procedure SetHost(const Value: String);
> - procedure SetPort(const Value: Integer);
> - function GetHost: String;
> - function GetPort: Integer;
>  procedure OnTransportRead(Sender: TObject; Socket: TCustomWinSocket);
>  procedure OnTransportConnect(Sender: TObject; Socket: TCustomWinSocket);
>  procedure OnTransportDisconnect(Sender: TObject; Socket: TCustomWinSocket);
> + procedure OnTransportError(Sender: TObject; Socket: TCustomWinSocket;
> + ErrorEvent: TErrorEvent; var ErrorCode: Integer);
> + procedure OnTimer(Sender: TObject);
>  procedure Connect;
>  procedure Disconnect;
>  procedure Transmit(Frame: TStompFrame); overload;
>  procedure Transmit(Frame: TStompFrame; Headers: array of TItem); overload;
>  procedure Send(Dest: String; Body: String; IsText: Boolean; ReceiptID:
> String); overload;
>  procedure Send(Dest: String; Body: String; Headers: array of TItem; IsText:
> Boolean; ReceiptID: String); overload;
> + function GetServerAddr: String;
> + procedure SetServerAddr(const Value: String);
> +
> + procedure SplitAddrs(Addr: String);
> + function GetTestConnection: boolean;
> + procedure SetTestConnection(const Value: boolean);
> + function GetTestConnectionInterval: Integer;
> + procedure SetTestConnectionInterval(const Value: Integer);
> +
> + procedure DoClose;
> + procedure DoOpen;
>  protected
>  { Protected declarations }
>  public
>  { Public declarations }
>  constructor Create(AOwner: TComponent); override;
> - //clear connect headers and set new.
> - procedure ClearAndSetConnectHeaders(Headers: array of
> TItem);
> + {
> + //clear all the items of CONNECT HEADERS except that of login and
> passcode, and set new.
> + //login and passcode should be set in the ServerAddr property.
> + procedure ClearAndSetSuppConnectHeaders(Headers: array of
> TItem);
> + }
>  destructor Destroy; override;
> - //Open connection and send connect frame
> + //Open connection and send connect frame if connected.
> + //connecting will be tested if TestConnection is true and connection will
> be tried in circular form .
>  procedure Open;
> - //Send disconnect frame and close connection
> + //disable connection timer, then send disconnect frame if possible and
> close connection
>  procedure Close;
>
>  //Send send frame
> @@ -141,29 +169,31 @@
>
>  property Connected: Boolean read FConnected;
>  property Transport: TClientSocket read FTransport write FTransport;
> + function GetServerAddrs: TAddresses;
>  published
>  { Published declarations }
> - //Stomp server host
> - property Host: String read GetHost write SetHost;
> - //Stomp server port
> - property Port: Integer read GetPort write SetPort;
> -
> +
> + //Stomp Server Address: ServerAddr should be in the form of host:port or
> host:port:user:passcode
> + property ServerAddr: String read GetServerAddr write SetServerAddr;
>  //fired after receive CONNECTED frame. client should be in charge of free
> StompFrame.
>  property OnConnect: TStompConnectNotifyEvent read FOnConnect write
> FOnConnect;
>  //If socket close operation is active, it is fired after sending DISCONNECT
> frame
>  // and just before the socket is closed.
>  //If socket close operation is passive, it is fired just before the socket
> is closed.
>  property OnDisconnect: TStompDisconnectNotifyEvent read FOnDisconnect write
> FOnDisconnect;
> - //fired when socket error occurs. Normally the event handler should set
> ErrorCode to 0,
> - //in order to clear the error.
> - property OnTransportError: TSocketErrorEvent read FOnTransportError write
> FOnTransportError;
>  //fired on receiving error frame. Note the difference between this event
> and OnTransportError.
>  property OnError: TStompErrorNotifyEvent read FOnError write FOnError;
>  //fired on receiving message frame. client should be in charge of free
> StompFrame.
>  property OnMessage: TStompMessageNotifyEvent read FOnMessage write
> FOnMessage;
>  //fired on receiving receipt frame.
>  property OnReceipt: TStompReceiptNotifyEvent read FOnReceipt write
> FOnReceipt;
> -
> + //Set headers other than login and passcode for CONNECT frame.
> + property OnSetOtherConnectHeaders: TSetOtherConnectHeaders read
> FOnSetOtherConnectHeaders write FOnSetOtherConnectHeaders;
> + //connection test set. default true; TestConnection should not be set
> between open and close,
> + //because it will have no effect.
> + property TestConnection: boolean read GetTestConnection write
> SetTestConnection;
> + //connection test interval in ms. default 1000;
> + property TestInterval: Integer read GetTestConnectionInterval write
> SetTestConnectionInterval;
>  end;
>
>
> @@ -389,16 +419,13 @@
>
>  procedure TStompClient.Close;
>  begin
> - if self.FTransport.Active then
> - Self.Disconnect;
> - self.FTransport.Close;
> + self.FTimer.Enabled:= false;
> + DoClose;
>  end;
>
>  procedure TStompClient.Connect;
> -
>  begin
>  FTransport.Socket.SendText(FConnectFrame.output);
> -
>  end;
>
>  constructor TStompClient.Create(AOwner: TComponent);
> @@ -410,13 +437,17 @@
>  FConnectFrame.Add('passcode', '');
>  FTransport:= TClientSocket.Create(Self);
>  FTransport.OnConnect:= OnTransportConnect;
> + FTransport.OnError:= OnTransportError;
>  FTransport.OnDisconnect:= OnTransportDisconnect;
>  FTransport.OnRead:= OnTransportRead;
> - FTransport.OnError:= OnTransportError;
>  FConnected:= false;
> + FTimer:= TTimer.Create(self);
> + FTimer.OnTimer:= OnTimer;
> + FTimer.Enabled:= false;
> + TestConnection:= true;
> + TestInterval:= 1000;
>  FBuf:= '';
> - self.FTransport.Port:= 61613;
> -
> + self.ServerAddr:= '127.0.0.1:61613';
>  end;
>
>  destructor TStompClient.Destroy;
> @@ -441,19 +472,23 @@
>  end;
>
>
> -function TStompClient.GetHost: String;
> -begin
> - result:= FTransport.Host;
> -end;
> -
> -function TStompClient.GetPort: Integer;
> -begin
> - result:= FTransport.Port;
> -end;
> -
>  procedure TStompClient.OnTransportConnect(Sender: TObject;
>  Socket: TCustomWinSocket);
> +var
> + index: Integer;
> + Host: String;
> + Port: Integer;
>  begin
> + index:= FNextConnect-1;
> + if (index < 0) then
> + index:= Length(FServerAddrs)+index;
> + Host:= FServerAddrs[index].Host;
> + Port:= FServerAddrs[index].Port;
> + FConnectFrame.ClearHeader;
> + FConnectFrame.Add('login', FServerAddrs[index].UserName);
> + FConnectFrame.Add('passcode', FServerAddrs[index].PassCode);
> + if Assigned(FOnSetOtherConnectHeaders) then
> + FOnSetOtherConnectHeaders(Host, Port, FConnectFrame);
>  Connect;
>  end;
>
> @@ -549,25 +584,21 @@
>  end;
>
>
> -procedure TStompClient.Open;
> +procedure TStompClient.DoOpen;
> +var
> + Host: String;
> + Port: Integer;
>  begin
> + Host:= FServerAddrs[FNextConnect].Host;
> + Port:= FServerAddrs[FNextConnect].Port;
> + FTransport.Host:= Host;
> + FTransport.Port:= Port;
> + Inc(FNextConnect);
> + FNextConnect:= FNextConnect mod Length(FServerAddrs);
>  FTransport.Open;
>  end;
>
>
> -procedure TStompClient.SetHost(const Value: String);
> -begin
> - FTransport.Host:= Value;
> -end;
> -
> -
> -
> -procedure TStompClient.SetPort(const Value: Integer);
> -begin
> - FTransport.Port:= Value;
> -end;
> -
> -
>  procedure TStompClient.OnTransportDisconnect(Sender:
> TObject;
>  Socket: TCustomWinSocket);
>  begin
> @@ -772,17 +803,174 @@
>  Send(Dest, Body, Headers, true, ReceiptID);
>  end;
>
> -procedure TStompClient.ClearAndSetConnectHeaders(Headers:
> array of TItem);
> +{
> +procedure
> TStompClient.ClearAndSetSuppConnectHeaders(Headers: array
> of TItem);
>  var
> - i: integer;
> + login: String;
> + passcode: String;
> + i: Integer;
>  begin
> + login:= FConnectFrame.GetValue('login');
> + passcode:= FConnectFrame.GetValue('passcode');
>  FConnectFrame.ClearHeader;
> + FConnectFrame.Add('login', login);
> + FConnectFrame.Add('passcode', passcode);
>  for i:= low(Headers) to high(Headers) do
>  begin
>  FConnectFrame.Add(Headers[i].Key, Headers[i].Value);
>  end;
>  end;
> +}
>
> +
> +function TStompClient.GetServerAddr: String;
> +begin
> + result:= Self.FServerAddr;
> +end;
> +
> +procedure TStompClient.SetServerAddr(const Value: String);
> +begin
> + SplitAddrs(Value);
> + Self.FServerAddr:= Value;
> +end;
> +
> +procedure TStompClient.SplitAddrs(Addr: String);
> +var
> + i, j, k: Integer;
> + sAddr: String;
> + guess, actual: Integer;
> + from: Integer;
> + buf: String;
> +begin
> + try
> + if not (Length(Addr) > 0) then
> + begin
> + raise EStomp('invalid address:'+Addr);
> + end
> + else
> + begin
> + if (Addr[Length(Addr)] <> ';') then
> + Addr:= Addr+';';
> + end;
> + guess:= 1;
> + actual:= 0;
> + from:= 1;
> + SetLength(FServerAddrs, guess);
> +
> + for i:=1 to Length(Addr) do
> + begin
> + if (Addr[i] = ';') then
> + begin
> + sAddr:= Copy(Addr, from, i-from);
> + from:= i+1;
> + if (actual > guess-1) then
> + begin
> + guess:= guess*2;
> + SetLength(FServerAddrs, guess);
> + end;
> +
> + if (sAddr[Length(sAddr)] <> ':') then
> + sAddr:= sAddr+':';
> + FServerAddrs[actual].Host:= '';
> + FServerAddrs[actual].Port:= 61613;
> + FServerAddrs[actual].UserName:= '';
> + FServerAddrs[actual].PassCode:= '';
> + buf:= '';
> + k:= 0;
> + for j:= 1 to Length(sAddr) do
> + begin
> + if (sAddr[j] <> ':') then
> + buf:= buf+sAddr[j]
> + else
> + begin
> + if (k = 0) then
> + FServerAddrs[actual].Host:= buf
> + else if (k = 1) then
> + FServerAddrs[actual].Port:= StrToInt(buf)
> + else if (k = 2) then
> + FServerAddrs[actual].UserName:= buf
> + else if (k = 3) then
> + FServerAddrs[actual].PassCode:= buf
> + else
> + raise EStomp.Create('invalid address:'+Addr);
> + inc(k);
> + buf:= '';
> + end;
> + end;
> +
> + if (FServerAddrs[actual].Host = '') then
> + raise EStomp.Create('invalid address:'+Addr);
> +
> + Inc(actual);
> + end;
> + end;
> + SetLength(FServerAddrs, actual);
> + FNextConnect:= 0;
> + except
> + on e: Exception do
> + begin
> + FServerAddrs:= nil;
> + raise EStomp.Create(e.Message);
> + end;
> + end;
> +end;
> +
> +procedure TStompClient.OnTransportError(Sender: TObject; Socket:
> TCustomWinSocket;
> + ErrorEvent: TErrorEvent; var ErrorCode: Integer);
> +begin
> + try
> + self.FTransport.Close;
> + ErrorCode:= 0;
> + except
> + end;
> +end;
> +
> +function TStompClient.GetTestConnection: boolean;
> +begin
> + result:= FTestConnection;
> +end;
> +
> +procedure TStompClient.SetTestConnection(const Value: boolean);
> +begin
> + FTestConnection:= Value;
> +end;
> +
> +function TStompClient.GetTestConnectionInterval: Integer;
> +begin
> + result:= FTimer.Interval;
> +end;
> +
> +procedure TStompClient.SetTestConnectionInterval(const
> Value: Integer);
> +begin
> + FTimer.Interval:= Value;
> +end;
> +
> +procedure TStompClient.OnTimer(Sender: TObject);
> +begin
> + if not self.FTransport.Active then
> + begin
> + self.DoOpen;
> + end;
> +end;
> +
> +procedure TStompClient.DoClose;
> +begin
> + if self.FTransport.Active then
> + Self.Disconnect;
> + self.FTransport.Close;
> +end;
> +
> +procedure TStompClient.Open;
> +begin
> + self.FTimer.Enabled:= self.FTestConnection;
> + DoOpen;
> +end;
> +
> +function TStompClient.GetServerAddrs: TAddresses;
> +begin
> + result:= FServerAddrs;
> +end;
> +
>  end.
>
>
>
>
> Added: trunk/Delphi/unit_test/TestStomp.dpr (0 => 82) ---
> trunk/Delphi/unit_test/TestStomp.dpr (rev 0)
> +++ trunk/Delphi/unit_test/TestStomp.dpr 2007-05-16
> 07:47:05 UTC (rev 82)
> @@ -0,0 +1,15 @@
> +
> +program TestStomp;
> +
> +uses
> + TestFramework,
> + GUITestRunner,
> + untTestStomp in 'untTestStomp.pas',
> + StompClient in '..\source\StompClient.pas';
> +
> +{$R *.res}
> +
> +begin
> + TGUITestRunner.runRegisteredTests;
> +end.
> +
>
>
> Added: trunk/Delphi/unit_test/dunit.ini (0 => 82) ---
> trunk/Delphi/unit_test/dunit.ini (rev 0)
> +++ trunk/Delphi/unit_test/dunit.ini 2007-05-16 07:47:05
> UTC (rev 82)
> @@ -0,0 +1,26 @@
> +[GUITestRunner Config]
> +AutoSave=1
> +Left=167
> +Top=94
> +Width=789
> +Height=540
> +Maximized=0
> +UseRegistry=0
> +ResultsPanel.Height=174
> +ErrorMessage.Height=75
> +ErrorMessage.Visible=1
> +FailureList.ColumnWidth[0]=120
> +FailureList.ColumnWidth[1]=100
> +FailureList.ColumnWidth[2]=222
> +FailureList.ColumnWidth[3]=327
> +HideTestNodesOnOpen=0
> +BreakOnFailures=0
> +FailOnNoChecksExecuted=0
> +FailOnMemoryLeaked=0
> +IgnoreSetUpTearDownLeaks=0
> +ReportMemoryLeakTypes=0
> +SelectTestedNode=1
> +WarnOnFailTestOverride=0
> +PopupX=350
> +PopupY=30
> +
>
>
> Added: trunk/Delphi/unit_test/untTestStomp.pas (0 => 82)
> --- trunk/Delphi/unit_test/untTestStomp.pas (rev 0)
> +++ trunk/Delphi/unit_test/untTestStomp.pas 2007-05-16
> 07:47:05 UTC (rev 82)
> @@ -0,0 +1,75 @@
> +unit untTestStomp;
> +
> +interface
> +
> +uses StompClient, TestFrameWork;
> +
> +type
> +
> + TTestStomp = class(TTestCase)
> + private
> + FClient: TStompClient;
> + protected
> + procedure SetUp; override;
> + procedure TearDown; override;
> + published
> + procedure testSingle;
> + procedure testMulti;
> + end;
> +
> +
> +
> +implementation
> +
> +{ TTestStomp }
> +
> +procedure TTestStomp.SetUp;
> +begin
> + FClient:= TStompClient.Create(nil);
> +end;
> +
> +procedure TTestStomp.TearDown;
> +begin
> + FClient.Free;
> +end;
> +
> +procedure TTestStomp.testMulti;
> +var
> + addrs: TAddresses;
> +begin
> + FClient.ServerAddr:=
> '127.0.0.1:61614;127.0.0.2:61613:pdv:hello;127.0.0.3:61613:man';
> + addrs:= FClient.GetServerAddrs;
> + checkEquals(3, Length(addrs));
> + checkEquals('127.0.0.1', addrs[0].Host);
> + checkEquals(61614, addrs[0].Port);
> + checkEquals('', addrs[0].UserName);
> + checkEquals('', addrs[0].PassCode);
> +
> + checkEquals('127.0.0.2', addrs[1].Host);
> + checkEquals(61613, addrs[1].Port);
> + checkEquals('pdv', addrs[1].UserName);
> + checkEquals('hello', addrs[1].PassCode);
> +
> + checkEquals('127.0.0.3', addrs[2].Host);
> + checkEquals(61613, addrs[2].Port);
> + checkEquals('man', addrs[2].UserName);
> + checkEquals('', addrs[21].PassCode);
> +end;
> +
> +procedure TTestStomp.testSingle;
> +var
> + addrs: TAddresses;
> +begin
> + FClient.ServerAddr:= '127.0.0.1:61614';
> + addrs:= FClient.GetServerAddrs;
> + checkEquals(1, Length(addrs));
> + checkEquals('127.0.0.1', addrs[0].Host);
> + checkEquals(61614, addrs[0].Port);
> + checkEquals('', addrs[0].UserName);
> + checkEquals('', addrs[0].PassCode);
> +end;
> +
> +initialization
> + RegisterTest('', TTestStomp.suite);
> +
> +end.
>
>
>  ________________________________
>
>
>  To unsubscribe from this list please visit:
>
>  http://xircles.codehaus.org/manage_email


--
James
-------
http://macstrac.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email