Skip to content

Commit f82565c

Browse files
committed
Fix unit tests.
1 parent 83ac6cc commit f82565c

File tree

2 files changed

+58
-54
lines changed

2 files changed

+58
-54
lines changed

java-components/domain-proxy/client/src/main/java/com/redhat/hacbs/domainproxy/client/DomainProxyClient.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,37 @@ public class DomainProxyClient {
5151
public void start() {
5252
Log.info("Starting domain proxy client...");
5353
Log.infof("Byte buffer size %d", byteBufferSize); // TODO Remove
54-
try (final ServerSocketChannel serverChannel = ServerSocketChannel.open(StandardProtocolFamily.INET);
55-
final Selector selector = Selector.open()) {
56-
final InetSocketAddress address = new InetSocketAddress(LOCALHOST, clientHttpPort);
57-
serverChannel.bind(address);
58-
serverChannel.configureBlocking(false);
59-
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
60-
while (running.get()) {
61-
if (selector.select(SELECTOR_TIMEOUT_MS) > 0) {
62-
final Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
63-
while (keys.hasNext()) {
64-
final SelectionKey key = keys.next();
65-
keys.remove();
66-
if (key.isAcceptable()) {
67-
if (key.channel() instanceof final ServerSocketChannel keyChannel) {
68-
final SocketChannel httpClientChannel = keyChannel.accept();
69-
final SocketChannel domainSocketChannel = SocketChannel
70-
.open(UnixDomainSocketAddress.of(domainSocket));
71-
executor.submit(
72-
() -> createChannelToChannelBiDirectionalHandler(byteBufferSize, httpClientChannel,
73-
domainSocketChannel).run());
54+
new Thread(() -> {
55+
try (final ServerSocketChannel serverChannel = ServerSocketChannel.open(StandardProtocolFamily.INET);
56+
final Selector selector = Selector.open()) {
57+
final InetSocketAddress address = new InetSocketAddress(LOCALHOST, clientHttpPort);
58+
serverChannel.bind(address);
59+
serverChannel.configureBlocking(false);
60+
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
61+
while (running.get()) {
62+
if (selector.select(SELECTOR_TIMEOUT_MS) > 0) {
63+
final Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
64+
while (keys.hasNext()) {
65+
final SelectionKey key = keys.next();
66+
keys.remove();
67+
if (key.isAcceptable()) {
68+
if (key.channel() instanceof final ServerSocketChannel keyChannel) {
69+
final SocketChannel httpClientChannel = keyChannel.accept();
70+
final SocketChannel domainSocketChannel = SocketChannel
71+
.open(UnixDomainSocketAddress.of(domainSocket));
72+
executor.submit(
73+
createChannelToChannelBiDirectionalHandler(byteBufferSize, httpClientChannel,
74+
domainSocketChannel));
75+
}
7476
}
7577
}
7678
}
7779
}
80+
} catch (final IOException e) {
81+
Log.errorf(e, "Error initialising domain proxy client");
7882
}
79-
} catch (final IOException e) {
80-
Log.errorf(e, "Error initialising domain proxy client");
81-
}
82-
Quarkus.asyncExit();
83+
Quarkus.asyncExit();
84+
}).start();
8385
}
8486

8587
@PreDestroy

java-components/domain-proxy/server/src/main/java/com/redhat/hacbs/domainproxy/server/DomainProxyServer.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,43 @@ public class DomainProxyServer {
5252
@PostConstruct
5353
public void start() {
5454
Log.infof("Byte buffer size %d", byteBufferSize); // TODO Remove
55-
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
56-
try {
57-
Files.delete(Path.of(domainSocket));
58-
} catch (final IOException e) {
59-
Log.errorf(e, "Error deleting domain socket");
60-
}
61-
}));
62-
try (final ServerSocketChannel serverChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
63-
final Selector selector = Selector.open()) {
64-
serverChannel.bind(UnixDomainSocketAddress.of(domainSocket));
65-
serverChannel.configureBlocking(false);
66-
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
67-
while (running.get()) {
68-
if (selector.select(SELECTOR_TIMEOUT_MS) > 0) {
69-
final Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
70-
while (keys.hasNext()) {
71-
final SelectionKey key = keys.next();
72-
keys.remove();
73-
if (key.isAcceptable()) {
74-
if (key.channel() instanceof final ServerSocketChannel keyChannel) {
75-
final SocketChannel domainSocketChannel = keyChannel.accept();
76-
final SocketChannel httpServerChannel = SocketChannel
77-
.open(new InetSocketAddress(LOCALHOST, httpServerPort));
78-
executor.submit(
79-
() -> createChannelToChannelBiDirectionalHandler(byteBufferSize, httpServerChannel,
80-
domainSocketChannel).run());
55+
new Thread(() -> {
56+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
57+
try {
58+
Files.delete(Path.of(domainSocket));
59+
} catch (final IOException e) {
60+
Log.errorf(e, "Error deleting domain socket");
61+
}
62+
}));
63+
try (final ServerSocketChannel serverChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
64+
final Selector selector = Selector.open()) {
65+
serverChannel.bind(UnixDomainSocketAddress.of(domainSocket));
66+
serverChannel.configureBlocking(false);
67+
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
68+
while (running.get()) {
69+
if (selector.select(SELECTOR_TIMEOUT_MS) > 0) {
70+
final Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
71+
while (keys.hasNext()) {
72+
final SelectionKey key = keys.next();
73+
keys.remove();
74+
if (key.isAcceptable()) {
75+
if (key.channel() instanceof final ServerSocketChannel keyChannel) {
76+
final SocketChannel domainSocketChannel = keyChannel.accept();
77+
final SocketChannel httpServerChannel = SocketChannel
78+
.open(new InetSocketAddress(LOCALHOST, httpServerPort));
79+
executor.submit(
80+
createChannelToChannelBiDirectionalHandler(byteBufferSize, httpServerChannel,
81+
domainSocketChannel));
82+
}
8183
}
8284
}
8385
}
8486
}
87+
} catch (final IOException e) {
88+
Log.errorf(e, "Error initialising domain proxy server");
8589
}
86-
} catch (final IOException e) {
87-
Log.errorf(e, "Error initialising domain proxy server");
88-
}
89-
Quarkus.asyncExit();
90+
Quarkus.asyncExit();
91+
}).start();
9092
}
9193

9294
@PreDestroy

0 commit comments

Comments
 (0)