Created
July 23, 2022 00:36
-
-
Save zeroFruit/b74108f285ca784a78ecd12b121e5672 to your computer and use it in GitHub Desktop.
Channel concept & implementation— el Project (2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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