@@ -67,5 +67,76 @@ public async Task TestQueuePurgeAsync()
67
67
Assert . True ( await publishSyncSource . Task ) ;
68
68
Assert . Equal ( ( uint ) messageCount , await _channel . QueuePurgeAsync ( q ) ) ;
69
69
}
70
+
71
+ [ Fact ]
72
+ public async Task TestNonCopyingBody ( )
73
+ {
74
+ const int size = 1024 ;
75
+
76
+ QueueDeclareOk q = await _channel . QueueDeclareAsync ( string . Empty , false , false , true , false , null ) ;
77
+ byte [ ] body = GetRandomBody ( size ) ;
78
+
79
+ uint rentedBytes ;
80
+
81
+ using ( var result = await TrackRentedBytes ( ) )
82
+ {
83
+ await _channel . BasicPublishAsync ( string . Empty , q , body , copyBody : false ) ;
84
+ rentedBytes = result . RentedBytes ;
85
+ }
86
+
87
+ Assert . Equal ( ( uint ) 1 , await _channel . QueuePurgeAsync ( q ) ) ;
88
+
89
+ // It is expected that the rented bytes is smaller than the size of the body
90
+ // since we're not copying the body. Only the frame headers are rented.
91
+ Assert . True ( rentedBytes < size ) ;
92
+ }
93
+
94
+ [ Fact ]
95
+ public async Task TestCopyingBody ( )
96
+ {
97
+ const int size = 1024 ;
98
+
99
+ QueueDeclareOk q = await _channel . QueueDeclareAsync ( string . Empty , false , false , true , false , null ) ;
100
+ byte [ ] body = GetRandomBody ( size ) ;
101
+
102
+ uint rentedBytes ;
103
+
104
+ using ( var result = await TrackRentedBytes ( ) )
105
+ {
106
+ await _channel . BasicPublishAsync ( string . Empty , q , body , copyBody : true ) ;
107
+ rentedBytes = result . RentedBytes ;
108
+ }
109
+
110
+ Assert . Equal ( ( uint ) 1 , await _channel . QueuePurgeAsync ( q ) ) ;
111
+
112
+ // It is expected that the rented bytes is larger than the size of the body
113
+ // since the body is copied with the frame headers.
114
+ Assert . True ( rentedBytes >= size ) ;
115
+ }
116
+
117
+ [ Fact ]
118
+ public async Task TestDefaultCopyingBody ( )
119
+ {
120
+ Assert . Equal ( int . MaxValue , _conn . CopyBodyToMemoryThreshold ) ;
121
+
122
+ const int size = 1024 ;
123
+
124
+ QueueDeclareOk q = await _channel . QueueDeclareAsync ( string . Empty , false , false , true , false , null ) ;
125
+ byte [ ] body = GetRandomBody ( size ) ;
126
+
127
+ uint rentedBytes ;
128
+
129
+ using ( var result = await TrackRentedBytes ( ) )
130
+ {
131
+ await _channel . BasicPublishAsync ( string . Empty , q , body , copyBody : true ) ;
132
+ rentedBytes = result . RentedBytes ;
133
+ }
134
+
135
+ Assert . Equal ( ( uint ) 1 , await _channel . QueuePurgeAsync ( q ) ) ;
136
+
137
+ // It is expected that the rented bytes is larger than the size of the body
138
+ // since the body is copied with the frame headers.
139
+ Assert . True ( rentedBytes >= size ) ;
140
+ }
70
141
}
71
142
}
0 commit comments