Debian Codegraph @

proton-j/src/test/java/org/apache/qpid/proton/systemtests/engine/ConnectionTest.java

raw
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.engine;
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.CLOSED;
24 import static org.apache.qpid.proton.engine.EndpointState.UNINITIALIZED;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import org.apache.qpid.proton.Proton;
34 import org.apache.qpid.proton.amqp.Symbol;
35 import org.apache.qpid.proton.amqp.transport.Close;
36 import org.apache.qpid.proton.amqp.transport.ErrorCondition;
37 import org.apache.qpid.proton.amqp.transport.Open;
38 import org.apache.qpid.proton.engine.Connection;
39 import org.apache.qpid.proton.engine.Endpoint;
40 import org.apache.qpid.proton.engine.EndpointState;
41 import org.apache.qpid.proton.engine.Session;
42 import org.apache.qpid.proton.engine.Transport;
43 import org.apache.qpid.proton.engine.impl.AmqpFramer;
44 import org.junit.Ignore;
45 import org.junit.Test;
46
47 /**
48 * Implicitly tests both {@link Connection} and {@link Transport} (e.g. for stuff like the AMQP header exchange).
49 *
50 * TODO test that the connection properties, connection capability, and error info maps have keys that are exclusively of type Symbol.
51 */
52 public class ConnectionTest
53 {
54 private static final String SERVER_CONTAINER = "serverContainer";
55 private static final String CLIENT_CONTAINER = "clientContainer";
56
57 private final Transport _clientTransport = Proton.transport();
58 private final Transport _serverTransport = Proton.transport();
59
60 private final TransportPumper _pumper = new TransportPumper(_clientTransport, _serverTransport);
61
62 private final Connection _clientConnection = Proton.connection();
63 private final Connection _serverConnection = Proton.connection();
64
65 private final AmqpFramer _framer = new AmqpFramer();
66
67 // 2.4.1 Opening A Connection
68
69 /** */
70 @Test
71 public void testOpenConnection()
72 {
73 _pumper.pumpAll();
74
75 bindAndOpenConnections();
76 }
77
78
79 /** Container id is a mandatory field so this should cause an error */
80 @Test
81 public void testReceiptOfOpenWithoutContainerId_causesTODO()
82 {
83 _pumper.pumpAll();
84
85 Open openWithoutContainerId = new Open();
86 byte[] openFrameBuffer = _framer.generateFrame(0, openWithoutContainerId);
87
88 int serverConsumed = _serverTransport.input(openFrameBuffer, 0, openFrameBuffer.length);
89 assertEquals(openFrameBuffer.length, serverConsumed);
90 assertEquals(_serverTransport.capacity(), Transport.END_OF_STREAM);
91 }
92
93 /**
94 * "Prior to any explicit negotiation, the maximum frame size is 512 (MIN-MAX-FRAME-SIZE) and the maximum channel number is 0"
95 * */
96 @Test
97 public void testReceiptOfOpenExactlyDefaultMaximumFrameSize()
98 {
99 _pumper.pumpAll();
100
101 _serverTransport.bind(_serverConnection);
102 assertEnpointState(_serverConnection, UNINITIALIZED, UNINITIALIZED);
103
104 // containerId and extended header sized to give an open frame
105 // exactly 512 bytes in length.
106 String containerId = "12345678";
107 int extendedHeaderSize = 122 * 4;
108
109 Open open = new Open();
110 open.setContainerId(containerId);
111 byte[] openFrameBuffer = _framer.generateFrame(0, new byte[extendedHeaderSize], open);
112 assertEquals("Test requires a frame of size MIN_MAX_FRAME_SIZE",
113 Transport.MIN_MAX_FRAME_SIZE, openFrameBuffer.length);
114
115 int serverConsumed = _serverTransport.input(openFrameBuffer, 0, openFrameBuffer.length);
116 assertEquals(openFrameBuffer.length, serverConsumed);
117
118 // Verify that the server has seen the Open arrive
119 assertEnpointState(_serverConnection, UNINITIALIZED, ACTIVE);
120 assertEquals(containerId, _serverConnection.getRemoteContainer());
121 }
122
123 /**
124 * "Prior to any explicit negotiation, the maximum frame size is 512 (MIN-MAX-FRAME-SIZE) and the maximum channel number is 0"
125 */
126 @Test
127 public void testReceiptOfOpenBiggerThanDefaultMaximumFrameSize_causesTODO()
128 {
129 _pumper.pumpAll();
130
131 _serverTransport.bind(_serverConnection);
132 assertEnpointState(_serverConnection, UNINITIALIZED, UNINITIALIZED);
133
134 // containerId and extended header sized to give an open frame
135 // 1 byte larger the than 512 bytes permitted before negotiation by the AMQP spec.
136
137 String containerId = "123456789";
138 int extendedHeaderSize = 122 * 4;
139
140 Open bigOpen = new Open();
141 bigOpen.setContainerId(containerId);
142 byte[] openFrameBuffer = _framer.generateFrame(0, new byte[extendedHeaderSize], bigOpen);
143 assertEquals("Test requires a frame of size MIN_MAX_FRAME_SIZE + 1",
144 Transport.MIN_MAX_FRAME_SIZE + 1, openFrameBuffer.length);
145
146 int serverConsumed = _serverTransport.input(openFrameBuffer, 0, openFrameBuffer.length);
147 assertEquals(openFrameBuffer.length, serverConsumed);
148
149 // TODO server should indicate error but currently both implementations currently process
150 // the larger frames. The following assertions should fail but currently pass.
151 assertEnpointState(_serverConnection, UNINITIALIZED, ACTIVE);
152 assertNotNull(_serverConnection.getRemoteContainer());
153 }
154
155 @Test
156 public void testReceiptOfSecondOpen_causesTODO()
157 {
158 bindAndOpenConnections();
159
160 Open secondOpen = new Open(); // erroneous
161 secondOpen.setContainerId("secondOpen");
162 byte[] openFrameBuffer = _framer.generateFrame(0, secondOpen);
163
164 int serverConsumed = _serverTransport.input(openFrameBuffer, 0, openFrameBuffer.length);
165 assertEquals(openFrameBuffer.length, serverConsumed);
166
167 // TODO server should indicate error but currently both implementation currently
168 // allow this condition
169 }
170
171 /** "each peer MUST send an open frame before sending any other frames"
172 *
173 * @see ConnectionTest#testReceiptOfCloseBeforeOpen_causesTODO()
174 */
175 public void testReceiptOfIntialFrameOtherThanOpen_causesTODO()
176 {
177 }
178
179 /**
180 * 2.4.5 "Implementations MUST be prepared to handle empty frames arriving on any valid channel"
181 *
182 * TODO consider moving to {@link TransportTest} once we have a less Connection-centric way of
183 * checking health than calling {@link #bindAndOpenConnections()}
184 */
185 @Test
186 public void testReceiptOfInitialEmptyFrame_isAllowed()
187 {
188 _pumper.pumpAll();
189
190 byte[] emptyFrame = _framer.createEmptyFrame(0);
191 int bytesConsumed = _serverTransport.input(emptyFrame, 0, emptyFrame.length);
192 assertEquals(emptyFrame.length, bytesConsumed);
193
194 bindAndOpenConnections();
195 }
196
197
198 /** "The open frame can only be sent on channel 0" */
199 @Test
200 @Ignore("Reinstate once it is agreed how error condition will be reported to user of API")
201 public void testReceiptOfOpenOnNonZeroChannelNumber_causesTODO()
202 {
203 _pumper.pumpAll();
204
205 Open open = new Open();
206 open.setContainerId(SERVER_CONTAINER);
207
208 int nonZeroChannelId = 1;
209 byte[] buf = _framer.generateFrame(nonZeroChannelId, open);
210 int rv = _serverTransport.input(buf, 0, buf.length);
211 // TODO server should indicate error
212 }
213
214
215 /**
216 * "After sending the open frame and reading its partner's open frame a peer MUST operate within
217 * mutually acceptable limitations from this point forward"
218 * see 2.7.1 "A peer that receives an oversized frame MUST close the connection with the framing-error error-code"
219 */
220 public void testReceiptOfFrameLargerThanAgreedMaximumSize_causesTODO()
221 {
222 }
223
224 public void testThatSentFramesAreWithinMaximumSizeLimit()
225 {
226 }
227
228 // 2.4.2 Pipelined Open
229
230 /** test that the other peer accepts the pipelined frames and creates an open connection */
231 @Test
232 public void testReceiptOfOpenUsingPipelining()
233 {
234 _clientConnection.setContainer(CLIENT_CONTAINER);
235 _clientTransport.bind(_clientConnection);
236 _clientConnection.open();
237
238 _serverTransport.bind(_serverConnection);
239
240 // when pipelining, we delay pumping until the connection is both bound and opened
241 _pumper.pumpOnceFromClientToServer();
242
243 assertEnpointState(_clientConnection, ACTIVE, UNINITIALIZED);
244 assertEnpointState(_serverConnection, UNINITIALIZED, ACTIVE);
245 }
246
247
248 /** test that the other peer accepts the pipelined frames and creates an already-closed connection */
249 @Test
250 public void testReceiptOfOpenThenCloseUsingPipelining()
251 {
252 _clientConnection.setContainer(CLIENT_CONTAINER);
253 _clientTransport.bind(_clientConnection);
254 _clientConnection.open();
255 _clientConnection.close();
256
257 _serverTransport.bind(_serverConnection);
258 _pumper.pumpOnceFromClientToServer();
259
260 assertEnpointState(_clientConnection, CLOSED, UNINITIALIZED);
261 assertEnpointState(_serverConnection, UNINITIALIZED, CLOSED);
262 }
263
264 /**
265 * Similar to {@link #testReceiptOfOpenUsingPipelining()} but opens both ends of the connection
266 * so we can actually use it.
267 */
268 @Test
269 public void testOpenConnectionUsingPipelining()
270 {
271 _clientConnection.setContainer(CLIENT_CONTAINER);
272 _clientTransport.bind(_clientConnection);
273 _clientConnection.open();
274
275
276 _serverConnection.setContainer(SERVER_CONTAINER);
277 _serverTransport.bind(_serverConnection);
278 _serverConnection.open();
279
280 _pumper.pumpAll();
281
282 assertEnpointState(_clientConnection, ACTIVE, ACTIVE);
283 assertEnpointState(_serverConnection, ACTIVE, ACTIVE);
284
285 assertConnectionIsUsable();
286 }
287
288 // 2.4.3 Closing A Connection and 2.7.9 Close
289
290 /**
291 * "each peer MUST write a close frame"
292 * Omits the optional error field
293 */
294 @Test
295 public void testCloseConnection()
296 {
297 bindAndOpenConnections();
298
299 assertEnpointState(_clientConnection, ACTIVE, ACTIVE);
300 assertEnpointState(_serverConnection, ACTIVE, ACTIVE);
301
302 _clientConnection.close();
303
304 assertEnpointState(_clientConnection, CLOSED, ACTIVE);
305 assertEnpointState(_serverConnection, ACTIVE, ACTIVE);
306
307 _pumper.pumpAll();
308
309 assertEnpointState(_clientConnection, CLOSED, ACTIVE);
310 assertEnpointState(_serverConnection, ACTIVE, CLOSED);
311
312 _serverConnection.close();
313
314 assertEnpointState(_clientConnection, CLOSED, ACTIVE);
315 assertEnpointState(_serverConnection, CLOSED, CLOSED);
316
317 _pumper.pumpAll();
318
319 assertEnpointState(_clientConnection, CLOSED, CLOSED);
320 assertEnpointState(_serverConnection, CLOSED, CLOSED);
321 }
322
323 /**
324 * "each peer MUST write a close frame with a code indicating the reason for closing"
325 * Also see 2.8.16 Connection Error
326 */
327 @Test
328 @SuppressWarnings({ "rawtypes", "unchecked" })
329 public void testCloseConnectionWithErrorCode_causesCloseFrameContainingErrorCodeToBeSent()
330 {
331 bindAndOpenConnections();
332
333 /*
334 * TODO javadoc for {@link Connection#getCondition()} states null is returned if there is no condition,
335 * this differs from the implementation of both Proton-c and Proton-j.
336 */
337 assertNull(_clientConnection.getCondition().getCondition());
338 assertNull(_serverConnection.getCondition().getCondition());
339
340 assertNull(_clientConnection.getRemoteCondition().getCondition());
341 assertNull(_serverConnection.getRemoteCondition().getCondition());
342
343 ErrorCondition clientErrorCondition = new ErrorCondition(Symbol.getSymbol("myerror"), "mydescription");
344 Map info = new HashMap();
345 info.put(Symbol.getSymbol("simplevalue"), "value");
346 info.put(Symbol.getSymbol("list"), Arrays.asList("e1", "e2", "e3"));
347 clientErrorCondition.setInfo(info);
348 _clientConnection.setCondition(clientErrorCondition);
349
350 _clientConnection.close();
351 _pumper.pumpAll();
352
353 assertEquals(clientErrorCondition, _serverConnection.getRemoteCondition());
354 assertNull(_serverConnection.getCondition().getCondition());
355 }
356
357 /**
358 * "each peer MUST write a close frame with a code indicating the reason for closing"
359 */
360 public void testReceiptOfConnectionCloseContainingErrorCode_allowsErrorCodeToBeObserved()
361 {
362 }
363
364 /**
365 * A test for when the connection close frame contains a session error
366 * rather than a connection error. This is allowed by the spec.
367 */
368 public void testReceiptOfConnectionCloseContainingNonConnectionErrorCode_causesTODO()
369 {
370 }
371
372 /** "This frame MUST be the last thing ever written onto a connection." */
373 public void testUsingProtonAfterClosingConnection_doesntCauseFrameToBeSent()
374 {
375 }
376
377 /** "This frame MUST be the last thing ever written onto a connection." */
378 public void testReceiptOfFrameAfterClose_causesTODO()
379 {
380 }
381
382 /** "A close frame MAY be received on any channel up to the maximum channel number negotiated in open" */
383 public void testReceiptOfCloseOnNonZeroChannelNumber_causesHappyPathTODO()
384 {
385 }
386
387 /**
388 * "each peer MUST send an open frame before sending any other frames"
389 */
390 @Test
391 public void testReceiptOfCloseBeforeOpen_causesTODO()
392 {
393 _pumper.pumpAll();
394
395 Close surprisingClose = new Close();
396
397 byte[] buf = _framer.generateFrame(0, surprisingClose);
398 _serverTransport.input(buf, 0, buf.length);
399
400 // TODO server should indicate error
401 }
402
403 // 2.4.4 Simultaneous Close
404
405 /** "both endpoints MAY simultaneously" */
406 public void testPeersCloseConnectionSimultaneously()
407 {
408 }
409
410 // 2.4.5 Idle Timeout Of A Connection
411
412 public void testReceiptOfFrame_preventsIdleTimeoutOccurring()
413 {
414 }
415
416 /** "If the threshold is exceeded, then a peer SHOULD try to gracefully close the connection using a close frame with an error explaining why" */
417 public void testReceiptOfFrameTooLate_causedIdleTimeoutToOccur()
418 {
419 }
420
421 /** "Each peer has its own (independent) idle timeout." */
422 public void testPeersWithDifferentIdleTimeouts_timeOutAtTheCorrectTimes()
423 {
424 }
425
426 /**
427 * "If the value is not set, then the sender does not have an idle time-out. However,
428 * senders doing this SHOULD be aware that implementations MAY choose to use an internal default
429 * to efficiently manage a peer's resources."
430 */
431 public void testReceiptOfFrameWithZeroIdleTimeout_causesNoIdleFramesToBeSent()
432 {
433 }
434
435 /**
436 * "If a peer can not, for any reason support a proposed idle timeout,
437 * then it SHOULD close the connection using a close frame with an error explaining why"
438 */
439 public void testReceiptOfOpenWithUnsupportedTimeout_causesCloseWithError()
440 {
441 }
442
443 /**
444 * implementations ... MUST use channel 0 if a maximum channel number has not yet been negotiated
445 * (i.e., before an open frame has been received)
446 */
447 public void testReceiptOfEmptyFrameOnNonZeroChannelBeforeMaximumChannelsNegotiated_causesTODO()
448 {
449 }
450
451
452 // 2.4.7 State transitions
453
454 /**
455 * The DISCARDING state is a variant of the CLOSE_SENT state where the close is triggered by an error.
456 * In this case any incoming frames on the connection MUST be silently discarded until the peer's close frame is received
457 */
458 public void testReceiptOfFrameWhenInDiscardingState_isIgnored()
459 {
460 }
461
462 // 2.7.1 Open
463
464 public void testReceiptOfOpen_containerCanBeRetrieved()
465 {
466 }
467
468 /**
469 * The spec says:
470 * "If no hostname is provided the receiving peer SHOULD select a default based on its own configuration"
471 * but Proton's Engine layer does not do any defaulting - this is the responsibility
472 * of other layers e.g. Messenger or Driver.
473 */
474 public void testReceiptOfOpenWithoutHostname_nullHostnameIsRetrieved()
475 {
476 }
477
478 public void testReceiptOfOpenWithHostname_hostnameCanBeRetrieved()
479 {
480 }
481
482 /**
483 * "Both peers MUST accept frames of up to 512 (MIN-MAX-FRAME-SIZE) octets."
484 */
485 public void testReceiptOfOpenWithMaximumFramesizeLowerThanMinMaxFrameSize_causesTODO()
486 {
487 }
488
489 public void testInitiatingPeerAndReceivingPeerUseDifferentMaxFrameSizes()
490 {
491 }
492
493 public void testReceiptOfSessionBeginThatBreaksChannelMax_causesTODO()
494 {
495 }
496
497 public void testCreationOfSessionThatBreaksChannelMax_causesTODO()
498 {
499 }
500
501 public void testOpenConnectionWithPeersUsingUnequalChannelMax_enforcesLowerOfTwoValues()
502 {
503 }
504
505 public void testOpenConnectionWithOnePeerUsingUnsetChannelMax_enforcesTheSetValue()
506 {
507 }
508
509 public void testReceiptOfBeginWithInUseChannelId_causesTODO()
510 {
511 }
512
513 /** "If a session is locally initiated, the remote-channel MUST NOT be set." */
514 public void testReceiptOfUnsolicitedBeginWithChannelId_causesTODO()
515 {
516 }
517
518 /**
519 * "When an endpoint responds to a remotely initiated session, the remote-channel MUST be set
520 * to the channel on which the remote session sent the begin."
521 */
522 public void testThatBeginResponseContainsChannelId()
523 {
524 }
525
526 /**
527 * I imagine we will want to begin ChannelMax number of sessions, then end
528 * a session from the 'middle'. Then check we are correctly begin a new
529 * channel.
530 */
531 public void testEnd_channelNumberAvailableForReuse()
532 {
533 }
534
535 public void testReceiptOfOpenWithOutgoingLocales_outgoingLocalesCanBeRetrieved()
536 {
537 }
538
539 /** "A null value or an empty list implies that only en-US is supported. " */
540 public void testReceiptOfOpenWithNullOutgoingLocales_defaultOutgoingLocaleCanBeRetrieved()
541 {
542 }
543
544 /** "A null value or an empty list implies that only en-US is supported. " */
545 public void testReceiptOfOpenWithEmptyListOfOutgoingLocales_defaultOutgoingLocaleCanBeRetrieved()
546 {
547 }
548
549 public void testReceiptOfOpenWithIncomingLocales_incomingLocalesCanBeRetrieved()
550 {
551 }
552
553 /** "A null value or an empty list implies that only en-US is supported. " */
554 public void testReceiptOfOpenWithNullIncomingLocales_defaultIncomingLocaleCanBeRetrieved()
555 {
556 }
557
558 /** "A null value or an empty list implies that only en-US is supported. " */
559 public void testReceiptOfOpenWithEmptyListOfIncomingLocales_defaultIncomingLocaleCanBeRetrieved()
560 {
561 }
562
563 // TODO It seems that currently Proton-j merely exposes the remote capabilities to
564 // the user and is seems to be a end-user responsibility to enforce "If the receiver of the
565 // offered-capabilities requires an extension capability which is not present in the
566 // offered-capability list then it MUST close the connection.". However, i wonder if this
567 // is an omission -- surely Proton could valid that request desirable capabilities are
568 // offered by the remote???
569
570 public void testReceiptOfOpenWithOfferedCapabilities_offeredCapabilitiesCanBeRetrieved()
571 {
572 }
573
574 public void testReceiptOfOpenWithDesiredCapabilities_desiredCapabilitiesCanBeRetrieved()
575 {
576 }
577
578 public void testReceiptOfOpenWithProperties_propertiesCanBeRetrieved()
579 {
580 }
581
582 // Transport/Connection related api-inspired tests
583
584 /**
585 * TODO is there a limit on the number of connections?
586 * Also try closing them in a different order to their creation.
587 */
588 public void testCreateMultipleConnections()
589 {
590 }
591
592 public void testBindTwoConnectionsToATransport_causesTODO()
593 {
594 }
595
596 public void testBindAConnectionToTwoTransports_causesTODO()
597 {
598 }
599
600 /**
601 * TODO possibly try to bind this "opened" connection too if it doesn't go pop before this.
602 */
603 public void testOpenBeforeBind_causesTODO()
604 {
605 }
606
607 public void testOpenTwice_throwsExceptionTODO()
608 {
609 }
610
611 public void testOpenAfterClose_throwsExceptionTODO()
612 {
613 }
614
615 // Connection.java-related api-inspired tests
616
617 /**
618 * also test that the session appears in the connection's session list
619 */
620 public void testCreateSession()
621 {
622 }
623
624 public void testSessionHeadWhenNoSessionsExist_returnsNull()
625 {
626 }
627
628 public void testSessionHead_returnsSessionsMatchingCriteria()
629 {
630 }
631
632 public void testLinkHeadWhenNoLinksExist_returnsNull()
633 {
634 }
635
636 public void testLinkHead_returnsLinksMatchingCriteria()
637 {
638 }
639
640 public void testGetWorkHeadWhenNoWork_returnsNull()
641 {
642 }
643
644 public void testGetWorkHeadWhenOneDeliveryIsPending_returnsTheDelivery()
645 {
646 }
647
648 /**
649 * use a name that is longer than the limit of AMQShortString
650 */
651 public void testSetContainerWithLongName_isAllowed()
652 {
653 }
654
655 public void testSetContainerWithNullName_throwsException()
656 {
657 }
658
659 public void testSetContainerWithEmptyName_throwsException()
660 {
661 }
662
663 public void testSetContainerAfterOpeningConnection_throwsExceptionTODO()
664 {
665 }
666
667 public void testOpenWithoutContainerName_throwsExceptionTODO()
668 {
669 }
670
671 public void testGetRemoteContainerBeforeOpen_returnsNull()
672 {
673 }
674
675 public void testGetRemoteContainerBeforeReceiptOfOpen_returnsNull()
676 {
677 }
678
679 public void testSetHostnameWithLongName_isAllowed()
680 {
681 }
682
683 /**
684 * Proton does not require the conventional foo.bar.com format for hostnames.
685 */
686 public void testSetHostnameWithNonstandardName_isAllowed()
687 {
688 }
689
690 public void testSetHostnameAfterOpeningConnection_throwsExceptionTODO()
691 {
692 }
693
694 public void testSetOfferedCapabilitiesAfterOpeningConnection_throwsExceptionTODO()
695 {
696 }
697
698 public void testSetDesiredCapabilitiesAfterOpeningConnection_throwsExceptionTODO()
699 {
700 }
701
702 public void testSetPropertiesAfterOpeningConnection_throwsExceptionTODO()
703 {
704 }
705
706 // Endpoint api-inspired tests
707
708 public void testGetLocalStateBeforeOpen_returnsUninitialised()
709 {
710 }
711
712 public void testGetLocalStateAfterClose_returnsClosed()
713 {
714 }
715
716 public void testGetRemoteStateBeforeReceiptOfOpen_returnsUninitialised()
717 {
718 }
719
720 public void testGetRemoteStateAfterReceiptOfClose_returnsClosed()
721 {
722 }
723
724 public void testFree_isAllowed()
725 {
726 }
727
728 public void testSetContext_contextCanBeRetrieved()
729 {
730 }
731
732 public void testGetContextWithoutSettingContext_returnsNull()
733 {
734 }
735
736 private void assertConnectionIsUsable()
737 {
738 Session clientSesion = _clientConnection.session();
739 clientSesion.open();
740 _pumper.pumpAll();
741
742 Session serverSession = _serverConnection.sessionHead(of(UNINITIALIZED), of(ACTIVE));
743 serverSession.open();
744 _pumper.pumpAll();
745
746 assertEnpointState(clientSesion, ACTIVE, ACTIVE);
747 assertEnpointState(serverSession, ACTIVE, ACTIVE);
748 }
749
750 private void bindAndOpenConnections()
751 {
752 // TODO should we be checking local and remote error conditions as part of this?
753
754 _clientConnection.setContainer(CLIENT_CONTAINER);
755 _serverConnection.setContainer(SERVER_CONTAINER);
756
757 assertEnpointState(_clientConnection, UNINITIALIZED, UNINITIALIZED);
758 assertEnpointState(_serverConnection, UNINITIALIZED, UNINITIALIZED);
759
760 _clientTransport.bind(_clientConnection);
761 _serverTransport.bind(_serverConnection);
762
763 _clientConnection.open();
764
765 assertEnpointState(_clientConnection, ACTIVE, UNINITIALIZED);
766 assertEnpointState(_serverConnection, UNINITIALIZED, UNINITIALIZED);
767
768 _pumper.pumpAll();
769
770 assertEnpointState(_clientConnection, ACTIVE, UNINITIALIZED);
771 assertEnpointState(_serverConnection, UNINITIALIZED, ACTIVE);
772
773 _serverConnection.open();
774
775 assertEnpointState(_clientConnection, ACTIVE, UNINITIALIZED);
776 assertEnpointState(_serverConnection, ACTIVE, ACTIVE);
777
778 _pumper.pumpAll();
779
780 assertEnpointState(_clientConnection, ACTIVE, ACTIVE);
781 assertEnpointState(_serverConnection, ACTIVE, ACTIVE);
782 }
783
784 private void assertEnpointState(Endpoint endpoint, EndpointState localState, EndpointState remoteState)
785 {
786 assertEquals("Unexpected local state", localState, endpoint.getLocalState());
787 assertEquals("Unexpected remote state", remoteState, endpoint.getRemoteState());
788 }
789 }