Skip to content

Commit 080149d

Browse files
authored
Maintenance: tidy up IPC locks, make exclusive test timeout a bit longer (#1849)
1 parent a4c4240 commit 080149d

9 files changed

Lines changed: 14 additions & 30 deletions

File tree

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/ByteChannelWrapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* @since 2.0.1
3030
*/
3131
public class ByteChannelWrapper implements ByteChannel {
32-
3332
private final ByteChannel socket;
3433

3534
public ByteChannelWrapper(ByteChannel socket) {

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ void ensureInitialized() throws IOException {
116116
}
117117

118118
SocketChannel createClient() throws IOException {
119-
String familyProp = System.getProperty(IpcServer.SYSTEM_PROP_FAMILY, IpcServer.DEFAULT_FAMILY);
120-
SocketFamily family = familyProp != null ? SocketFamily.valueOf(familyProp) : SocketFamily.inet;
119+
SocketFamily family =
120+
SocketFamily.valueOf(System.getProperty(IpcServer.SYSTEM_PROP_FAMILY, IpcServer.DEFAULT_FAMILY));
121121

122122
Path lockPath = this.lockPath.toAbsolutePath().normalize();
123123
Path lockFile =
@@ -414,7 +414,7 @@ void unlock(String contextId) {
414414
*/
415415
void stopServer() {
416416
try {
417-
List<String> response = send(Arrays.asList(REQUEST_STOP), Long.MAX_VALUE, TimeUnit.MILLISECONDS);
417+
List<String> response = send(List.of(REQUEST_STOP), Long.MAX_VALUE, TimeUnit.MILLISECONDS);
418418
if (response.size() != 1 || !RESPONSE_STOP.equals(response.get(0))) {
419419
throw new IOException("Unexpected response: " + response);
420420
}

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcMessages.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* @since 2.0.1
2525
*/
2626
public class IpcMessages {
27-
2827
public static final String REQUEST_CONTEXT = "request-context";
2928
public static final String REQUEST_ACQUIRE = "request-acquire";
3029
public static final String REQUEST_CLOSE = "request-close";

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcNamedLock.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,5 @@ public void doUnlock() {
9595
}
9696
}
9797

98-
private static final class Ctx {
99-
private final boolean acted;
100-
private final String contextId;
101-
private final boolean shared;
102-
103-
private Ctx(boolean acted, String contextId, boolean shared) {
104-
this.acted = acted;
105-
this.contextId = contextId;
106-
this.shared = shared;
107-
}
108-
}
98+
private record Ctx(boolean acted, String contextId, boolean shared) {}
10999
}

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcNamedLockFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public IpcNamedLockFactory(Path ipcHome) {
5656
requireNonNull(ipcHome);
5757
Path repository = ipcHome.resolve("repository");
5858
Path logPath = ipcHome.resolve("log");
59-
Path syncPath = null;
60-
this.client = new IpcClient(repository, logPath, syncPath);
59+
this.client = new IpcClient(repository, logPath, null);
6160
}
6261

6362
@Override

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/IpcServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private void client(SocketChannel socket) {
271271
}
272272
break;
273273
case IpcMessages.REQUEST_ACQUIRE:
274-
if (request.size() < 1) {
274+
if (request.isEmpty()) {
275275
throw new IOException(
276276
"Expected at least one argument for " + command + " but got " + request);
277277
}
@@ -321,7 +321,7 @@ private void client(SocketChannel socket) {
321321
}
322322
break;
323323
case IpcMessages.REQUEST_STOP:
324-
if (request.size() != 0) {
324+
if (!request.isEmpty()) {
325325
throw new IOException("Expected zero argument for " + command + " but got " + request);
326326
}
327327
synchronized (output) {

maven-resolver-named-locks-ipc/src/main/java/org/eclipse/aether/named/ipc/SocketFamily.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ public enum SocketFamily {
3838
unix;
3939

4040
public ServerSocketChannel openServerSocket() throws IOException {
41-
switch (this) {
42-
case inet:
43-
return ServerSocketChannel.open().bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
44-
case unix:
45-
return ServerSocketChannel.open(StandardProtocolFamily.UNIX).bind(null, 0);
46-
default:
47-
throw new IllegalStateException();
48-
}
41+
return switch (this) {
42+
case inet -> ServerSocketChannel.open().bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
43+
case unix -> ServerSocketChannel.open(StandardProtocolFamily.UNIX).bind(null, 0);
44+
default -> throw new IllegalStateException();
45+
};
4946
}
5047

5148
public static SocketAddress fromString(String str) {

maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/NamedLockFactoryAdapterTestSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void sharedAccess() throws InterruptedException {
114114
}
115115

116116
@Test
117-
@Timeout(15)
117+
@Timeout(25)
118118
public void exclusiveAccess() throws InterruptedException {
119119
CountDownLatch winners = new CountDownLatch(1); // we expect 1 winner
120120
CountDownLatch losers = new CountDownLatch(1); // we expect 1 loser

maven-resolver-named-locks-ipc/src/test/java/org/eclipse/aether/named/ipc/NamedLockFactoryTestSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void sharedAccess(TestInfo testInfo) throws InterruptedException {
135135
}
136136

137137
@Test
138-
@Timeout(15)
138+
@Timeout(25)
139139
public void exclusiveAccess(TestInfo testInfo) throws InterruptedException {
140140
final Collection<NamedLockKey> keys = Collections.singleton(NamedLockKey.of(testInfo.getDisplayName()));
141141
CountDownLatch winners = new CountDownLatch(1); // we expect 1 winner

0 commit comments

Comments
 (0)