|
20 | 20 |
|
21 | 21 | import io.netty.util.concurrent.GlobalEventExecutor;
|
22 | 22 | import org.junit.jupiter.api.Test;
|
| 23 | +import org.junit.jupiter.params.ParameterizedTest; |
| 24 | +import org.junit.jupiter.params.provider.ValueSource; |
23 | 25 | import org.mockito.ArgumentCaptor;
|
24 | 26 |
|
25 | 27 | import java.io.IOException;
|
|
33 | 35 | import org.neo4j.driver.Logger;
|
34 | 36 | import org.neo4j.driver.Logging;
|
35 | 37 | import org.neo4j.driver.exceptions.AuthenticationException;
|
| 38 | +import org.neo4j.driver.exceptions.AuthorizationExpiredException; |
| 39 | +import org.neo4j.driver.exceptions.ClientException; |
36 | 40 | import org.neo4j.driver.exceptions.DiscoveryException;
|
37 | 41 | import org.neo4j.driver.exceptions.ProtocolException;
|
38 | 42 | import org.neo4j.driver.exceptions.ServiceUnavailableException;
|
@@ -143,6 +147,67 @@ void shouldFailImmediatelyOnAuthError()
|
143 | 147 | verify( table ).forget( A );
|
144 | 148 | }
|
145 | 149 |
|
| 150 | + @Test |
| 151 | + void shouldUseAnotherRouterOnAuthorizationExpiredException() |
| 152 | + { |
| 153 | + ClusterComposition expectedComposition = |
| 154 | + new ClusterComposition( 42, asOrderedSet( A, B, C ), asOrderedSet( B, C, D ), asOrderedSet( A, B ), null ); |
| 155 | + |
| 156 | + Map<BoltServerAddress,Object> responsesByAddress = new HashMap<>(); |
| 157 | + responsesByAddress.put( A, new AuthorizationExpiredException( "Neo.ClientError.Security.AuthorizationExpired", "message" ) ); |
| 158 | + responsesByAddress.put( B, expectedComposition ); |
| 159 | + |
| 160 | + ClusterCompositionProvider compositionProvider = compositionProviderMock( responsesByAddress ); |
| 161 | + Rediscovery rediscovery = newRediscovery( A, compositionProvider, mock( ServerAddressResolver.class ) ); |
| 162 | + RoutingTable table = routingTableMock( A, B, C ); |
| 163 | + |
| 164 | + ClusterComposition actualComposition = await( rediscovery.lookupClusterComposition( table, pool, empty(), null ) ).getClusterComposition(); |
| 165 | + |
| 166 | + assertEquals( expectedComposition, actualComposition ); |
| 167 | + verify( table ).forget( A ); |
| 168 | + verify( table, never() ).forget( B ); |
| 169 | + verify( table, never() ).forget( C ); |
| 170 | + } |
| 171 | + |
| 172 | + @ParameterizedTest |
| 173 | + @ValueSource( strings = {"Neo.ClientError.Transaction.InvalidBookmark", "Neo.ClientError.Transaction.InvalidBookmarkMixture"} ) |
| 174 | + void shouldFailImmediatelyOnBookmarkErrors( String code ) |
| 175 | + { |
| 176 | + ClientException error = new ClientException( code, "Invalid" ); |
| 177 | + |
| 178 | + Map<BoltServerAddress,Object> responsesByAddress = new HashMap<>(); |
| 179 | + responsesByAddress.put( A, new RuntimeException( "Hi!" ) ); |
| 180 | + responsesByAddress.put( B, error ); |
| 181 | + |
| 182 | + ClusterCompositionProvider compositionProvider = compositionProviderMock( responsesByAddress ); |
| 183 | + Rediscovery rediscovery = newRediscovery( A, compositionProvider, mock( ServerAddressResolver.class ) ); |
| 184 | + RoutingTable table = routingTableMock( A, B, C ); |
| 185 | + |
| 186 | + ClientException actualError = assertThrows( ClientException.class, |
| 187 | + () -> await( rediscovery.lookupClusterComposition( table, pool, empty(), null ) ) ); |
| 188 | + assertEquals( error, actualError ); |
| 189 | + verify( table ).forget( A ); |
| 190 | + } |
| 191 | + |
| 192 | + @Test |
| 193 | + void shouldFailImmediatelyOnClosedPoolError() |
| 194 | + { |
| 195 | + IllegalStateException error = new IllegalStateException( ConnectionPool.CONNECTION_POOL_CLOSED_ERROR_MESSAGE ); |
| 196 | + |
| 197 | + Map<BoltServerAddress,Object> responsesByAddress = new HashMap<>(); |
| 198 | + responsesByAddress.put( A, new RuntimeException( "Hi!" ) ); |
| 199 | + responsesByAddress.put( B, error ); |
| 200 | + |
| 201 | + ClusterCompositionProvider compositionProvider = compositionProviderMock( responsesByAddress ); |
| 202 | + Rediscovery rediscovery = newRediscovery( A, compositionProvider, mock( ServerAddressResolver.class ) ); |
| 203 | + RoutingTable table = routingTableMock( A, B, C ); |
| 204 | + |
| 205 | + IllegalStateException actualError = assertThrows( IllegalStateException.class, |
| 206 | + () -> await( rediscovery.lookupClusterComposition( table, pool, empty(), null ) ) ); |
| 207 | + assertEquals( error, actualError ); |
| 208 | + verify( table ).forget( A ); |
| 209 | + } |
| 210 | + |
146 | 211 | @Test
|
147 | 212 | void shouldFallbackToInitialRouterWhenKnownRoutersFail()
|
148 | 213 | {
|
|
0 commit comments