Skip to content

Commit

Permalink
Merge pull request #2624 from rsksmart/vovchyk/min-java-ver-bump
Browse files Browse the repository at this point in the history
chore: increase min supported java version to 17
  • Loading branch information
Vovchyk authored Sep 25, 2024
2 parents d27c6b9 + a808164 commit 87d4895
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 87 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ on:
jobs:
build:
runs-on: ubuntu-latest
container:
image: openjdk:8-jdk
steps:
- uses: actions/checkout@v4
- name: Setup System Tools
run: |
apt update -y
apt install -y gnupg2 curl

- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Verify files
run: |
Expand Down Expand Up @@ -250,15 +250,14 @@ jobs:
unit-tests:
needs: build
runs-on: ubuntu-latest
container:
image: openjdk:8-jdk
steps:
- uses: actions/checkout@v4

- name: Setup System Tools
run: |
apt update -y
apt install -y curl
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- uses: actions/cache@v4
name: Cache Gradle
Expand Down Expand Up @@ -297,15 +296,14 @@ jobs:
integration-tests:
runs-on: ubuntu-latest
container:
image: openjdk:8-jdk
steps:
- uses: actions/checkout@v4

- name: Setup System Tools
run: |
apt update -y
apt install -y curl
- name: Setup Java JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- uses: actions/cache@v4
name: Cache Gradle
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,27 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Java JDK
if: ${{ matrix.language == 'java' }}
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Before Index (java)
if: ${{ matrix.language == 'java' }}
run: ./configure.sh

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11-jdk-slim-buster AS build
FROM eclipse-temurin:17-jdk AS build

RUN apt-get update -y && \
apt-get install -y git curl gnupg
Expand All @@ -19,7 +19,7 @@ RUN gpg --keyserver https://secchannel.rsk.co/SUPPORT.asc --recv-keys 1DC9157991
modifier=$(sed -n 's/^modifier=//p' "$file" | tr -d "\"'") && \
cp "rskj-core/build/libs/rskj-core-$version_number-$modifier-all.jar" rsk.jar

FROM openjdk:11-jre-slim-buster
FROM eclipse-temurin:17-jre
LABEL org.opencontainers.image.authors="[email protected]"

RUN useradd -ms /sbin/nologin -d /var/lib/rsk rsk
Expand Down
4 changes: 2 additions & 2 deletions rskj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ repositories {
}
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17

mainClassName = 'co.rsk.Start'
applicationDefaultJvmArgs = ["-server", "-Xss32m", "-Xms3G", "-XX:+UseCompressedOops", "-XX:-OmitStackTraceInFastThrow"]
Expand Down
6 changes: 3 additions & 3 deletions rskj-core/src/main/java/co/rsk/net/NodeMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void run() {
long startNanos = System.nanoTime();
logStart(task);
this.processMessage(task.getSender(), task.getMessage());
logEnd(task, startNanos);
logEnd(task, startNanos, loggerMessageProcess);
} else {
logger.trace("No task");
}
Expand Down Expand Up @@ -362,7 +362,7 @@ private void logStart(MessageTask task) {
}

