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

[CALCITE-5748] Upgrade guava from 31.1-jre to 32.0.0-jre #3240

Closed
wants to merge 12 commits into from
Closed
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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
name: 'Linux (JDK 17)'
runs-on: ubuntu-latest
env:
GUAVA: '31.1-jre'
GUAVA: '32.0.0-jre'
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -194,7 +194,7 @@ jobs:
name: 'Linux (JDK 19)'
runs-on: ubuntu-latest
env:
GUAVA: '31.1-jre'
GUAVA: '32.0.0-jre'
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -314,10 +314,10 @@ jobs:

errorprone-guava31: # LTS JDK version, don't remove until EOL
if: github.event.action != 'labeled'
name: 'Error Prone (JDK 11), Guava 31'
name: 'Error Prone (JDK 11), Guava 32'
runs-on: ubuntu-latest
env:
GUAVA: '31.1-jre' # ErrorProne checks for Beta APIs, so use the newest supported Guava version
GUAVA: '32.0.0-jre' # ErrorProne checks for Beta APIs, so use the newest supported Guava version
steps:
- uses: actions/checkout@v3
with:
Expand Down
9 changes: 0 additions & 9 deletions core/src/main/java/org/apache/calcite/runtime/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,6 @@ public <T> Closeable addThread(final Consumer<T> handler) {
return () -> removeThread(handler);
}

// CHECKSTYLE: IGNORE 1
/** @deprecated Use {@link #addThread(Consumer)}. */
@SuppressWarnings("Guava")
@Deprecated // to be removed before 2.0
public <T, R> Closeable addThread(
final com.google.common.base.Function<T, R> handler) {
return addThread((Consumer<T>) handler::apply);
}
Comment on lines -164 to -169
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With guava 32 it starts failing on errorprone checks with CheckReturnValue
Since it is already deprecated with a comment what to use instead probably it makes sense to remove it


