Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 21 upgrade #93

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>runtime</scope>
</dependency>

<!-- for testing -->
Expand Down
8 changes: 7 additions & 1 deletion concurrent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<dependencies>
<dependency>
<groupId>io.airlift</groupId>
<groupId>com.facebook.airlift</groupId>
<artifactId>units</artifactId>
</dependency>

Expand Down Expand Up @@ -67,6 +67,12 @@
<artifactId>jmh-generator-annprocess</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-annotations</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.facebook.airlift.concurrent;

import com.google.common.collect.Streams;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.FutureCallback;
Expand Down Expand Up @@ -29,15 +30,14 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.propagateIfPossible;
import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

public final class MoreFutures
Expand Down Expand Up @@ -87,7 +87,7 @@ public void onFailure(Throwable t)
public static Throwable unwrapCompletionException(Throwable throwable)
{
if (throwable instanceof CompletionException) {
return firstNonNull(throwable.getCause(), throwable);
return requireNonNullElse(throwable.getCause(), throwable);
}
return throwable;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ public static void checkSuccess(Future<?> future, String errorMessage)
public static <V> ListenableFuture<V> whenAnyComplete(Iterable<? extends ListenableFuture<? extends V>> futures)
{
requireNonNull(futures, "futures is null");
checkArgument(!isEmpty(futures), "futures is empty");
checkArgument(Streams.stream(futures).findAny().isPresent(), "futures is empty");

ExtendedSettableFuture<V> firstCompletedFuture = ExtendedSettableFuture.create();
for (ListenableFuture<? extends V> future : futures) {
Expand All @@ -298,7 +298,7 @@ public static <V> ListenableFuture<V> whenAnyComplete(Iterable<? extends Listena
public static <V> ListenableFuture<V> whenAnyCompleteCancelOthers(Iterable<? extends ListenableFuture<? extends V>> futures)
{
requireNonNull(futures, "futures is null");
checkArgument(!isEmpty(futures), "futures is empty");
checkArgument(Streams.stream(futures).findAny().isPresent(), "futures is empty");

// wait for the first task to unblock and then cancel all futures to free up resources
ListenableFuture<V> anyComplete = whenAnyComplete(futures);
Expand Down Expand Up @@ -332,7 +332,7 @@ public static <V> CompletableFuture<V> firstCompletedFuture(Iterable<? extends C
public static <V> CompletableFuture<V> firstCompletedFuture(Iterable<? extends CompletionStage<? extends V>> futures, boolean propagateCancel)
{
requireNonNull(futures, "futures is null");
checkArgument(!isEmpty(futures), "futures is empty");
checkArgument(Streams.stream(futures).findAny().isPresent(), "futures is empty");

CompletableFuture<V> future = new CompletableFuture<>();
for (CompletionStage<? extends V> stage : futures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SetThreadName(String format, Object... args)
{
requireNonNull(format, "format is null");
originalThreadName = Thread.currentThread().getName();
Thread.currentThread().setName(String.format(format, args) + "-" + Thread.currentThread().getId());
Thread.currentThread().setName(String.format(format, args) + "-" + Thread.currentThread().threadId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.airlift.units.Duration;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -55,6 +56,7 @@
import static org.testng.Assert.fail;

@SuppressWarnings("deprecation")
@SuppressModernizer
public class TestMoreFutures
{
private final ScheduledExecutorService executorService = newSingleThreadScheduledExecutor(daemonThreadsNamed("test-%s"));
Expand Down
3 changes: 3 additions & 0 deletions configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<air.test.jvm.additional-arguments>
--add-opens java.base/java.lang=ALL-UNNAMED
</air.test.jvm.additional-arguments>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ConfigurationBinding(Key<T> key, Class<T> configClass, Optional<String> p
requireNonNull(key, "key");
requireNonNull(configClass, "configClass");
requireNonNull(prefix, "prefix is null");
checkArgument(!prefix.isPresent() || !prefix.get().isEmpty(), "prefix is empty");
prefix.ifPresent(str -> checkArgument(!str.isEmpty(), "prefix is empty"));

this.key = key;
this.configClass = configClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import static com.facebook.airlift.configuration.ConfigBinder.configBinder;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static org.testng.Assert.assertEquals;

public class TestConfigurationInspector
Expand Down Expand Up @@ -42,7 +42,7 @@ private ConfigRecord<?> getConfigRecord()
Map<String, String> properties = ImmutableMap.of("stringValue", "string");
ConfigurationFactory configurationFactory = new ConfigurationFactory(properties);
configurationFactory.registerConfigurationClasses(binder -> configBinder(binder).bindConfig(ConfigWithOptionalValue.class));
return getOnlyElement(new ConfigurationInspector().inspect(configurationFactory));
return new ConfigurationInspector().inspect(configurationFactory).stream().collect(onlyElement());
}

public static class ConfigWithOptionalValue
Expand Down
5 changes: 4 additions & 1 deletion dbpool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<air.test.jvm.additional-arguments>
--add-opens java.base/java.lang=ALL-UNNAMED
</air.test.jvm.additional-arguments>
</properties>

<dependencies>
Expand All @@ -32,7 +35,7 @@
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<groupId>com.facebook.airlift</groupId>
<artifactId>units</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.facebook.airlift.dbpool.H2EmbeddedDataSourceConfig.Cipher;
import com.google.common.io.Resources;
import com.google.common.primitives.Ints;
import org.h2.jdbcx.JdbcDataSource;
import org.h2.util.ScriptReader;

Expand All @@ -32,6 +31,7 @@
import java.sql.SQLException;
import java.sql.Statement;

import static java.lang.Math.toIntExact;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.SECONDS;
Expand Down Expand Up @@ -73,7 +73,7 @@ public H2EmbeddedDataSource(H2EmbeddedDataSourceConfig config)
else {
dataSource.setPassword("");
}
dataSource.setLoginTimeout(Ints.checkedCast(config.getMaxConnectionWait().roundTo(SECONDS)));
dataSource.setLoginTimeout(toIntExact(config.getMaxConnectionWait().roundTo(SECONDS)));

// connect to database and initialize database
Connection connection = getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.facebook.airlift.dbpool;

import com.google.common.primitives.Ints;
import io.airlift.units.Duration;
import org.weakref.jmx.Flatten;
import org.weakref.jmx.Managed;
Expand All @@ -36,6 +35,7 @@

import static io.airlift.units.Duration.nanosSince;
import static java.lang.Math.ceil;
import static java.lang.Math.toIntExact;

public abstract class ManagedDataSource
implements DataSource
Expand All @@ -53,7 +53,7 @@ protected ManagedDataSource(int maxConnections, Duration maxConnectionWait)
throw new NullPointerException("maxConnectionWait is null");
}
semaphore = new ManagedSemaphore(maxConnections);
maxConnectionWaitMillis.set(Ints.checkedCast(maxConnectionWait.toMillis()));
maxConnectionWaitMillis.set(toIntExact(maxConnectionWait.toMillis()));
}

@Override
Expand Down Expand Up @@ -143,7 +143,7 @@ public void setMaxConnectionWaitMillis(Duration maxConnectionWait)
throw new NullPointerException("maxConnectionWait is null");
}

int millis = Ints.checkedCast(maxConnectionWait.toMillis());
int millis = toIntExact(maxConnectionWait.toMillis());
if (millis < 1) {
throw new IllegalArgumentException("maxConnectionWait must be greater than 1 millisecond");
}
Expand Down
5 changes: 4 additions & 1 deletion discovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<air.test.jvm.additional-arguments>
--add-opens java.base/java.lang=ALL-UNNAMED
</air.test.jvm.additional-arguments>
</properties>

<dependencies>
Expand All @@ -31,7 +34,7 @@
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<groupId>com.facebook.airlift</groupId>
<artifactId>units</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String value()

public String toString()
{
return String.format("@%s(value=%s)", ServiceType.class.getName(), Annotations.memberValueString(value));
return String.format("@%s(%s)", ServiceType.class.getName(), Annotations.memberValueString(value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.facebook.airlift.discovery.client.ServiceSelector;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;

Expand All @@ -44,7 +44,7 @@ public StaticServiceSelector(Iterable<ServiceDescriptor> serviceDescriptors)
{
requireNonNull(serviceDescriptors, "serviceDescriptors is null");

ServiceDescriptor serviceDescriptor = Iterables.getFirst(serviceDescriptors, null);
ServiceDescriptor serviceDescriptor = Streams.stream(serviceDescriptors).findFirst().orElse(null);
if (serviceDescriptor != null) {
this.type = serviceDescriptor.getType();
this.pool = serviceDescriptor.getPool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import static com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder;
import static com.facebook.airlift.discovery.client.ServiceTypes.serviceType;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static java.util.Objects.requireNonNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
Expand Down Expand Up @@ -97,10 +97,10 @@ public void testMerging()
});

HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("http://127.0.0.1:4444"));
assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("http://127.0.0.1:4444"));

selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("banana")));
assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("http://127.0.0.1:4444"));
assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("http://127.0.0.1:4444"));

selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("carrot")));
assertTrue(selector.selectHttpService().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.facebook.airlift.json.JsonCodec;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import org.testng.annotations.Test;

Expand All @@ -28,6 +27,7 @@
import static com.facebook.airlift.json.JsonCodec.jsonCodec;
import static com.facebook.airlift.json.JsonCodec.mapJsonCodec;
import static com.facebook.airlift.testing.EquivalenceTester.equivalenceTester;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
Expand All @@ -53,7 +53,7 @@ public void testJsonEncode()

// set id in expected
List<Map<String, Object>> services = toServices(expected.get("services"));
services.get(0).put("id", Iterables.getOnlyElement(announcement.getServices()).getId().toString());
services.get(0).put("id", announcement.getServices().stream().collect(onlyElement()).getId().toString());

assertEquals(actual, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.facebook.airlift.discovery.client;

import com.facebook.airlift.discovery.client.testing.TestingDiscoveryModule;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
Expand All @@ -28,6 +27,7 @@

import static com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder;
import static com.facebook.airlift.discovery.client.ServiceAnnouncement.serviceAnnouncement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

Expand Down Expand Up @@ -154,7 +154,7 @@ private void assertAnnouncement(Set<ServiceAnnouncement> actualAnnouncements, Se
{
assertNotNull(actualAnnouncements);
assertEquals(actualAnnouncements.size(), 1);
ServiceAnnouncement announcement = Iterables.getOnlyElement(actualAnnouncements);
ServiceAnnouncement announcement = actualAnnouncements.stream().collect(onlyElement());
assertEquals(announcement.getType(), expected.getType());
assertEquals(announcement.getProperties(), expected.getProperties());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder;
import static com.facebook.airlift.discovery.client.ServiceAnnouncement.serviceAnnouncement;
import static com.facebook.airlift.discovery.client.ServiceTypes.serviceType;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static org.testng.Assert.assertEquals;

public class TestHttpServiceSelectorBinder
Expand All @@ -51,7 +51,7 @@ public void testHttpSelectorString()
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build()));

HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http"));
assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-http"));
}

@Test
Expand All @@ -67,7 +67,7 @@ public void testHttpSelectorAnnotation()
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build()));

HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http"));
assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-http"));

ServiceSelectorManager manager = injector.getInstance(ServiceSelectorManager.class);
assertEquals(manager.getServiceSelectors().size(), 1);
Expand All @@ -88,7 +88,7 @@ public void testHttpsSelector()
discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("https", "fake://server-https").build()));

HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-https"));
assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-https"));
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion event/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<groupId>com.facebook.airlift</groupId>
<artifactId>units</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
Expand Down
Loading
Loading