Skip to content

Commit 2ca56b5

Browse files
authored
Merge pull request #469 from lutovich/1.5-more-cc-tests
Added couple routing driver integration tests
2 parents 998d84f + f7ceaa2 commit 2ca56b5

File tree

9 files changed

+500
-135
lines changed

9 files changed

+500
-135
lines changed

driver/src/test/java/org/neo4j/driver/internal/util/ChannelTrackingDriverFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class ChannelTrackingDriverFactory extends DriverFactoryWithClock
4040
private final int eventLoopThreads;
4141
private ConnectionPool pool;
4242

43+
public ChannelTrackingDriverFactory()
44+
{
45+
this( 0, Clock.SYSTEM );
46+
}
47+
4348
public ChannelTrackingDriverFactory( Clock clock )
4449
{
4550
this( 0, clock );
@@ -88,13 +93,11 @@ public List<Channel> channels()
8893
return new ArrayList<>( channels );
8994
}
9095

91-
public void closeChannels()
96+
public List<Channel> pollChannels()
9297
{
93-
for ( Channel channel : channels )
94-
{
95-
channel.close().syncUninterruptibly();
96-
}
98+
List<Channel> result = new ArrayList<>( channels );
9799
channels.clear();
100+
return result;
98101
}
99102

100103
public int activeChannels( BoltServerAddress address )
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2002-2018 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.internal.util;
20+
21+
import io.netty.channel.ChannelHandlerContext;
22+
import io.netty.handler.codec.MessageToMessageEncoder;
23+
24+
import java.util.List;
25+
26+
import org.neo4j.driver.internal.messaging.ResetMessage;
27+
import org.neo4j.driver.internal.messaging.RunMessage;
28+
29+
public class ThrowingMessageEncoder<T> extends MessageToMessageEncoder<T>
30+
{
31+
private final RuntimeException error;
32+
33+
private ThrowingMessageEncoder( Class<T> messageType, RuntimeException error )
34+
{
35+
super( messageType );
36+
this.error = error;
37+
}
38+
39+
@Override
40+
protected void encode( ChannelHandlerContext ctx, T msg, List<Object> out )
41+
{
42+
ctx.pipeline().remove( this );
43+
throw error;
44+
}
45+
46+
public static ThrowingMessageEncoder<RunMessage> forRunMessage( RuntimeException error )
47+
{
48+
return new ThrowingMessageEncoder<>( RunMessage.class, error );
49+
}
50+
51+
public static ThrowingMessageEncoder<ResetMessage> forResetMessage( RuntimeException error )
52+
{
53+
return new ThrowingMessageEncoder<>( ResetMessage.class, error );
54+
}
55+
}

0 commit comments

Comments
 (0)