Skip to content

Commit 47c18d3

Browse files
amends to use valkey-java 5.4.0
1 parent ef32446 commit 47c18d3

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
testImplementation group: 'org.mockito', name: 'mockito-inline', version: "${mockitoVersion}"
3535
*/
3636

37-
// sadly doesnt work => testImplementation 'com.github.fppt:jedis-mock:0.1.14'
37+
// sadly doesn't work => testImplementation 'com.github.fppt:jedis-mock:0.1.14'
3838
}
3939

4040
jacocoTestReport {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
projectVersion=6.3.0
1+
projectVersion=6.5.0
22
#javaVersion=JavaVersion.VERSION_11
33
javaVersion=11
44

55
# https://github.com/johnrengelman/shadow
66
shadowVersion=7.1.2
77

88
# https://central.sonatype.com/artifact/io.valkey/valkey-java
9-
valkeyJavaVersion=5.3.0
9+
valkeyJavaVersion=5.4.0
1010
# https://mvnrepository.com/artifact/org.javassist/javassist
1111
javassistVersion=3.30.1-GA
1212
# https://mvnrepository.com/artifact/org.slf4j/slf4j-api

src/test/java/org/oba/jedis/extra/utils/test/TestingUtils.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import io.valkey.params.SetParams;
55

66
import java.lang.reflect.Field;
7+
import java.util.ArrayList;
8+
import java.util.List;
79

810
public class TestingUtils {
911

1012
private TestingUtils() {}
1113

1214
public static boolean isSetParamsNX(SetParams setParams) {
1315
if (setParams != null) {
14-
Protocol.Keyword valueExistance = extractPrivateValue("existance", SetParams.class, setParams, Protocol.Keyword.class);
16+
Protocol.Keyword valueExistance = extractPrivateValue("existence", SetParams.class, setParams, Protocol.Keyword.class);
1517
return valueExistance == Protocol.Keyword.NX;
1618
} else {
1719
return false;
@@ -22,8 +24,8 @@ public static boolean isSetParamsNX(SetParams setParams) {
2224

2325
public static Long extractSetParamsExpireTimePX(SetParams setParams) {
2426
if (setParams != null) {
25-
Protocol.Keyword valueExpiration = extractPrivateValue("expiration", SetParams.class, setParams, Protocol.Keyword.class);
26-
Long valueExpirationValue = extractPrivateValue("expirationValue", SetParams.class, setParams, Long.class);
27+
Protocol.Keyword valueExpiration = extractPrivateValue("expiration", SetParams.class, setParams, Protocol.Keyword.class, true);
28+
Long valueExpirationValue = extractPrivateValue("expirationValue", SetParams.class, setParams, Long.class, true);
2729
if (valueExpiration == null && valueExpirationValue == null) {
2830
return null;
2931
} else if (valueExpiration == Protocol.Keyword.PX) {
@@ -39,8 +41,17 @@ public static Long extractSetParamsExpireTimePX(SetParams setParams) {
3941

4042

4143
public static <I,O> O extractPrivateValue(String field, Class<I> originType, I origin, Class<O> resultType) {
44+
return extractPrivateValue(field, originType, origin, resultType, false);
45+
}
46+
47+
public static <I,O> O extractPrivateValue(String field, Class<I> originType, I origin, Class<O> resultType, boolean searchInParent) {
4248
try {
43-
Field privateField = origin.getClass().getDeclaredField(field);
49+
Field privateField;
50+
if (searchInParent) {
51+
privateField = getPrivateFieldsFromObjectAndParent(originType, field);
52+
} else {
53+
privateField = origin.getClass().getDeclaredField(field);
54+
}
4455
privateField.setAccessible(true);
4556
if (resultType == privateField.getType()){
4657
return (O) privateField.get(origin);
@@ -56,4 +67,21 @@ public static <I,O> O extractPrivateValue(String field, Class<I> originType, I o
5667
}
5768
}
5869

59-
}
70+
public static Field getPrivateFieldsFromObjectAndParent(Class<?> type, String name) {
71+
List<Field> fieldList = new ArrayList<>();
72+
Class<?> currentType = type;
73+
while (currentType != null && currentType != Object.class) {
74+
for (Field field : currentType.getDeclaredFields()) {
75+
if (!field.isSynthetic()) {
76+
fieldList.add(field);
77+
}
78+
}
79+
currentType = currentType.getSuperclass();
80+
}
81+
return fieldList.stream().
82+
filter(f -> f.getName().equals(name)).
83+
findFirst().get();
84+
85+
}
86+
87+
}

0 commit comments

Comments
 (0)