11using System ;
2+ using System . IO ;
23using System . Net ;
34using System . Net . Sockets ;
45using System . Text ;
@@ -40,8 +41,8 @@ public void SendLineExceedsBuffer()
4041 srv . AcceptAsync ( ) ;
4142
4243 using var ls = new LineTcpSender ( IPAddress . Loopback . ToString ( ) , _port , 25 ) ;
43- var lineCount = 50 ;
44- var expected = "metric\\ name,t\\ a\\ g=v\\ alu\\ ,\\ e number=10i,db\\ l=123.12,string=\" -=\\ \" \" ,привед =\" медвед\" 1000000000\n " ;
44+ var lineCount = 500 ;
45+ var expected = "metric\\ name,t\\ a\\ g=v\\ alu\\ ,\\ e number=10i,db\\ l=123.12,string=\" -=\\ \" \" ,при \\ вед =\" медвед\" 1000000000\n " ;
4546 var totalExpectedSb = new StringBuilder ( ) ;
4647 for ( int i = 0 ; i < lineCount ; i ++ )
4748 {
@@ -50,7 +51,7 @@ public void SendLineExceedsBuffer()
5051 . Field ( "number" , 10 )
5152 . Field ( "db l" , 123.12 )
5253 . Field ( "string" , " -=\" " )
53- . Field ( "привед " , "медвед" )
54+ . Field ( "при вед " , "медвед" )
5455 . At ( new DateTime ( 1970 , 01 , 01 , 0 , 0 , 1 ) ) ;
5556 totalExpectedSb . Append ( expected ) ;
5657 }
@@ -78,6 +79,31 @@ public void SendNegativeLongAndDouble()
7879 var expected = "neg\\ \\ name number1=-9223372036854775807i,number2=9223372036854775807i,number3=-1.7976931348623157E+308,number4=1.7976931348623157E+308\n " ;
7980 WaitAssert ( srv , expected ) ;
8081 }
82+
83+ [ Test ]
84+ public void SendMillionToFile ( )
85+ {
86+ using var srv = CreateTcpListener ( _port ) ;
87+ srv . AcceptAsync ( ) ;
88+
89+ var nowMillisecond = DateTime . Now . Millisecond ;
90+ var metric = "metric_name" + nowMillisecond ;
91+
92+ using var ls = new LineTcpSender ( IPAddress . Loopback . ToString ( ) , _port , 2048 ) ;
93+ for ( int i = 0 ; i < 1E6 ; i ++ )
94+ {
95+ ls . Metric ( metric )
96+ . Tag ( "nopoint" , "tag" + i % 100 )
97+ . Field ( "counter" , i * 1111.1 )
98+ . Field ( "int" , i )
99+ . Field ( "привед" , "мед вед" )
100+ . At ( new DateTime ( 2021 , 1 , 1 , ( i / 360 / 1000 ) % 60 , ( i / 60 / 1000 ) % 60 , ( i / 1000 ) % 60 , i % 1000 ) ) ;
101+ }
102+ ls . Flush ( ) ;
103+
104+ File . WriteAllText ( $ "out-{ nowMillisecond } .txt", srv . GetTextReceived ( ) ) ;
105+ }
106+
81107
82108 private static void WaitAssert ( DummyIlpServer srv , string expected )
83109 {
@@ -177,8 +203,8 @@ private class DummyIlpServer : IDisposable
177203 private readonly TcpListener _server ;
178204 private readonly byte [ ] _buffer = new byte [ 2048 ] ;
179205 private readonly CancellationTokenSource _cancellationTokenSource = new ( ) ;
180- private readonly StringBuilder _request = new ( ) ;
181- private volatile int _totalReceived = 0 ;
206+ private volatile int _totalReceived ;
207+ private readonly MemoryStream _received = new ( ) ;
182208
183209 public DummyIlpServer ( int port )
184210 {
@@ -211,9 +237,8 @@ private async Task SaveData(Socket connection)
211237 int received = await connection . ReceiveAsync ( _buffer , SocketFlags . None , _cancellationTokenSource . Token ) ;
212238 if ( received > 0 )
213239 {
214- var value = Encoding . UTF8 . GetString ( _buffer , 0 , received ) ;
215- _request . Append ( value ) ;
216- _totalReceived += value . Length ;
240+ _received . Write ( _buffer , 0 , received ) ;
241+ _totalReceived += received ;
217242 }
218243 }
219244 }
@@ -228,7 +253,7 @@ public void Dispose()
228253
229254 public string GetTextReceived ( )
230255 {
231- return _request . ToString ( ) ;
256+ return Encoding . UTF8 . GetString ( _received . GetBuffer ( ) , 0 , ( int ) _received . Length ) ;
232257 }
233258 }
234259 }
0 commit comments