@@ -139,9 +139,14 @@ public void ensuresThatSetupPayloadCanBeRetained() {
139139 @ Test
140140 public void ensuresThatMonoFromRSocketConnectorCanBeUsedForMultipleSubscriptions () {
141141 Payload setupPayload = ByteBufPayload .create ("TestData" , "TestMetadata" );
142-
143142 Assertions .assertThat (setupPayload .refCnt ()).isOne ();
144143
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+
145150 TestClientTransport testClientTransport = new TestClientTransport ();
146151 Mono <RSocket > connectionMono =
147152 RSocketConnector .create ().setupPayload (setupPayload ).connect (testClientTransport );
@@ -168,6 +173,15 @@ public void ensuresThatMonoFromRSocketConnectorCanBeUsedForMultipleSubscriptions
168173 .expectComplete ()
169174 .verify (Duration .ofMillis (100 ));
170175
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+
171185 Assertions .assertThat (testClientTransport .testConnection ().getSent ())
172186 .hasSize (1 )
173187 .allMatch (
@@ -176,7 +190,11 @@ public void ensuresThatMonoFromRSocketConnectorCanBeUsedForMultipleSubscriptions
176190 return payload .getDataUtf8 ().equals ("TestData" )
177191 && payload .getMetadataUtf8 ().equals ("TestMetadata" );
178192 })
179- .allMatch (ReferenceCounted ::release );
193+ .allMatch (
194+ byteBuf -> {
195+ System .out .println ("calling release " + byteBuf .refCnt ());
196+ return byteBuf .release ();
197+ });
180198 Assertions .assertThat (setupPayload .refCnt ()).isZero ();
181199 }
182200
0 commit comments