-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fetch server version using info command #2258
Changes from 2 commits
558321d
272e69c
699bed7
b35bec3
9b4ee91
33383e9
3374abc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,18 +1,58 @@ | ||||||
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ | ||||||
/** | ||||||
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||||||
*/ | ||||||
package glide; | ||||||
|
||||||
import com.vdurmont.semver4j.Semver; | ||||||
import glide.api.GlideClient; | ||||||
import glide.api.models.commands.InfoOptions; | ||||||
|
||||||
import java.util.Arrays; | ||||||
|
||||||
import static glide.TestUtilities.commonClientConfig; | ||||||
|
||||||
public final class TestConfiguration { | ||||||
// All servers are hosted on localhost | ||||||
public static final int[] STANDALONE_PORTS = getPortsFromProperty("test.server.standalone.ports"); | ||||||
public static final int[] CLUSTER_PORTS = getPortsFromProperty("test.server.cluster.ports"); | ||||||
public static final Semver SERVER_VERSION = new Semver(System.getProperty("test.server.version")); | ||||||
private static final GlideClient standaloneClient; | ||||||
public static final Semver SERVER_VERSION; | ||||||
|
||||||
static { | ||||||
try { | ||||||
standaloneClient = GlideClient.createClient(commonClientConfig().build()).get(); | ||||||
String infoResponse = standaloneClient.info( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need static lifetime for the client There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||||||
InfoOptions.builder() | ||||||
.section(InfoOptions.Section.SERVER) | ||||||
.build() | ||||||
).get(); | ||||||
String serverVersion = null; | ||||||
String[] serverSectionArray = infoResponse.split("\n"); | ||||||
|
||||||
for (int i = 0; i < serverSectionArray.length; i++) { | ||||||
if (serverSectionArray[i].contains("redis_version")) { | ||||||
String[] versionKeyValue = serverSectionArray[i].split(":"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for valkey version first
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||||||
if (versionKeyValue.length > 1) { | ||||||
serverVersion = versionKeyValue[1]; | ||||||
} | ||||||
break; | ||||||
} | ||||||
} | ||||||
if (serverVersion != null) { | ||||||
SERVER_VERSION = new Semver(serverVersion); | ||||||
} else { | ||||||
throw new Exception("Error in getting server version"); | ||||||
} | ||||||
|
||||||
} catch (Exception e) { | ||||||
throw new RuntimeException(e); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a message, e.g. "failed to get server version" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||||||
|
||||||
} | ||||||
|
||||||
private static int[] getPortsFromProperty(String propName) { | ||||||
return Arrays.stream(System.getProperty(propName).split(",")) | ||||||
.mapToInt(Integer::parseInt) | ||||||
.toArray(); | ||||||
.mapToInt(Integer::parseInt) | ||||||
.toArray(); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a function to
TestUtilities
which runsinfo
and parses the response. The function has one argument - client.Then static block will call that function. Add
@SneakyThrows
to the function - we don't care about exceptions.This could be used in some specific tests where we could have servers of different versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
Moved function to TestUtilities.