| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
package org.apache.qpid.proton.systemtests; |
| 20 |
|
| 21 |
import static java.util.EnumSet.of; |
| 22 |
import static org.apache.qpid.proton.engine.EndpointState.ACTIVE; |
| 23 |
import static org.apache.qpid.proton.engine.EndpointState.UNINITIALIZED; |
| 24 |
import static org.apache.qpid.proton.systemtests.TestLoggingHelper.bold; |
| 25 |
import static org.junit.Assert.assertEquals; |
| 26 |
import static org.junit.Assert.assertFalse; |
| 27 |
import static org.junit.Assert.assertNotNull; |
| 28 |
import static org.junit.Assert.assertNull; |
| 29 |
import static org.junit.Assert.assertTrue; |
| 30 |
|
| 31 |
import java.nio.charset.StandardCharsets; |
| 32 |
import java.util.Arrays; |
| 33 |
import java.util.HashMap; |
| 34 |
import java.util.Map; |
| 35 |
import java.util.logging.Logger; |
| 36 |
|
| 37 |
import org.apache.qpid.proton.Proton; |
| 38 |
import org.apache.qpid.proton.amqp.Symbol; |
| 39 |
import org.apache.qpid.proton.amqp.UnsignedLong; |
| 40 |
import org.apache.qpid.proton.amqp.messaging.AmqpValue; |
| 41 |
import org.apache.qpid.proton.amqp.messaging.Source; |
| 42 |
import org.apache.qpid.proton.amqp.messaging.Target; |
| 43 |
import org.apache.qpid.proton.amqp.transport.ReceiverSettleMode; |
| 44 |
import org.apache.qpid.proton.amqp.transport.SenderSettleMode; |
| 45 |
import org.apache.qpid.proton.engine.Connection; |
| 46 |
import org.apache.qpid.proton.engine.Delivery; |
| 47 |
import org.apache.qpid.proton.engine.Link; |
| 48 |
import org.apache.qpid.proton.engine.Receiver; |
| 49 |
import org.apache.qpid.proton.engine.Sender; |
| 50 |
import org.apache.qpid.proton.engine.Session; |
| 51 |
import org.apache.qpid.proton.engine.Transport; |
| 52 |
import org.apache.qpid.proton.message.Message; |
| 53 |
import org.junit.Test; |
| 54 |
|
| 55 |
public class LinkTest extends EngineTestBase |
| 56 |
{ |
| 57 |
private static final Logger LOGGER = Logger.getLogger(LinkTest.class.getName()); |
| 58 |
|
| 59 |
private static final int BUFFER_SIZE = 4096; |
| 60 |
|
| 61 |
private static final Symbol RCV_PROP = Symbol.valueOf("ReceiverPropName"); |
| 62 |
private static final Integer RCV_PROP_VAL = 1234; |
| 63 |
private static final Symbol SND_PROP = Symbol.valueOf("SenderPropName"); |
| 64 |
private static final Integer SND_PROP_VAL = 5678; |
| 65 |
private static final UnsignedLong CLIENT_MAX_MSG_SIZE = UnsignedLong.valueOf(54321); |
| 66 |
private static final UnsignedLong SERVER_MAX_MSG_SIZE = UnsignedLong.valueOf(12345); |
| 67 |
|
| 68 |
private final String _sourceAddress = getServer().containerId + "-link1-source"; |
| 69 |
|
| 70 |
@Test |
| 71 |
public void testCapabilities() throws Exception |
| 72 |
{ |
| 73 |
final Symbol recvOfferedCap = Symbol.valueOf("recvOfferedCapability"); |
| 74 |
final Symbol recvDesiredCap = Symbol.valueOf("recvDesiredCapability"); |
| 75 |
final Symbol senderOfferedCap = Symbol.valueOf("senderOfferedCapability"); |
| 76 |
final Symbol senderDesiredCap = Symbol.valueOf("senderDesiredCapability"); |
| 77 |
|
| 78 |
Symbol[] clientOfferedCapabilities = new Symbol[] { recvOfferedCap }; |
| 79 |
Symbol[] clientDesiredCapabilities = new Symbol[] { recvDesiredCap }; |
| 80 |
|
| 81 |
Symbol[] serverOfferedCapabilities = new Symbol[] { senderOfferedCap }; |
| 82 |
Symbol[] serverDesiredCapabilities = new Symbol[] { senderDesiredCap }; |
| 83 |
|
| 84 |
LOGGER.fine(bold("======== About to create transports")); |
| 85 |
|
| 86 |
getClient().transport = Proton.transport(); |
| 87 |
ProtocolTracerEnabler.setProtocolTracer(getClient().transport, TestLoggingHelper.CLIENT_PREFIX); |
| 88 |
|
| 89 |
getServer().transport = Proton.transport(); |
| 90 |
ProtocolTracerEnabler.setProtocolTracer(getServer().transport, " " + TestLoggingHelper.SERVER_PREFIX); |
| 91 |
|
| 92 |
doOutputInputCycle(); |
| 93 |
|
| 94 |
getClient().connection = Proton.connection(); |
| 95 |
getClient().transport.bind(getClient().connection); |
| 96 |
|
| 97 |
getServer().connection = Proton.connection(); |
| 98 |
getServer().transport.bind(getServer().connection); |
| 99 |
|
| 100 |
LOGGER.fine(bold("======== About to open connections")); |
| 101 |
getClient().connection.open(); |
| 102 |
getServer().connection.open(); |
| 103 |
|
| 104 |
doOutputInputCycle(); |
| 105 |
|
| 106 |
LOGGER.fine(bold("======== About to open sessions")); |
| 107 |
getClient().session = getClient().connection.session(); |
| 108 |
getClient().session.open(); |
| 109 |
|
| 110 |
pumpClientToServer(); |
| 111 |
|
| 112 |
getServer().session = getServer().connection.sessionHead(of(UNINITIALIZED), of(ACTIVE)); |
| 113 |
assertEndpointState(getServer().session, UNINITIALIZED, ACTIVE); |
| 114 |
|
| 115 |
getServer().session.open(); |
| 116 |
assertEndpointState(getServer().session, ACTIVE, ACTIVE); |
| 117 |
|
| 118 |
pumpServerToClient(); |
| 119 |
assertEndpointState(getClient().session, ACTIVE, ACTIVE); |
| 120 |
|
| 121 |
LOGGER.fine(bold("======== About to create reciever")); |
| 122 |
|
| 123 |
getClient().source = new Source(); |
| 124 |
getClient().source.setAddress(_sourceAddress); |
| 125 |
|
| 126 |
getClient().target = new Target(); |
| 127 |
getClient().target.setAddress(null); |
| 128 |
|
| 129 |
getClient().receiver = getClient().session.receiver("link1"); |
| 130 |
getClient().receiver.setTarget(getClient().target); |
| 131 |
getClient().receiver.setSource(getClient().source); |
| 132 |
|
| 133 |
getClient().receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST); |
| 134 |
getClient().receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED); |
| 135 |
|
| 136 |
// Set the client receivers capabilities |
| 137 |
getClient().receiver.setOfferedCapabilities(clientOfferedCapabilities); |
| 138 |
getClient().receiver.setDesiredCapabilities(clientDesiredCapabilities); |
| 139 |
|
| 140 |
assertEndpointState(getClient().receiver, UNINITIALIZED, UNINITIALIZED); |
| 141 |
|
| 142 |
getClient().receiver.open(); |
| 143 |
assertEndpointState(getClient().receiver, ACTIVE, UNINITIALIZED); |
| 144 |
|
| 145 |
pumpClientToServer(); |
| 146 |
|
| 147 |
LOGGER.fine(bold("======== About to set up implicitly created sender")); |
| 148 |
|
| 149 |
getServer().sender = (Sender) getServer().connection.linkHead(of(UNINITIALIZED), of(ACTIVE)); |
| 150 |
|
| 151 |
getServer().sender.setReceiverSettleMode(getServer().sender.getRemoteReceiverSettleMode()); |
| 152 |
getServer().sender.setSenderSettleMode(getServer().sender.getRemoteSenderSettleMode()); |
| 153 |
|
| 154 |
org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = getServer().sender.getRemoteSource(); |
| 155 |
getServer().sender.setSource(serverRemoteSource); |
| 156 |
|
| 157 |
// Set the server senders capabilities |
| 158 |
getServer().sender.setOfferedCapabilities(serverOfferedCapabilities); |
| 159 |
getServer().sender.setDesiredCapabilities(serverDesiredCapabilities); |
| 160 |
|
| 161 |
assertEndpointState(getServer().sender, UNINITIALIZED, ACTIVE); |
| 162 |
getServer().sender.open(); |
| 163 |
|
| 164 |
assertEndpointState(getServer().sender, ACTIVE, ACTIVE); |
| 165 |
|
| 166 |
pumpServerToClient(); |
| 167 |
|
| 168 |
assertEndpointState(getClient().receiver, ACTIVE, ACTIVE); |
| 169 |
|
| 170 |
// Verify server side got the clients receiver capabilities as expected |
| 171 |
Symbol[] serverRemoteOfferedCapabilities = getServer().sender.getRemoteOfferedCapabilities(); |
| 172 |
assertNotNull("Server had no remote offered capabilities", serverRemoteOfferedCapabilities); |
| 173 |
assertEquals("Server remote offered capabilities not expected size", 1, serverRemoteOfferedCapabilities.length); |
| 174 |
assertTrue("Server remote offered capabilities lack expected value: " + recvOfferedCap, Arrays.asList(serverRemoteOfferedCapabilities).contains(recvOfferedCap)); |
| 175 |
|
| 176 |
Symbol[] serverRemoteDesiredCapabilities = getServer().sender.getRemoteDesiredCapabilities(); |
| 177 |
assertNotNull("Server had no remote desired capabilities", serverRemoteDesiredCapabilities); |
| 178 |
assertEquals("Server remote desired capabilities not expected size", 1, serverRemoteDesiredCapabilities.length); |
| 179 |
assertTrue("Server remote desired capabilities lack expected value: " + recvDesiredCap, Arrays.asList(serverRemoteDesiredCapabilities).contains(recvDesiredCap)); |
| 180 |
|
| 181 |
// Verify the client side got the servers sender capabilities as expected |
| 182 |
Symbol[] clientRemoteOfferedCapabilities = getClient().receiver.getRemoteOfferedCapabilities(); |
| 183 |
assertNotNull("Client had no remote offered capabilities", clientRemoteOfferedCapabilities); |
| 184 |
assertEquals("Client remote offered capabilities not expected size", 1, clientRemoteOfferedCapabilities.length); |
| 185 |
assertTrue("Client remote offered capabilities lack expected value: " + senderOfferedCap, Arrays.asList(clientRemoteOfferedCapabilities).contains(senderOfferedCap)); |
| 186 |
|
| 187 |
Symbol[] clientRemoteDesiredCapabilities = getClient().receiver.getRemoteDesiredCapabilities(); |
| 188 |
assertNotNull("Client had no remote desired capabilities", clientRemoteDesiredCapabilities); |
| 189 |
assertEquals("Client remote desired capabilities not expected size", 1, clientRemoteDesiredCapabilities.length); |
| 190 |
assertTrue("Client remote desired capabilities lack expected value: " + senderDesiredCap, Arrays.asList(clientRemoteDesiredCapabilities).contains(senderDesiredCap)); |
| 191 |
} |
| 192 |
|
| 193 |
@Test |
| 194 |
public void testProperties() throws Exception |
| 195 |
{ |
| 196 |
Map<Symbol, Object> receiverProps = new HashMap<>(); |
| 197 |
receiverProps.put(RCV_PROP, RCV_PROP_VAL); |
| 198 |
|
| 199 |
Map<Symbol, Object> senderProps = new HashMap<>(); |
| 200 |
senderProps.put(SND_PROP, SND_PROP_VAL); |
| 201 |
|
| 202 |
LOGGER.fine(bold("======== About to create transports")); |
| 203 |
|
| 204 |
getClient().transport = Proton.transport(); |
| 205 |
ProtocolTracerEnabler.setProtocolTracer(getClient().transport, TestLoggingHelper.CLIENT_PREFIX); |
| 206 |
|
| 207 |
getServer().transport = Proton.transport(); |
| 208 |
ProtocolTracerEnabler.setProtocolTracer(getServer().transport, " " + TestLoggingHelper.SERVER_PREFIX); |
| 209 |
|
| 210 |
doOutputInputCycle(); |
| 211 |
|
| 212 |
getClient().connection = Proton.connection(); |
| 213 |
getClient().transport.bind(getClient().connection); |
| 214 |
|
| 215 |
getServer().connection = Proton.connection(); |
| 216 |
getServer().transport.bind(getServer().connection); |
| 217 |
|
| 218 |
LOGGER.fine(bold("======== About to open connections")); |
| 219 |
getClient().connection.open(); |
| 220 |
getServer().connection.open(); |
| 221 |
|
| 222 |
doOutputInputCycle(); |
| 223 |
|
| 224 |
LOGGER.fine(bold("======== About to open sessions")); |
| 225 |
getClient().session = getClient().connection.session(); |
| 226 |
getClient().session.open(); |
| 227 |
|
| 228 |
pumpClientToServer(); |
| 229 |
|
| 230 |
getServer().session = getServer().connection.sessionHead(of(UNINITIALIZED), of(ACTIVE)); |
| 231 |
assertEndpointState(getServer().session, UNINITIALIZED, ACTIVE); |
| 232 |
|
| 233 |
getServer().session.open(); |
| 234 |
assertEndpointState(getServer().session, ACTIVE, ACTIVE); |
| 235 |
|
| 236 |
pumpServerToClient(); |
| 237 |
assertEndpointState(getClient().session, ACTIVE, ACTIVE); |
| 238 |
|
| 239 |
LOGGER.fine(bold("======== About to create reciever")); |
| 240 |
|
| 241 |
getClient().source = new Source(); |
| 242 |
getClient().source.setAddress(_sourceAddress); |
| 243 |
|
| 244 |
getClient().target = new Target(); |
| 245 |
getClient().target.setAddress(null); |
| 246 |
|
| 247 |
getClient().receiver = getClient().session.receiver("link1"); |
| 248 |
getClient().receiver.setTarget(getClient().target); |
| 249 |
getClient().receiver.setSource(getClient().source); |
| 250 |
|
| 251 |
getClient().receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST); |
| 252 |
getClient().receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED); |
| 253 |
|
| 254 |
// Set the recievers properties |
| 255 |
getClient().receiver.setProperties(receiverProps); |
| 256 |
|
| 257 |
assertEndpointState(getClient().receiver, UNINITIALIZED, UNINITIALIZED); |
| 258 |
|
| 259 |
getClient().receiver.open(); |
| 260 |
assertEndpointState(getClient().receiver, ACTIVE, UNINITIALIZED); |
| 261 |
|
| 262 |
pumpClientToServer(); |
| 263 |
|
| 264 |
LOGGER.fine(bold("======== About to set up implicitly created sender")); |
| 265 |
|
| 266 |
getServer().sender = (Sender) getServer().connection.linkHead(of(UNINITIALIZED), of(ACTIVE)); |
| 267 |
|
| 268 |
getServer().sender.setReceiverSettleMode(getServer().sender.getRemoteReceiverSettleMode()); |
| 269 |
getServer().sender.setSenderSettleMode(getServer().sender.getRemoteSenderSettleMode()); |
| 270 |
|
| 271 |
org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = getServer().sender.getRemoteSource(); |
| 272 |
getServer().sender.setSource(serverRemoteSource); |
| 273 |
|
| 274 |
// Set the senders properties |
| 275 |
getServer().sender.setProperties(senderProps); |
| 276 |
|
| 277 |
assertEndpointState(getServer().sender, UNINITIALIZED, ACTIVE); |
| 278 |
getServer().sender.open(); |
| 279 |
|
| 280 |
assertEndpointState(getServer().sender, ACTIVE, ACTIVE); |
| 281 |
|
| 282 |
pumpServerToClient(); |
| 283 |
|
| 284 |
assertEndpointState(getClient().receiver, ACTIVE, ACTIVE); |
| 285 |
|
| 286 |
// Verify server side got the clients receiver properties as expected |
| 287 |
Map<Symbol, Object> serverRemoteProperties = getServer().sender.getRemoteProperties(); |
| 288 |
assertNotNull("Server had no remote properties", serverRemoteProperties); |
| 289 |
assertEquals("Server remote properties not expected size", 1, serverRemoteProperties.size()); |
| 290 |
assertTrue("Server remote properties lack expected key: " + RCV_PROP, serverRemoteProperties.containsKey(RCV_PROP)); |
| 291 |
assertEquals("Server remote properties contain unexpected value for key: " + RCV_PROP, RCV_PROP_VAL, serverRemoteProperties.get(RCV_PROP)); |
| 292 |
|
| 293 |
// Verify the client side got the servers sender properties as expected |
| 294 |
Map<Symbol, Object> clientRemoteProperties = getClient().receiver.getRemoteProperties(); |
| 295 |
assertNotNull("Client had no remote properties", clientRemoteProperties); |
| 296 |
assertEquals("Client remote properties not expected size", 1, clientRemoteProperties.size()); |
| 297 |
assertTrue("Client remote properties lack expected key: " + SND_PROP, clientRemoteProperties.containsKey(SND_PROP)); |
| 298 |
assertEquals("Client remote properties contain unexpected value for key: " + SND_PROP, SND_PROP_VAL, clientRemoteProperties.get(SND_PROP)); |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Test the {@link Link#getCredit()}, {@link Link#getQueued()}, and |
| 303 |
* {@link Link#getRemoteCredit()} methods behave as expected when sending |
| 304 |
* from server and receiving on client links. |
| 305 |
* |
| 306 |
* @throws Exception |
| 307 |
* if something unexpected occurs |
| 308 |
*/ |
| 309 |
@Test |
| 310 |
public void testLinkCreditState() throws Exception |
| 311 |
{ |
| 312 |
LOGGER.fine(bold("======== About to create transports")); |
| 313 |
|
| 314 |
getClient().transport = Proton.transport(); |
| 315 |
ProtocolTracerEnabler.setProtocolTracer(getClient().transport, TestLoggingHelper.CLIENT_PREFIX); |
| 316 |
|
| 317 |
getServer().transport = Proton.transport(); |
| 318 |
ProtocolTracerEnabler.setProtocolTracer(getServer().transport, " " + TestLoggingHelper.SERVER_PREFIX); |
| 319 |
|
| 320 |
doOutputInputCycle(); |
| 321 |
|
| 322 |
getClient().connection = Proton.connection(); |
| 323 |
getClient().transport.bind(getClient().connection); |
| 324 |
|
| 325 |
getServer().connection = Proton.connection(); |
| 326 |
getServer().transport.bind(getServer().connection); |
| 327 |
|
| 328 |
LOGGER.fine(bold("======== About to open connections")); |
| 329 |
getClient().connection.open(); |
| 330 |
getServer().connection.open(); |
| 331 |
|
| 332 |
doOutputInputCycle(); |
| 333 |
|
| 334 |
LOGGER.fine(bold("======== About to open sessions")); |
| 335 |
getClient().session = getClient().connection.session(); |
| 336 |
getClient().session.open(); |
| 337 |
|
| 338 |
pumpClientToServer(); |
| 339 |
|
| 340 |
getServer().session = getServer().connection.sessionHead(of(UNINITIALIZED), of(ACTIVE)); |
| 341 |
assertEndpointState(getServer().session, UNINITIALIZED, ACTIVE); |
| 342 |
|
| 343 |
getServer().session.open(); |
| 344 |
assertEndpointState(getServer().session, ACTIVE, ACTIVE); |
| 345 |
|
| 346 |
pumpServerToClient(); |
| 347 |
assertEndpointState(getClient().session, ACTIVE, ACTIVE); |
| 348 |
|
| 349 |
LOGGER.fine(bold("======== About to create reciever")); |
| 350 |
|
| 351 |
getClient().source = new Source(); |
| 352 |
getClient().source.setAddress(_sourceAddress); |
| 353 |
|
| 354 |
getClient().target = new Target(); |
| 355 |
getClient().target.setAddress(null); |
| 356 |
|
| 357 |
getClient().receiver = getClient().session.receiver("link1"); |
| 358 |
getClient().receiver.setTarget(getClient().target); |
| 359 |
getClient().receiver.setSource(getClient().source); |
| 360 |
|
| 361 |
getClient().receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST); |
| 362 |
getClient().receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED); |
| 363 |
|
| 364 |
assertEndpointState(getClient().receiver, UNINITIALIZED, UNINITIALIZED); |
| 365 |
|
| 366 |
getClient().receiver.open(); |
| 367 |
assertEndpointState(getClient().receiver, ACTIVE, UNINITIALIZED); |
| 368 |
|
| 369 |
pumpClientToServer(); |
| 370 |
|
| 371 |
LOGGER.fine(bold("======== About to set up implicitly created sender")); |
| 372 |
|
| 373 |
getServer().sender = (Sender) getServer().connection.linkHead(of(UNINITIALIZED), of(ACTIVE)); |
| 374 |
|
| 375 |
getServer().sender.setReceiverSettleMode(getServer().sender.getRemoteReceiverSettleMode()); |
| 376 |
getServer().sender.setSenderSettleMode(getServer().sender.getRemoteSenderSettleMode()); |
| 377 |
|
| 378 |
org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = getServer().sender.getRemoteSource(); |
| 379 |
getServer().sender.setSource(serverRemoteSource); |
| 380 |
|
| 381 |
assertEndpointState(getServer().sender, UNINITIALIZED, ACTIVE); |
| 382 |
getServer().sender.open(); |
| 383 |
|
| 384 |
assertEndpointState(getServer().sender, ACTIVE, ACTIVE); |
| 385 |
|
| 386 |
pumpServerToClient(); |
| 387 |
|
| 388 |
assertEndpointState(getClient().receiver, ACTIVE, ACTIVE); |
| 389 |
|
| 390 |
LOGGER.fine(bold("======== About to flow credit")); |
| 391 |
|
| 392 |
// Verify credit state |
| 393 |
assertLinkCreditState(getServer().sender, 0, 0, 0); |
| 394 |
assertLinkCreditState(getClient().receiver, 0, 0, 0); |
| 395 |
|
| 396 |
int messagCount = 4; |
| 397 |
getClient().receiver.flow(messagCount); |
| 398 |
|
| 399 |
// Verify credit state |
| 400 |
assertLinkCreditState(getServer().sender, 0, 0, 0); |
| 401 |
assertLinkCreditState(getClient().receiver, 4, 0, 4); |
| 402 |
|
| 403 |
pumpClientToServer(); |
| 404 |
|
| 405 |
// Verify credit state |
| 406 |
assertLinkCreditState(getServer().sender, 4, 0, 4); |
| 407 |
assertLinkCreditState(getClient().receiver, 4, 0, 4); |
| 408 |
|
| 409 |
LOGGER.fine(bold("======== About to create messages and send to the client")); |
| 410 |
|
| 411 |
// 'Send' and verify credit state |
| 412 |
sendMessageToClient("delivery1", "Msg1"); |
| 413 |
assertLinkCreditState(getServer().sender, 3, 1, 3); |
| 414 |
assertLinkCreditState(getClient().receiver, 4, 0, 4); |
| 415 |
|
| 416 |
// 'Send' and verify credit state |
| 417 |
sendMessageToClient("delivery2", "Msg2"); |
| 418 |
assertLinkCreditState(getServer().sender, 2, 2, 2); |
| 419 |
assertLinkCreditState(getClient().receiver, 4, 0, 4); |
| 420 |
|
| 421 |
// Pump to the client to send messages 'on the wire', verify new state, process messages |
| 422 |
pumpServerToClient(); |
| 423 |
|
| 424 |
LOGGER.fine(bold("======== About to process the messages on the client")); |
| 425 |
|
| 426 |
assertLinkCreditState(getServer().sender, 2, 0, 2); |
| 427 |
assertLinkCreditState(getClient().receiver, 4, 2, 2); |
| 428 |
|
| 429 |
receiveMessageFromServer("delivery1", "Msg1"); |
| 430 |
|
| 431 |
assertLinkCreditState(getServer().sender, 2, 0, 2); |
| 432 |
assertLinkCreditState(getClient().receiver, 3, 1, 2); |
| 433 |
|
| 434 |
receiveMessageFromServer("delivery2", "Msg2"); |
| 435 |
|
| 436 |
assertLinkCreditState(getServer().sender, 2, 0, 2); |
| 437 |
assertLinkCreditState(getClient().receiver, 2, 0, 2); |
| 438 |
} |
| 439 |
|
| 440 |
//TODO |
| 441 |
@Test |
| 442 |
public void testMaxMessageSizeValue() throws Exception |
| 443 |
{ |
| 444 |
LOGGER.fine(bold("======== About to create transports")); |
| 445 |
|
| 446 |
Transport clientTransport = Proton.transport(); |
| 447 |
getClient().setTransport(clientTransport); |
| 448 |
ProtocolTracerEnabler.setProtocolTracer(clientTransport, TestLoggingHelper.CLIENT_PREFIX); |
| 449 |
|
| 450 |
Transport serverTransport = Proton.transport(); |
| 451 |
getServer().setTransport(serverTransport); |
| 452 |
ProtocolTracerEnabler.setProtocolTracer(serverTransport, " " + TestLoggingHelper.SERVER_PREFIX); |
| 453 |
|
| 454 |
doOutputInputCycle(); |
| 455 |
|
| 456 |
Connection clientConnection = Proton.connection(); |
| 457 |
getClient().setConnection(clientConnection); |
| 458 |
clientTransport.bind(clientConnection); |
| 459 |
|
| 460 |
Connection serverConnection = Proton.connection(); |
| 461 |
getServer().setConnection(serverConnection); |
| 462 |
serverTransport.bind(serverConnection); |
| 463 |
|
| 464 |
LOGGER.fine(bold("======== About to open connections")); |
| 465 |
clientConnection.open(); |
| 466 |
serverConnection.open(); |
| 467 |
|
| 468 |
doOutputInputCycle(); |
| 469 |
|
| 470 |
LOGGER.fine(bold("======== About to open sessions")); |
| 471 |
Session clientSession = clientConnection.session(); |
| 472 |
getClient().setSession(clientSession); |
| 473 |
clientSession.open(); |
| 474 |
|
| 475 |
pumpClientToServer(); |
| 476 |
|
| 477 |
Session serverSession = serverConnection.sessionHead(of(UNINITIALIZED), of(ACTIVE)); |
| 478 |
getServer().setSession(serverSession); |
| 479 |
|
| 480 |
serverSession.open(); |
| 481 |
|
| 482 |
pumpServerToClient(); |
| 483 |
|
| 484 |
LOGGER.fine(bold("======== About to create receiver")); |
| 485 |
|
| 486 |
Source clientSource = new Source(); |
| 487 |
getClient().setSource(clientSource); |
| 488 |
clientSource.setAddress(_sourceAddress); |
| 489 |
|
| 490 |
Target clientTarget = new Target(); |
| 491 |
getClient().setTarget(clientTarget); |
| 492 |
clientTarget.setAddress(null); |
| 493 |
|
| 494 |
Receiver clientReceiver = clientSession.receiver("link1"); |
| 495 |
getClient().setReceiver(clientReceiver); |
| 496 |
clientReceiver.setTarget(clientTarget); |
| 497 |
clientReceiver.setSource(clientSource); |
| 498 |
|
| 499 |
clientReceiver.setReceiverSettleMode(ReceiverSettleMode.FIRST); |
| 500 |
clientReceiver.setSenderSettleMode(SenderSettleMode.UNSETTLED); |
| 501 |
|
| 502 |
// Set the local link max-message-size |
| 503 |
assertNull("Expected no value to be set", clientReceiver.getMaxMessageSize()); |
| 504 |
clientReceiver.setMaxMessageSize(CLIENT_MAX_MSG_SIZE); |
| 505 |
assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, clientReceiver.getMaxMessageSize()); |
| 506 |
|
| 507 |
clientReceiver.open(); |
| 508 |
pumpClientToServer(); |
| 509 |
|
| 510 |
LOGGER.fine(bold("======== About to set up implicitly created sender")); |
| 511 |
|
| 512 |
Sender serverSender = (Sender) getServer().getConnection().linkHead(of(UNINITIALIZED), of(ACTIVE)); |
| 513 |
getServer().setSender(serverSender); |
| 514 |
|
| 515 |
serverSender.setReceiverSettleMode(serverSender.getRemoteReceiverSettleMode()); |
| 516 |
serverSender.setSenderSettleMode(serverSender.getRemoteSenderSettleMode()); |
| 517 |
|
| 518 |
org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = serverSender.getRemoteSource(); |
| 519 |
serverSender.setSource(serverRemoteSource); |
| 520 |
|
| 521 |
assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, serverSender.getRemoteMaxMessageSize()); |
| 522 |
|
| 523 |
// Set the local link max-message-size |
| 524 |
assertNull("Expected no value to be set", serverSender.getMaxMessageSize()); |
| 525 |
serverSender.setMaxMessageSize(SERVER_MAX_MSG_SIZE); |
| 526 |
assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, serverSender.getMaxMessageSize()); |
| 527 |
|
| 528 |
serverSender.open(); |
| 529 |
|
| 530 |
assertNull("Expected no value to be present yet", clientReceiver.getRemoteMaxMessageSize()); |
| 531 |
|
| 532 |
pumpServerToClient(); |
| 533 |
|
| 534 |
assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, clientReceiver.getRemoteMaxMessageSize()); |
| 535 |
} |
| 536 |
|
| 537 |
void assertLinkCreditState(Link link, int credit, int queued, int remoteCredit) |
| 538 |
{ |
| 539 |
assertEquals("Unexpected credit", credit, link.getCredit()); |
| 540 |
assertEquals("Unexpected queued", queued, link.getQueued()); |
| 541 |
assertEquals("Unexpected remote credit", remoteCredit, link.getRemoteCredit()); |
| 542 |
} |
| 543 |
|
| 544 |
private Delivery receiveMessageFromServer(String deliveryTag, String messageContent) |
| 545 |
{ |
| 546 |
Delivery delivery = getClient().connection.getWorkHead(); |
| 547 |
|
| 548 |
assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag())); |
| 549 |
assertEquals("The received delivery should be on our receiver", |
| 550 |
getClient().receiver, delivery.getLink()); |
| 551 |
|
| 552 |
assertNull(delivery.getLocalState()); |
| 553 |
assertNull(delivery.getRemoteState()); |
| 554 |
|
| 555 |
assertFalse(delivery.isPartial()); |
| 556 |
assertTrue(delivery.isReadable()); |
| 557 |
|
| 558 |
byte[] received = new byte[BUFFER_SIZE]; |
| 559 |
int len = getClient().receiver.recv(received, 0, BUFFER_SIZE); |
| 560 |
|
| 561 |
assertTrue("given array was too small", len < BUFFER_SIZE); |
| 562 |
|
| 563 |
Message m = Proton.message(); |
| 564 |
m.decode(received, 0, len); |
| 565 |
|
| 566 |
Object messageBody = ((AmqpValue)m.getBody()).getValue(); |
| 567 |
assertEquals("Unexpected message content", messageContent, messageBody); |
| 568 |
|
| 569 |
boolean receiverAdvanced = getClient().receiver.advance(); |
| 570 |
assertTrue("receiver has not advanced", receiverAdvanced); |
| 571 |
|
| 572 |
return delivery; |
| 573 |
} |
| 574 |
|
| 575 |
private Delivery sendMessageToClient(String deliveryTag, String messageContent) |
| 576 |
{ |
| 577 |
byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8); |
| 578 |
|
| 579 |
Message m = Proton.message(); |
| 580 |
m.setBody(new AmqpValue(messageContent)); |
| 581 |
|
| 582 |
byte[] encoded = new byte[BUFFER_SIZE]; |
| 583 |
int len = m.encode(encoded, 0, BUFFER_SIZE); |
| 584 |
|
| 585 |
assertTrue("given array was too small", len < BUFFER_SIZE); |
| 586 |
|
| 587 |
Delivery serverDelivery = getServer().sender.delivery(tag); |
| 588 |
|
| 589 |
int sent = getServer().sender.send(encoded, 0, len); |
| 590 |
|
| 591 |
assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent); |
| 592 |
|
| 593 |
boolean senderAdvanced = getServer().sender.advance(); |
| 594 |
assertTrue("sender has not advanced", senderAdvanced); |
| 595 |
|
| 596 |
return serverDelivery; |
| 597 |
} |
| 598 |
} |