13
0
geforkt von Mirrors/Velocity

Relax registration checks for same servers somewhat.

If a server with the same ServerInfo is attempting to be re-registered,
we will return the existing registered server, which is less surprising
behavior than before.
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-10-21 20:03:38 -04:00
Ursprung 3bd48dec99
Commit f6cac0f50a
2 geänderte Dateien mit 17 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -34,8 +34,15 @@ public class ServerMap {
Preconditions.checkNotNull(serverInfo, "serverInfo"); Preconditions.checkNotNull(serverInfo, "serverInfo");
String lowerName = serverInfo.getName().toLowerCase(Locale.US); String lowerName = serverInfo.getName().toLowerCase(Locale.US);
VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo); VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo);
Preconditions.checkArgument(servers.putIfAbsent(lowerName, rs) == null, "Server with name %s already registered", serverInfo.getName());
RegisteredServer existing = servers.putIfAbsent(lowerName, rs);
if (existing != null && !existing.getServerInfo().equals(serverInfo)) {
throw new IllegalArgumentException("Server with name " + serverInfo.getName() + " already registered");
} else if (existing == null) {
return rs; return rs;
} else {
return existing;
}
} }
public void unregister(ServerInfo serverInfo) { public void unregister(ServerInfo serverInfo) {

Datei anzeigen

@ -35,4 +35,12 @@ class ServerMapTest {
ServerInfo willReject = new ServerInfo("TESTSERVER", TEST_ADDRESS); ServerInfo willReject = new ServerInfo("TESTSERVER", TEST_ADDRESS);
assertThrows(IllegalArgumentException.class, () -> map.register(willReject)); assertThrows(IllegalArgumentException.class, () -> map.register(willReject));
} }
@Test
void allowsSameServerLaxRegistrationCheck() {
ServerMap map = new ServerMap(null);
ServerInfo info = new ServerInfo("TestServer", TEST_ADDRESS);
RegisteredServer connection = map.register(info);
assertEquals(connection, map.register(info));
}
} }