/** Removes a thread handler from this Hook. */
private boolean removeThread(Consumer handler) {
return castNonNull(threadHandlers.get()).remove(handler);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ foodmart-data-hsqldb.version=0.5
foodmart-data-json.version=0.4
foodmart-queries.version=0.4.1
geode-core.version=1.15.1
guava.version=31.1-jre
guava.version=32.0.0-jre
h2.version=2.1.210
hadoop.version=2.7.5
hamcrest-date.version=2.0.4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
*
* http://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 org.apache.calcite.adapter.redis;

import org.apache.commons.io.FileUtils;

import com.google.common.io.Resources;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import redis.embedded.util.Architecture;
import redis.embedded.util.OS;
import redis.embedded.util.OsArchitecture;

/**
* This is almost a copy of {@link redis.embedded.RedisExecProvider} invoking
* {@link redis.embedded.util.JarUtil} under the hood.
* The problem is that it calls deprecated guava's {@link com.google.common.io.Files#createTempDir()}
* resulting in ''posix:permissions' not supported as initial attribute' on Windows.
*/
public class CalciteTestRedisExecProvider {
private final Map<OsArchitecture, String> executables = new HashMap<>();

public static CalciteTestRedisExecProvider defaultProvider() {
return new CalciteTestRedisExecProvider();
}

private CalciteTestRedisExecProvider() {
initExecutables();
}

private void initExecutables() {
executables.put(OsArchitecture.WINDOWS_x86, "redis-server-2.8.19.exe");
executables.put(OsArchitecture.WINDOWS_x86_64, "redis-server-2.8.19.exe");

executables.put(OsArchitecture.UNIX_x86, "redis-server-2.8.19");
executables.put(OsArchitecture.UNIX_x86_64, "redis-server-2.8.19");

executables.put(OsArchitecture.MAC_OS_X_x86, "redis-server-2.8.19.app");
executables.put(OsArchitecture.MAC_OS_X_x86_64, "redis-server-2.8.19.app");
}

public CalciteTestRedisExecProvider override(OS os, String executable) {
Objects.requireNonNull(executable, "executable");
for (Architecture arch : Architecture.values()) {
override(os, arch, executable);
}
return this;
}

public CalciteTestRedisExecProvider override(OS os, Architecture arch, String executable) {
Objects.requireNonNull(executable, "executable");
executables.put(new OsArchitecture(os, arch), executable);
return this;
}

public File get() throws IOException {
OsArchitecture osArch = OsArchitecture.detect();
String executablePath = executables.get(osArch);
return fileExists(executablePath)
? new File(executablePath)
: JarUtil.extractExecutableFromJar(executablePath);
}

private boolean fileExists(String executablePath) {
return new File(executablePath).exists();
}

/**
* Calcite version of {@link redis.embedded.util.JarUtil}
* allowing to make it work on Windows with Guava 32.0.0+.
*/
private static class JarUtil {
public static File extractExecutableFromJar(String executable) throws IOException {
Path tmpDir = Files.createTempDirectory("redis");

File command = tmpDir.resolve(executable).toFile();
FileUtils.copyURLToFile(Resources.getResource(executable), command);
command.deleteOnExit();
command.setExecutable(true);

return command;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
*
* http://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 org.apache.calcite.adapter.redis;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import redis.embedded.RedisServer;
import redis.embedded.RedisServerBuilder;

/**
* This is almost a copy of {@link RedisServer}.
* The difference is that it makes {@link CalciteTestRedisServer#CalciteTestRedisServer(List, int)}
* public, adds {@link CalciteTestRedisServer#testBuilder()}.
*/
public class CalciteTestRedisServer extends RedisServer {
private static CalciteTestRedisExecProvider redisExecProvider =
CalciteTestRedisExecProvider.defaultProvider();

public CalciteTestRedisServer(File executable, Integer port) {
super(executable, port);
}

public CalciteTestRedisServer(List<String> args, int port) throws IOException {
super(redisExecProvider.get(), port);
this.args = new ArrayList<>(args);
}

public static CalciteTestRedisServerBuilder testBuilder() {
return new CalciteTestRedisServerBuilder();
}

public static RedisServerBuilder builder() {
throw new RuntimeException("Use CalciteTestRedisServer#testBuilder");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
*
* http://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 org.apache.calcite.adapter.redis;

import com.google.common.base.Strings;
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import redis.embedded.RedisServerBuilder;
import redis.embedded.exceptions.RedisBuildingException;

/**
* This is almost a copy of {@link RedisServerBuilder}.
* The difference is that it works with {@link CalciteTestRedisExecProvider}.
*/
public class CalciteTestRedisServerBuilder {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String CONF_FILENAME = "embedded-redis-server";

private File executable;
private CalciteTestRedisExecProvider redisExecProvider =
CalciteTestRedisExecProvider.defaultProvider();
private Integer port = 6379;
private InetSocketAddress slaveOf;
private String redisConf;

private StringBuilder redisConfigBuilder;

public CalciteTestRedisServerBuilder redisExecProvider(
CalciteTestRedisExecProvider redisExecProvider) {
this.redisExecProvider = redisExecProvider;
return this;
}

public CalciteTestRedisServerBuilder port(Integer port) {
this.port = port;
return this;
}

public CalciteTestRedisServerBuilder slaveOf(String hostname, Integer port) {
this.slaveOf = new InetSocketAddress(hostname, port);
return this;
}

public CalciteTestRedisServerBuilder slaveOf(InetSocketAddress slaveOf) {
this.slaveOf = slaveOf;
return this;
}

public CalciteTestRedisServerBuilder configFile(String redisConf) {
if (redisConfigBuilder != null) {
throw new RedisBuildingException(
"Redis configuration is already partially build using setting(String) method!");
}
this.redisConf = redisConf;
return this;
}

public CalciteTestRedisServerBuilder setting(String configLine) {
if (redisConf != null) {
throw new RedisBuildingException("Redis configuration is already set using redis conf file!");
}

if (redisConfigBuilder == null) {
redisConfigBuilder = new StringBuilder();
}

redisConfigBuilder.append(configLine);
redisConfigBuilder.append(LINE_SEPARATOR);
return this;
}

public CalciteTestRedisServer build() {
tryResolveConfAndExec();
List<String> args = buildCommandArgs();
try {
return new CalciteTestRedisServer(args, port);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public void reset() {
this.executable = null;
this.redisConfigBuilder = null;
this.slaveOf = null;
this.redisConf = null;
}

private void tryResolveConfAndExec() {
try {
resolveConfAndExec();
} catch (IOException e) {
throw new RedisBuildingException("Could not build server instance", e);
}
}

private void resolveConfAndExec() throws IOException {
if (redisConf == null && redisConfigBuilder != null) {
File redisConfigFile = File.createTempFile(resolveConfigName(), ".conf");
redisConfigFile.deleteOnExit();
Files.asCharSink(redisConfigFile, StandardCharsets.UTF_8)
.write(redisConfigBuilder.toString());
redisConf = redisConfigFile.getAbsolutePath();
}

try {
executable = redisExecProvider.get();
} catch (Exception e) {
throw new RedisBuildingException("Failed to resolve executable", e);
}
}

private String resolveConfigName() {
return CONF_FILENAME + "_" + port;
}

private List<String> buildCommandArgs() {
List<String> args = new ArrayList<String>();
args.add(executable.getAbsolutePath());

if (!Strings.isNullOrEmpty(redisConf)) {
args.add(redisConf);
}

if (port != null) {
args.add("--port");
args.add(Integer.toString(port));
}

if (slaveOf != null) {
args.add("--slaveof");
args.add(slaveOf.getHostName());
args.add(Integer.toString(slaveOf.getPort()));
}

return args;
}
}
Loading