37
37
import org .neo4j .driver .internal .async .inbound .InboundMessageDispatcher ;
38
38
import org .neo4j .driver .internal .async .outbound .OutboundMessageHandler ;
39
39
import org .neo4j .driver .internal .messaging .v1 .MessageFormatV1 ;
40
+ import org .neo4j .driver .internal .util .ServerVersion ;
40
41
41
42
import static org .junit .jupiter .api .Assertions .assertEquals ;
42
43
import static org .junit .jupiter .api .Assertions .assertFalse ;
@@ -73,7 +74,7 @@ void tearDown()
73
74
void shouldSetServerVersionOnChannel ()
74
75
{
75
76
ChannelPromise channelPromise = channel .newPromise ();
76
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
77
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
77
78
78
79
Map <String ,Value > metadata = metadata ( anyServerVersion (), "bolt-1" );
79
80
handler .onSuccess ( metadata );
@@ -86,7 +87,7 @@ void shouldSetServerVersionOnChannel()
86
87
void shouldThrowWhenServerVersionNotReturned ()
87
88
{
88
89
ChannelPromise channelPromise = channel .newPromise ();
89
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
90
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
90
91
91
92
Map <String ,Value > metadata = metadata ( null , "bolt-1" );
92
93
assertThrows ( UntrustedServerException .class , () -> handler .onSuccess ( metadata ) );
@@ -99,7 +100,7 @@ void shouldThrowWhenServerVersionNotReturned()
99
100
void shouldThrowWhenServerVersionIsNull ()
100
101
{
101
102
ChannelPromise channelPromise = channel .newPromise ();
102
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
103
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
103
104
104
105
Map <String ,Value > metadata = metadata ( Values .NULL , "bolt-x" );
105
106
assertThrows ( UntrustedServerException .class , () -> handler .onSuccess ( metadata ) );
@@ -112,7 +113,7 @@ void shouldThrowWhenServerVersionIsNull()
112
113
void shouldThrowWhenServerVersionCantBeParsed ()
113
114
{
114
115
ChannelPromise channelPromise = channel .newPromise ();
115
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
116
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
116
117
117
118
Map <String ,Value > metadata = metadata ( "WrongServerVersion" , "bolt-x" );
118
119
assertThrows ( IllegalArgumentException .class , () -> handler .onSuccess ( metadata ) );
@@ -121,11 +122,25 @@ void shouldThrowWhenServerVersionCantBeParsed()
121
122
assertTrue ( channel .closeFuture ().isDone () ); // channel was closed
122
123
}
123
124
125
+ @ Test
126
+ void shouldUseProtocolVersionForServerVersionWhenConnectedWithBoltV4 ()
127
+ {
128
+ ChannelPromise channelPromise = channel .newPromise ();
129
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 4 );
130
+
131
+ // server used in metadata should be ignored
132
+ Map <String ,Value > metadata = metadata ( ServerVersion .vInDev , "bolt-1" );
133
+ handler .onSuccess ( metadata );
134
+
135
+ assertTrue ( channelPromise .isSuccess () );
136
+ assertEquals ( ServerVersion .v4_0_0 , serverVersion ( channel ) );
137
+ }
138
+
124
139
@ Test
125
140
void shouldSetConnectionIdOnChannel ()
126
141
{
127
142
ChannelPromise channelPromise = channel .newPromise ();
128
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
143
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
129
144
130
145
Map <String ,Value > metadata = metadata ( anyServerVersion (), "bolt-42" );
131
146
handler .onSuccess ( metadata );
@@ -138,7 +153,7 @@ void shouldSetConnectionIdOnChannel()
138
153
void shouldThrowWhenConnectionIdNotReturned ()
139
154
{
140
155
ChannelPromise channelPromise = channel .newPromise ();
141
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
156
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
142
157
143
158
Map <String ,Value > metadata = metadata ( anyServerVersion (), null );
144
159
assertThrows ( IllegalStateException .class , () -> handler .onSuccess ( metadata ) );
@@ -151,7 +166,7 @@ void shouldThrowWhenConnectionIdNotReturned()
151
166
void shouldThrowWhenConnectionIdIsNull ()
152
167
{
153
168
ChannelPromise channelPromise = channel .newPromise ();
154
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
169
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
155
170
156
171
Map <String ,Value > metadata = metadata ( anyServerVersion (), Values .NULL );
157
172
assertThrows ( IllegalStateException .class , () -> handler .onSuccess ( metadata ) );
@@ -164,7 +179,7 @@ void shouldThrowWhenConnectionIdIsNull()
164
179
void shouldCloseChannelOnFailure () throws Exception
165
180
{
166
181
ChannelPromise channelPromise = channel .newPromise ();
167
- HelloResponseHandler handler = new HelloResponseHandler ( channelPromise );
182
+ HelloResponseHandler handler = new HelloResponseHandler ( channelPromise , 3 );
168
183
169
184
RuntimeException error = new RuntimeException ( "Hi!" );
170
185
handler .onFailure ( error );
0 commit comments