@@ -139,9 +139,14 @@ public void ensuresThatSetupPayloadCanBeRetained() {
139
139
@ Test
140
140
public void ensuresThatMonoFromRSocketConnectorCanBeUsedForMultipleSubscriptions () {
141
141
Payload setupPayload = ByteBufPayload .create ("TestData" , "TestMetadata" );
142
-
143
142
Assertions .assertThat (setupPayload .refCnt ()).isOne ();
144
143
144
+ // Keep the data and metadata around so we can try changing them independently
145
+ ByteBuf dataBuf = setupPayload .data ();
146
+ ByteBuf metadataBuf = setupPayload .metadata ();
147
+ dataBuf .retain ();
148
+ metadataBuf .retain ();
149
+
145
150
TestClientTransport testClientTransport = new TestClientTransport ();
146
151
Mono <RSocket > connectionMono =
147
152
RSocketConnector .create ().setupPayload (setupPayload ).connect (testClientTransport );
@@ -168,6 +173,15 @@ public void ensuresThatMonoFromRSocketConnectorCanBeUsedForMultipleSubscriptions
168
173
.expectComplete ()
169
174
.verify (Duration .ofMillis (100 ));
170
175
176
+ // Changing the original data and metadata should not impact the SetupPayload
177
+ dataBuf .writerIndex (dataBuf .readerIndex ());
178
+ dataBuf .writeChar ('d' );
179
+ dataBuf .release ();
180
+
181
+ metadataBuf .writerIndex (metadataBuf .readerIndex ());
182
+ metadataBuf .writeChar ('m' );
183
+ metadataBuf .release ();
184
+
171
185
Assertions .assertThat (testClientTransport .testConnection ().getSent ())
172
186
.hasSize (1 )
173
187
.allMatch (
@@ -176,7 +190,11 @@ public void ensuresThatMonoFromRSocketConnectorCanBeUsedForMultipleSubscriptions
176
190
return payload .getDataUtf8 ().equals ("TestData" )
177
191
&& payload .getMetadataUtf8 ().equals ("TestMetadata" );
178
192
})
179
- .allMatch (ReferenceCounted ::release );
193
+ .allMatch (
194
+ byteBuf -> {
195
+ System .out .println ("calling release " + byteBuf .refCnt ());
196
+ return byteBuf .release ();
197
+ });
180
198
Assertions .assertThat (setupPayload .refCnt ()).isZero ();
181
199
}
182
200
0 commit comments