-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to check if a IoEventLoopGroup / IoEventLoop is using a spe… (
#14019) …cific IoHandler Motivation: We need to provide a way for the user to check if an `IoEventLoopGroup` is supporting NIO / Epoll / KQueue etc. Before people often used `group instanceof NioEventLoopGroup` etc. Modifications: Add new method that people can use to check what kind of IO is used. Result: People can use `group.isIoType(NioHandler.class)` etc. --------- Co-authored-by: Bryce Anderson <bryce_anderson@apple.com>
- Loading branch information
1 parent
b2060ea
commit 062e9da
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
97 changes: 97 additions & 0 deletions
97
transport/src/test/java/io/netty/channel/SingleThreadIoEventLoopTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2024 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.channel; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.Executors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class SingleThreadIoEventLoopTest { | ||
|
||
@Test | ||
void testIsIoType() { | ||
IoHandler handler = new TestIoHandler(); | ||
IoHandler handler2 = new TestIoHandler() { }; | ||
|
||
IoEventLoopGroup group = new SingleThreadIoEventLoop(null, Executors.defaultThreadFactory(), handler); | ||
assertTrue(group.isIoType(handler.getClass())); | ||
assertFalse(group.isIoType(handler2.getClass())); | ||
group.shutdownGracefully(); | ||
} | ||
|
||
@Test | ||
void testIsCompatible() { | ||
IoHandler handler = new TestIoHandler() { | ||
@Override | ||
public boolean isCompatible(Class<? extends IoHandle> handleType) { | ||
return handleType.equals(TestIoHandle.class); | ||
} | ||
}; | ||
|
||
IoHandle handle = new TestIoHandle() { }; | ||
IoEventLoopGroup group = new SingleThreadIoEventLoop(null, Executors.defaultThreadFactory(), handler); | ||
assertTrue(group.isCompatible(TestIoHandle.class)); | ||
assertFalse(group.isCompatible(handle.getClass())); | ||
group.shutdownGracefully(); | ||
} | ||
|
||
private static class TestIoHandler implements IoHandler { | ||
@Override | ||
public int run(IoExecutionContext context) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void prepareToDestroy() { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public IoRegistration register(IoEventLoop eventLoop, IoHandle handle, IoOps ops) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void wakeup(IoEventLoop eventLoop) { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public boolean isCompatible(Class<? extends IoHandle> handleType) { | ||
return false; | ||
} | ||
} | ||
|
||
private class TestIoHandle implements IoHandle { | ||
@Override | ||
public void handle(IoRegistration registration, IoOps readyOps) { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// NOOP | ||
} | ||
} | ||
} |