Skip to content

Instantly share code, notes, and snippets.

@zeroFruit
Created July 23, 2022 00:36
Show Gist options
  • Save zeroFruit/b74108f285ca784a78ecd12b121e5672 to your computer and use it in GitHub Desktop.
Save zeroFruit/b74108f285ca784a78ecd12b121e5672 to your computer and use it in GitHub Desktop.
Channel concept & implementation— el Project (2)
public class LocalChannelTransportTests {
private static final String SERVER_ADDRESS = "server:addr";
private DefaultChannelEventLoopGroup group1, group2;
@BeforeEach
public void setUp() {
group1 = new DefaultChannelEventLoopGroup(1);
group2 = new DefaultChannelEventLoopGroup(1);
}
@Test
@DisplayName("When client connect to server, both server and client is in active state")
public void localChannel() throws InterruptedException {
ServerTransport st = new ServerTransport();
ClientTransport ct = new ClientTransport();
st.group(group1)
.channel(LocalServerChannel.class)
.handler(
new ChannelInitializer<LocalChannel>() {
@Override
protected void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new TestHandler());
}
});
ct.group(group2).channel(LocalChannel.class).handler(new TestHandler());
Channel sc = st.bind(new LocalAddress(SERVER_ADDRESS)).await().channel();
Channel cc = ct.connect(sc.localAddress()).await().channel();
assertTrue(sc.isActive());
assertTrue(cc.isActive());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment