Skip to content

Commit

Permalink
Adding pipeline rename handler tests (netty#10028)
Browse files Browse the repository at this point in the history
Motivation:

Current pipeline handler replace tests are replacing handler with same name.
we need test that test handler can renamed, old handlers are removed from pipeline.

Modification:

There is coverage missing related to renaming of handlers

Result:

Adds missing tests

Co-authored-by: phani254 <[email protected]>
  • Loading branch information
subbarao and phani254 authored Feb 14, 2020
1 parent e648aa2 commit 0e2e17f
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,61 @@ public void testReplaceChannelHandler() {
assertSame(pipeline.get("handler2"), newHandler2);
}

@Test(expected = IllegalArgumentException.class)
public void testReplaceHandlerChecksDuplicateNames() {
ChannelPipeline pipeline = new LocalChannel().pipeline();

ChannelHandler handler1 = newHandler();
ChannelHandler handler2 = newHandler();
pipeline.addLast("handler1", handler1);
pipeline.addLast("handler2", handler2);

ChannelHandler newHandler1 = newHandler();
pipeline.replace("handler1", "handler2", newHandler1);
}

@Test
public void testReplaceNameWithGenerated() {
ChannelPipeline pipeline = new LocalChannel().pipeline();

ChannelHandler handler1 = newHandler();
pipeline.addLast("handler1", handler1);
assertSame(pipeline.get("handler1"), handler1);

ChannelHandler newHandler1 = newHandler();
pipeline.replace("handler1", null, newHandler1);
assertSame(pipeline.get("DefaultChannelPipelineTest$TestHandler#0"), newHandler1);
assertNull(pipeline.get("handler1"));
}

@Test
public void testRenameChannelHandler() {
ChannelPipeline pipeline = new LocalChannel().pipeline();

ChannelHandler handler1 = newHandler();
pipeline.addLast("handler1", handler1);
pipeline.addLast("handler2", handler1);
pipeline.addLast("handler3", handler1);
assertSame(pipeline.get("handler1"), handler1);
assertSame(pipeline.get("handler2"), handler1);
assertSame(pipeline.get("handler3"), handler1);

ChannelHandler newHandler1 = newHandler();
pipeline.replace("handler1", "newHandler1", newHandler1);
assertSame(pipeline.get("newHandler1"), newHandler1);
assertNull(pipeline.get("handler1"));

ChannelHandler newHandler3 = newHandler();
pipeline.replace("handler3", "newHandler3", newHandler3);
assertSame(pipeline.get("newHandler3"), newHandler3);
assertNull(pipeline.get("handler3"));

ChannelHandler newHandler2 = newHandler();
pipeline.replace("handler2", "newHandler2", newHandler2);
assertSame(pipeline.get("newHandler2"), newHandler2);
assertNull(pipeline.get("handler2"));
}

@Test
public void testChannelHandlerContextNavigation() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
Expand Down

0 comments on commit 0e2e17f

Please sign in to comment.