THRIFT-5012 Centralize configuration aspects into a commonly used configuration object [ci skip]
Client: Delphi
Patch: Jens Geyer
This closes #1955
diff --git a/lib/delphi/test/Performance/PerfTests.pas b/lib/delphi/test/Performance/PerfTests.pas
index 2c820b1..e485212 100644
--- a/lib/delphi/test/Performance/PerfTests.pas
+++ b/lib/delphi/test/Performance/PerfTests.pas
@@ -21,6 +21,7 @@
uses
Windows, Classes, SysUtils,
Thrift.Collections,
+ Thrift.Configuration,
Thrift.Test,
Thrift.Protocol,
Thrift.Protocol.JSON,
@@ -34,9 +35,10 @@
type
TPerformanceTests = class
strict private
- Testdata : ICrazyNesting;
- MemBuffer : TMemoryStream;
- Transport : ITransport;
+ FTestdata : ICrazyNesting;
+ FMemBuffer : TMemoryStream;
+ FTransport : ITransport;
+ FConfig : IThriftConfiguration;
procedure ProtocolPeformanceTest;
procedure RunTest( const ptyp : TKnownProtocol; const layered : TLayeredTransport);
@@ -74,7 +76,7 @@
var layered : TLayeredTransport;
begin
Console.WriteLine('Setting up for ProtocolPeformanceTest ...');
- Testdata := TestDataFactory.CreateCrazyNesting();
+ FTestdata := TestDataFactory.CreateCrazyNesting();
for layered := Low(TLayeredTransport) to High(TLayeredTransport) do begin
RunTest( TKnownProtocol.prot_Binary, layered);
@@ -91,10 +93,12 @@
begin
QueryPerformanceFrequency( freq);
+ FConfig := TThriftConfigurationImpl.Create;
+
proto := GenericProtocolFactory( ptyp, layered, TRUE);
QueryPerformanceCounter( start);
- Testdata.Write(proto);
- Transport.Flush;
+ FTestdata.Write(proto);
+ FTransport.Flush;
QueryPerformanceCounter( stop);
Console.WriteLine( Format('RunTest(%s): write = %d msec', [
GetProtocolTransportName(ptyp,layered),
@@ -121,24 +125,24 @@
begin
// read happens after write here, so let's take over the written bytes
newBuf := TMemoryStream.Create;
- if not forWrite then newBuf.CopyFrom( MemBuffer, COPY_ENTIRE_STREAM);
- MemBuffer := newBuf;
- MemBuffer.Position := 0;
+ if not forWrite then newBuf.CopyFrom( FMemBuffer, COPY_ENTIRE_STREAM);
+ FMemBuffer := newBuf;
+ FMemBuffer.Position := 0;
// layered transports anyone?
stream := TThriftStreamAdapterDelphi.Create( newBuf, TRUE);
if forWrite
- then trans := TStreamTransportImpl.Create( nil, stream)
- else trans := TStreamTransportImpl.Create( stream, nil);
+ then trans := TStreamTransportImpl.Create( nil, stream, FConfig)
+ else trans := TStreamTransportImpl.Create( stream, nil, FConfig);
case layered of
- trns_Framed : Transport := TFramedTransportImpl.Create( trans);
- trns_Buffered : Transport := TBufferedTransportImpl.Create( trans);
+ trns_Framed : FTransport := TFramedTransportImpl.Create( trans);
+ trns_Buffered : FTransport := TBufferedTransportImpl.Create( trans);
else
- Transport := trans;
+ FTransport := trans;
end;
- if not Transport.IsOpen
- then Transport.Open;
+ if not FTransport.IsOpen
+ then FTransport.Open;
case ptyp of
prot_Binary : result := TBinaryProtocolImpl.Create(trans);
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index 3562dab..1579bd5 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -53,6 +53,8 @@
Thrift.Test,
Thrift.WinHTTP,
Thrift.Utils,
+
+ Thrift.Configuration,
Thrift.Collections;
type
@@ -122,7 +124,7 @@
procedure InitializeProtocolTransportStack;
procedure ShutdownProtocolTransportStack;
- function InitializeHttpTransport( const aTimeoutSetting : Integer) : IHTTPClient;
+ function InitializeHttpTransport( const aTimeoutSetting : Integer; const aConfig : IThriftConfiguration = nil) : IHTTPClient;
procedure JSONProtocolReadWriteTest;
function PrepareBinaryData( aRandomDist : Boolean; aSize : TTestSize) : TBytes;
@@ -1068,6 +1070,7 @@
var prot : IProtocol;
stm : TStringStream;
list : TThriftList;
+ config : IThriftConfiguration;
binary, binRead, emptyBinary : TBytes;
i,iErr : Integer;
const
@@ -1089,6 +1092,8 @@
try
StartTestGroup( 'JsonProtocolTest', test_Unknown);
+ config := TThriftConfigurationImpl.Create;
+
// prepare binary data
binary := PrepareBinaryData( FALSE, Normal);
SetLength( emptyBinary, 0); // empty binary data block
@@ -1096,7 +1101,7 @@
// output setup
prot := TJSONProtocolImpl.Create(
TStreamTransportImpl.Create(
- nil, TThriftStreamAdapterDelphi.Create( stm, FALSE)));
+ nil, TThriftStreamAdapterDelphi.Create( stm, FALSE), config));
// write
Init( list, TType.String_, 9);
@@ -1119,7 +1124,7 @@
stm.Position := 0;
prot := TJSONProtocolImpl.Create(
TStreamTransportImpl.Create(
- TThriftStreamAdapterDelphi.Create( stm, FALSE), nil));
+ TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config));
// read and compare
list := prot.ReadListBegin;
@@ -1161,7 +1166,7 @@
stm.Position := 0;
prot := TJSONProtocolImpl.Create(
TStreamTransportImpl.Create(
- TThriftStreamAdapterDelphi.Create( stm, FALSE), nil));
+ TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config));
Expect( prot.ReadString = SOLIDUS_EXCPECTED, 'Solidus encoding');
@@ -1172,12 +1177,12 @@
stm.Size := 0;
prot := TJSONProtocolImpl.Create(
TStreamTransportImpl.Create(
- nil, TThriftStreamAdapterDelphi.Create( stm, FALSE)));
+ nil, TThriftStreamAdapterDelphi.Create( stm, FALSE), config));
prot.WriteString( G_CLEF_AND_CYRILLIC_TEXT);
stm.Position := 0;
prot := TJSONProtocolImpl.Create(
TStreamTransportImpl.Create(
- TThriftStreamAdapterDelphi.Create( stm, FALSE), nil));
+ TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config));
Expect( prot.ReadString = G_CLEF_AND_CYRILLIC_TEXT, 'Writing JSON with chars > 8 bit');
// Widechars should work with hex-encoding too. Do they?
@@ -1187,7 +1192,7 @@
stm.Position := 0;
prot := TJSONProtocolImpl.Create(
TStreamTransportImpl.Create(
- TThriftStreamAdapterDelphi.Create( stm, FALSE), nil));
+ TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config));
Expect( prot.ReadString = G_CLEF_AND_CYRILLIC_TEXT, 'Reading JSON with chars > 8 bit');
@@ -1330,7 +1335,7 @@
end;
-function TClientThread.InitializeHttpTransport( const aTimeoutSetting : Integer) : IHTTPClient;
+function TClientThread.InitializeHttpTransport( const aTimeoutSetting : Integer; const aConfig : IThriftConfiguration) : IHTTPClient;
var sUrl : string;
comps : URL_COMPONENTS;
dwChars : DWORD;
@@ -1367,8 +1372,8 @@
Console.WriteLine('Target URL: '+sUrl);
case FSetup.endpoint of
- trns_MsxmlHttp : result := TMsxmlHTTPClientImpl.Create( sUrl);
- trns_WinHttp : result := TWinHTTPClientImpl.Create( sUrl);
+ trns_MsxmlHttp : result := TMsxmlHTTPClientImpl.Create( sUrl, aConfig);
+ trns_WinHttp : result := TWinHTTPClientImpl.Create( sUrl, aConfig);
else
raise Exception.Create(ENDPOINT_TRANSPORTS[FSetup.endpoint]+' unhandled case');
end;
@@ -1396,7 +1401,7 @@
case FSetup.endpoint of
trns_Sockets: begin
Console.WriteLine('Using sockets ('+FSetup.host+' port '+IntToStr(FSetup.port)+')');
- streamtrans := TSocketImpl.Create( FSetup.host, FSetup.port, DEFAULT_THRIFT_TIMEOUT);
+ streamtrans := TSocketImpl.Create( FSetup.host, FSetup.port);
FTransport := streamtrans;
end;
@@ -1417,7 +1422,7 @@
end;
trns_AnonPipes: begin
- streamtrans := TAnonymousPipeTransportImpl.Create( FSetup.hAnonRead, FSetup.hAnonWrite, FALSE);
+ streamtrans := TAnonymousPipeTransportImpl.Create( FSetup.hAnonRead, FSetup.hAnonWrite, FALSE, PIPE_TIMEOUT);
FTransport := streamtrans;
end;
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index da804fd..bbc798b 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -36,6 +36,7 @@
Thrift.Protocol.JSON,
Thrift.Protocol.Compact,
Thrift.Collections,
+ Thrift.Configuration,
Thrift.Utils,
Thrift.Test,
Thrift,
@@ -593,7 +594,7 @@
trns_NamedPipes : begin
Console.WriteLine('- named pipe ('+sPipeName+')');
- namedpipe := TNamedPipeServerTransportImpl.Create( sPipeName, 4096, PIPE_UNLIMITED_INSTANCES);
+ namedpipe := TNamedPipeServerTransportImpl.Create( sPipeName, 4096, PIPE_UNLIMITED_INSTANCES, INFINITE);
servertrans := namedpipe;
end;
@@ -614,7 +615,7 @@
if (trns_Framed in layered) then begin
Console.WriteLine('- framed transport');
- TransportFactory := TFramedTransportImpl.TFactory.Create
+ TransportFactory := TFramedTransportImpl.TFactory.Create;
end
else begin
TransportFactory := TTransportFactoryImpl.Create;
diff --git a/lib/delphi/test/client.dpr b/lib/delphi/test/client.dpr
index 83727f6..d4875b8 100644
--- a/lib/delphi/test/client.dpr
+++ b/lib/delphi/test/client.dpr
@@ -31,6 +31,7 @@
Thrift in '..\src\Thrift.pas',
Thrift.Transport in '..\src\Thrift.Transport.pas',
Thrift.Socket in '..\src\Thrift.Socket.pas',
+ Thrift.Configuration in '..\src\Thrift.Configuration.pas',
Thrift.Exception in '..\src\Thrift.Exception.pas',
Thrift.Transport.Pipes in '..\src\Thrift.Transport.Pipes.pas',
Thrift.Transport.WinHTTP in '..\src\Thrift.Transport.WinHTTP.pas',
diff --git a/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas b/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas
index 35fdf6f..4b6a0a2 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas
+++ b/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas
@@ -35,6 +35,7 @@
Thrift.Transport,
Thrift.Stream,
Thrift.Collections,
+ Thrift.Configuration,
Benchmark, // in gen-delphi folder
Aggr, // in gen-delphi folder
Multiplex.Test.Common;
@@ -93,8 +94,10 @@
procedure TTestClient.Setup;
var trans : ITransport;
+ config : IThriftConfiguration;
begin
- trans := TSocketImpl.Create( 'localhost', 9090);
+ config := TThriftConfigurationImpl.Create;
+ trans := TSocketImpl.Create( 'localhost', 9090, DEFAULT_THRIFT_TIMEOUT, config);
trans := TFramedTransportImpl.Create( trans);
trans.Open;
FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE);
diff --git a/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas b/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
index 3860f5a..a23ff37 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
+++ b/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
@@ -35,6 +35,7 @@
Thrift.Protocol.Multiplex,
Thrift.Processor.Multiplex,
Thrift.Collections,
+ Thrift.Configuration,
Thrift.Utils,
Thrift,
Benchmark, // in gen-delphi folder
@@ -156,11 +157,14 @@
aggrProcessor : IProcessor;
multiplex : IMultiplexedProcessor;
ServerEngine : IServer;
+ config : IThriftConfiguration;
begin
try
+ config := TThriftConfigurationImpl.Create;
+
// create protocol factory, default to BinaryProtocol
ProtocolFactory := TBinaryProtocolImpl.TFactory.Create( TRUE, TRUE);
- servertrans := TServerSocketImpl.Create( 9090, 0, FALSE);
+ servertrans := TServerSocketImpl.Create( 9090, DEFAULT_THRIFT_TIMEOUT, FALSE, config);
TransportFactory := TFramedTransportImpl.TFactory.Create;
benchHandler := TBenchmarkServiceImpl.Create;
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr b/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
index a57e93a..19f8f6a 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
@@ -33,6 +33,7 @@
Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
Thrift.Protocol.Multiplex in '..\..\src\Thrift.Protocol.Multiplex.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Stream in '..\..\src\Thrift.Stream.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr b/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
index 81ed3dd..307a9c2 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
@@ -33,6 +33,7 @@
Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
Thrift.Protocol.Multiplex in '..\..\src\Thrift.Protocol.Multiplex.pas',
Thrift.Processor.Multiplex in '..\..\src\Thrift.Processor.Multiplex.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
diff --git a/lib/delphi/test/serializer/TestSerializer.Tests.pas b/lib/delphi/test/serializer/TestSerializer.Tests.pas
index fe69f4e..83d67b1 100644
--- a/lib/delphi/test/serializer/TestSerializer.Tests.pas
+++ b/lib/delphi/test/serializer/TestSerializer.Tests.pas
@@ -33,6 +33,7 @@
Thrift.Protocol.JSON,
Thrift.Protocol.Compact,
Thrift.Collections,
+ Thrift.Configuration,
Thrift.Server,
Thrift.Utils,
Thrift.Serializer,
@@ -283,8 +284,12 @@
class function TTestSerializer.Serialize(const input : IBase; const factory : TFactoryPair) : TBytes;
var serial : TSerializer;
+ config : IThriftConfiguration;
begin
- serial := TSerializer.Create( factory.prot, factory.trans);
+ config := TThriftConfigurationImpl.Create;
+ config.MaxMessageSize := 0; // we don't read anything here
+
+ serial := TSerializer.Create( factory.prot, factory.trans, config);
try
result := serial.Serialize( input);
finally
@@ -295,8 +300,12 @@
class procedure TTestSerializer.Serialize(const input : IBase; const factory : TFactoryPair; const aStream : TStream);
var serial : TSerializer;
+ config : IThriftConfiguration;
begin
- serial := TSerializer.Create( factory.prot, factory.trans);
+ config := TThriftConfigurationImpl.Create;
+ config.MaxMessageSize := 0; // we don't read anything here
+
+ serial := TSerializer.Create( factory.prot, factory.trans, config);
try
serial.Serialize( input, aStream);
finally
@@ -307,8 +316,12 @@
class procedure TTestSerializer.Deserialize( const input : TBytes; const target : IBase; const factory : TFactoryPair);
var serial : TDeserializer;
+ config : IThriftConfiguration;
begin
- serial := TDeserializer.Create( factory.prot, factory.trans, Length(input));
+ config := TThriftConfigurationImpl.Create;
+ config.MaxMessageSize := Length(input);
+
+ serial := TDeserializer.Create( factory.prot, factory.trans, config);
try
serial.Deserialize( input, target);
ValidateReadToEnd( input, serial);
@@ -320,8 +333,12 @@
class procedure TTestSerializer.Deserialize( const input : TStream; const target : IBase; const factory : TFactoryPair);
var serial : TDeserializer;
+ config : IThriftConfiguration;
begin
- serial := TDeserializer.Create( factory.prot, factory.trans, input.Size);
+ config := TThriftConfigurationImpl.Create;
+ config.MaxMessageSize := input.Size;
+
+ serial := TDeserializer.Create( factory.prot, factory.trans, config);
try
serial.Deserialize( input, target);
ValidateReadToEnd( input, serial);
diff --git a/lib/delphi/test/serializer/TestSerializer.dpr b/lib/delphi/test/serializer/TestSerializer.dpr
index bb4cc89..0620014 100644
--- a/lib/delphi/test/serializer/TestSerializer.dpr
+++ b/lib/delphi/test/serializer/TestSerializer.dpr
@@ -34,6 +34,7 @@
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Protocol.Compact in '..\..\src\Thrift.Protocol.Compact.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.Serializer in '..\..\src\Thrift.Serializer.pas',
@@ -42,8 +43,8 @@
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
System_,
DebugProtoTest,
- TestSerializer.Tests,
- TestSerializer.Data;
+ TestSerializer.Tests in 'TestSerializer.Tests.pas',
+ TestSerializer.Data in 'TestSerializer.Data.pas';
var test : TTestSerializer;
diff --git a/lib/delphi/test/server.dpr b/lib/delphi/test/server.dpr
index 9731dd4..954d0b6 100644
--- a/lib/delphi/test/server.dpr
+++ b/lib/delphi/test/server.dpr
@@ -37,6 +37,7 @@
Thrift.Protocol.Multiplex in '..\src\Thrift.Protocol.Multiplex.pas',
Thrift.Processor.Multiplex in '..\src\Thrift.Processor.Multiplex.pas',
Thrift.Collections in '..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\src\Thrift.Configuration.pas',
Thrift.Server in '..\src\Thrift.Server.pas',
Thrift.TypeRegistry in '..\src\Thrift.TypeRegistry.pas',
Thrift.Utils in '..\src\Thrift.Utils.pas',
diff --git a/lib/delphi/test/skip/skiptest_version1.dpr b/lib/delphi/test/skip/skiptest_version1.dpr
index 0bfe96f..c97e50b 100644
--- a/lib/delphi/test/skip/skiptest_version1.dpr
+++ b/lib/delphi/test/skip/skiptest_version1.dpr
@@ -31,6 +31,7 @@
Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.WinHTTP in '..\..\src\Thrift.WinHTTP.pas',
@@ -70,8 +71,8 @@
begin
adapt := TThriftStreamAdapterDelphi.Create( stm, FALSE);
if aForInput
- then trans := TStreamTransportImpl.Create( adapt, nil)
- else trans := TStreamTransportImpl.Create( nil, adapt);
+ then trans := TStreamTransportImpl.Create( adapt, nil, TThriftConfigurationImpl.Create)
+ else trans := TStreamTransportImpl.Create( nil, adapt, TThriftConfigurationImpl.Create);
result := protfact.GetProtocol( trans);
end;
diff --git a/lib/delphi/test/skip/skiptest_version2.dpr b/lib/delphi/test/skip/skiptest_version2.dpr
index 7893748..07c2c9a 100644
--- a/lib/delphi/test/skip/skiptest_version2.dpr
+++ b/lib/delphi/test/skip/skiptest_version2.dpr
@@ -31,6 +31,7 @@
Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.WinHTTP in '..\..\src\Thrift.WinHTTP.pas',
@@ -96,8 +97,8 @@
begin
adapt := TThriftStreamAdapterDelphi.Create( stm, FALSE);
if aForInput
- then trans := TStreamTransportImpl.Create( adapt, nil)
- else trans := TStreamTransportImpl.Create( nil, adapt);
+ then trans := TStreamTransportImpl.Create( adapt, nil, TThriftConfigurationImpl.Create)
+ else trans := TStreamTransportImpl.Create( nil, adapt, TThriftConfigurationImpl.Create);
result := protfact.GetProtocol( trans);
end;
diff --git a/lib/delphi/test/typeregistry/TestTypeRegistry.dpr b/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
index fd5e3dd..31c0fb2 100644
--- a/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
+++ b/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
@@ -30,6 +30,7 @@
Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
Thrift.Server in '..\..\src\Thrift.Server.pas',
Thrift.Utils in '..\..\src\Thrift.Utils.pas',
Thrift.Serializer in '..\..\src\Thrift.Serializer.pas',