Skip to content

Commit

Permalink
Merge pull request valkey-io#1093 from Bit-Quill/java/integ_SanH_chan…
Browse files Browse the repository at this point in the history
…ge_VersionChecking

Java: Use 3rd party lib for version checking. (#130)
  • Loading branch information
Elen-Ghulam authored Mar 12, 2024
2 parents 3c1b696 + cf2b2e1 commit e180be8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
3 changes: 3 additions & 0 deletions java/integTest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ dependencies {
// junit
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
testImplementation 'org.mockito:mockito-junit-jupiter:3.12.4'

// semver4j for semantic versioning
implementation 'com.vdurmont:semver4j:3.1.0'
}

def standaloneRedisPorts = []
Expand Down
8 changes: 4 additions & 4 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,15 @@ public void expire_pexpire_and_ttl_with_positive_timeout(BaseClient client) {

// set command clears the timeout.
assertEquals(OK, client.set(key, "pexpire_timeout").get());
if (REDIS_VERSION.feature() < 7) {
if (REDIS_VERSION.isLowerThan("7.0.0")) {
assertTrue(client.pexpire(key, 10000L).get());
} else {
assertTrue(client.pexpire(key, 10000L, ExpireOptions.HAS_NO_EXPIRY).get());
}
assertTrue(client.ttl(key).get() <= 10L);

// TTL will be updated to the new value = 15
if (REDIS_VERSION.feature() < 7) {
if (REDIS_VERSION.isLowerThan("7.0.0")) {
assertTrue(client.expire(key, 15L).get());
} else {
assertTrue(client.expire(key, 15L, ExpireOptions.HAS_EXISTING_EXPIRY).get());
Expand All @@ -776,7 +776,7 @@ public void expireAt_pexpireAt_and_ttl_with_positive_timeout(BaseClient client)
assertTrue(client.ttl(key).get() <= 10L);

// extend TTL
if (REDIS_VERSION.feature() < 7) {
if (REDIS_VERSION.isLowerThan("7.0.0")) {
assertTrue(client.expireAt(key, Instant.now().getEpochSecond() + 50L).get());
} else {
assertTrue(
Expand All @@ -789,7 +789,7 @@ public void expireAt_pexpireAt_and_ttl_with_positive_timeout(BaseClient client)
}
assertTrue(client.ttl(key).get() <= 50L);

if (REDIS_VERSION.feature() < 7) {
if (REDIS_VERSION.isLowerThan("7.0.0")) {
assertTrue(client.pexpireAt(key, Instant.now().toEpochMilli() + 50000L).get());
} else {
// set command clears the timeout.
Expand Down
5 changes: 2 additions & 3 deletions java/integTest/src/test/java/glide/TestConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
package glide;

import java.lang.Runtime.Version;
import com.vdurmont.semver4j.Semver;
import java.util.Arrays;

public final class TestConfiguration {
// All redis servers are hosted on localhost
public static final int[] STANDALONE_PORTS = getPortsFromProperty("test.redis.standalone.ports");
public static final int[] CLUSTER_PORTS = getPortsFromProperty("test.redis.cluster.ports");
public static final Version REDIS_VERSION =
Version.parse(System.getProperty("test.redis.version"));
public static final Semver REDIS_VERSION = new Semver(System.getProperty("test.redis.version"));

private static int[] getPortsFromProperty(String propName) {
return Arrays.stream(System.getProperty(propName).split(","))
Expand Down
8 changes: 4 additions & 4 deletions java/integTest/src/test/java/glide/cluster/CommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class CommandTests {
"Cluster",
"Keyspace");
public static final List<String> EVERYTHING_INFO_SECTIONS =
REDIS_VERSION.feature() >= 7
REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")
// Latencystats was added in redis 7
? List.of(
"Server",
Expand Down Expand Up @@ -204,7 +204,7 @@ public void info_with_multi_node_route() {
@SneakyThrows
public void info_with_multiple_options() {
InfoOptions.InfoOptionsBuilder builder = InfoOptions.builder().section(CLUSTER);
if (REDIS_VERSION.feature() >= 7) {
if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
builder.section(CPU).section(MEMORY);
}
InfoOptions options = builder.build();
Expand Down Expand Up @@ -249,7 +249,7 @@ public void info_with_single_node_route_and_options() {
(String) ((Object[]) ((Object[]) ((Object[]) slotData.getSingleValue())[0])[2])[2];

InfoOptions.InfoOptionsBuilder builder = InfoOptions.builder().section(CLIENTS);
if (REDIS_VERSION.feature() >= 7) {
if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
builder.section(COMMANDSTATS).section(REPLICATION);
}
InfoOptions options = builder.build();
Expand All @@ -267,7 +267,7 @@ public void info_with_single_node_route_and_options() {
@SneakyThrows
public void info_with_multi_node_route_and_options() {
InfoOptions.InfoOptionsBuilder builder = InfoOptions.builder().section(CLIENTS);
if (REDIS_VERSION.feature() >= 7) {
if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
builder.section(COMMANDSTATS).section(REPLICATION);
}
InfoOptions options = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void info_without_options() {
@SneakyThrows
public void info_with_multiple_options() {
InfoOptions.InfoOptionsBuilder builder = InfoOptions.builder().section(CLUSTER);
if (REDIS_VERSION.feature() >= 7) {
if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) {
builder.section(CPU).section(MEMORY);
}
InfoOptions options = builder.build();
Expand Down

0 comments on commit e180be8

Please sign in to comment.