@VisibleForTesting
void logEnd(MessageTask task, long startNanos) {
static void logEnd(MessageTask task, long startNanos, Logger messageProcessingLogger) {
Duration processTime = Duration.ofNanos(System.nanoTime() - startNanos);

Message message = task.getMessage();
Expand All @@ -371,7 +371,7 @@ void logEnd(MessageTask task, long startNanos) {
boolean isOtherSlow = !isBlockRelated && processTime.getSeconds() > PROCESSING_TIME_TO_WARN_LIMIT;

if (isBlockSlow || isOtherSlow) {
loggerMessageProcess.warn("Message[{}] processing took too much: [{}]s.", message.getMessageType(), processTime.getSeconds());
messageProcessingLogger.warn("Message[{}] processing took too much: [{}]s.", message.getMessageType(), processTime.getSeconds());
}

logger.trace("End {} message task after [{}]s", task.getMessage().getMessageType(), processTime.getSeconds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class PreflightChecksUtils {
private static final Logger logger = LoggerFactory.getLogger(PreflightChecksUtils.class);

private static final int[] SUPPORTED_JAVA_VERSIONS = {8, 11, 17};
private static final int[] SUPPORTED_JAVA_VERSIONS = {17};

private final RskContext rskContext;

Expand Down
17 changes: 8 additions & 9 deletions rskj-core/src/test/java/co/rsk/net/NodeMessageHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
import co.rsk.net.sync.PeersInformation;
import co.rsk.net.sync.SyncConfiguration;
import co.rsk.net.utils.TransactionUtils;
import co.rsk.scoring.*;
import co.rsk.scoring.EventType;
import co.rsk.scoring.PeerScoring;
import co.rsk.scoring.PeerScoringManager;
import co.rsk.scoring.PunishmentParameters;
import co.rsk.test.World;
import co.rsk.test.builders.BlockChainBuilder;
import co.rsk.validators.*;
Expand Down Expand Up @@ -932,41 +935,37 @@ void testTooLongProcessing() {
final ChannelManager channelManager = mock(ChannelManager.class);
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(sender));

final NodeMessageHandler handler = NodeMessageHandlerUtil.createHandlerWithSyncProcessor(SyncConfiguration.IMMEDIATE_FOR_TESTING, channelManager);

BlockGenerator blockGenerator = new BlockGenerator();
final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());

{
Logger loggerNonBlock = mock(Logger.class);
TestUtils.setFinalStatic(handler, "loggerMessageProcess", loggerNonBlock);

final Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), new BlockDifficulty(BigInteger.TEN));
final Message message1 = new StatusMessage(status);
NodeMessageHandler.MessageTask task1 = new NodeMessageHandler.MessageTask(sender, message1, 100, new NodeMsgTraceInfo("testMsg", "testSession"));

// fake old start: 1st warn
handler.logEnd(task1, System.nanoTime() - Duration.ofSeconds(3).toNanos());
NodeMessageHandler.logEnd(task1, System.nanoTime() - Duration.ofSeconds(3).toNanos(), loggerNonBlock);
verify(loggerNonBlock, times(1)).warn(argThat(s -> s.contains("processing took too much")), eq(message1.getMessageType()), anyLong());

// fake recent start: still 1 one warn
handler.logEnd(task1, System.nanoTime() - Duration.ofMillis(5).toNanos());
NodeMessageHandler.logEnd(task1, System.nanoTime() - Duration.ofMillis(5).toNanos(), loggerNonBlock);
verify(loggerNonBlock, times(1)).warn(argThat(s -> s.contains("processing took too much")), eq(message1.getMessageType()), anyLong());
}

{
Logger loggerBlock = mock(Logger.class);
TestUtils.setFinalStatic(handler, "loggerMessageProcess", loggerBlock);

final Message message2 = new BlockMessage(block);
NodeMessageHandler.MessageTask task2 = new NodeMessageHandler.MessageTask(sender, message2, 100, new NodeMsgTraceInfo("testMsg2", "testSession2"));

// fake old start for block: 1st warn
handler.logEnd(task2, System.nanoTime() - Duration.ofSeconds(61).toNanos());
NodeMessageHandler.logEnd(task2, System.nanoTime() - Duration.ofSeconds(61).toNanos(), loggerBlock);
verify(loggerBlock, times(1)).warn(argThat(s -> s.contains("processing took too much")), eq(message2.getMessageType()), anyLong());

// fake old start for non-block: still 1 warn, Block has higher threshold for warn
handler.logEnd(task2, System.nanoTime() - Duration.ofSeconds(3).toNanos());
NodeMessageHandler.logEnd(task2, System.nanoTime() - Duration.ofSeconds(3).toNanos(), loggerBlock);
verify(loggerBlock, times(1)).warn(argThat(s -> s.contains("processing took too much")), eq(message2.getMessageType()), anyLong());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void runChecks_invalidJavaVersion_exceptionIsThrown() {
when(preflightChecksUtilsSpy.getJavaVersion()).thenReturn("16");

Exception exception = Assertions.assertThrows(PreflightCheckException.class, preflightChecksUtilsSpy::runChecks);
Assertions.assertEquals("Invalid Java Version '16'. Supported versions: 8 11 17", exception.getMessage());
Assertions.assertEquals("Invalid Java Version '16'. Supported versions: 17", exception.getMessage());

rskContext.close();
}
Expand All @@ -80,21 +80,6 @@ void runChecks_currentJavaVersionIs17_OK() throws Exception {
rskContext.close();
}

@Test
void runChecks_currentJavaVersionIs11_OK() throws Exception {
RskContext rskContext = new RskTestContext(tempDir);
PreflightChecksUtils preflightChecksUtilsSpy = spy(new PreflightChecksUtils(rskContext));

when(preflightChecksUtilsSpy.getJavaVersion()).thenReturn("11");

preflightChecksUtilsSpy.runChecks();

verify(preflightChecksUtilsSpy, times(1)).getJavaVersion();
verify(preflightChecksUtilsSpy, times(1)).getIntJavaVersion("11");

rskContext.close();
}

@Test
void runChecks_runAllChecks_OK() throws Exception {
RskContext rskContext = new RskTestContext(tempDir);
Expand Down
16 changes: 0 additions & 16 deletions rskj-core/src/test/java/org/ethereum/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import javax.annotation.Nonnull;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -173,21 +172,6 @@ public static <T extends Exception> T assertThrows(Class<T> c, Runnable f) {
return c.cast(thrownException);
}

public static <T, V> void setFinalStatic(T instance, String fieldName, V value) {
try {
Field field = getPrivateField(instance, fieldName);
field.setAccessible(true);

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

field.set(null, value);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new WhiteboxException("Could not set private static field", e);
}
}

public static <T, V> void setInternalState(T instance, String fieldName, V value) {
Field field = getPrivateField(instance, fieldName);
field.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,21 @@
import org.ethereum.sync.SyncPool;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.time.Duration;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.LongSupplier;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

/**
* @author Roman Mandeleil
Expand Down Expand Up @@ -102,12 +99,7 @@ void blockAddressCheck_logInvalidInetAddressException() throws UnknownHostExcept
channelManager.add(peer);
channelManager.tryProcessNewPeers();

Logger logger = mock(Logger.class);
TestUtils.setFinalStatic(channelManager, "logger", logger);

Assertions.assertTrue(channelManager.isAddressBlockAvailable(otherPeer.getInetSocketAddress().getAddress()));

verify(logger).error(anyString(), any(Throwable.class));
}

@Test
Expand Down Expand Up @@ -217,10 +209,6 @@ void testLogActivePeers() {
final ChannelManagerImpl channelManager = new ChannelManagerImpl(mock(RskSystemProperties.class), mock(SyncPool.class));
channelManager.setActivePeers(activePeers);

Logger logger = mock(Logger.class);
TestUtils.setFinalStatic(channelManager, "logger", logger);
when(logger.isDebugEnabled()).thenReturn(true);

LongSupplier timeLastLoggedPeersSupplier = () -> TestUtils.getInternalState(channelManager, "timeLastLoggedPeers");

// not enough time passed to log peers again, timeLastLoggedPeers should remain intact
Expand Down

0 comments on commit 87d4895

Please sign in to comment.