Skip to content

Commit f5d813c

Browse files
committed
Use faster hash for unit testing
1 parent 5d70e49 commit f5d813c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/AnnotationHelper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import io.kubernetes.client.models.V1ObjectMeta;
88
import io.kubernetes.client.models.V1Pod;
99
import io.kubernetes.client.util.Yaml;
10+
import java.util.function.Function;
1011
import org.apache.commons.codec.digest.DigestUtils;
1112

1213
/** Annotates pods, services with details about the Domain instance and checks these annotations. */
1314
public class AnnotationHelper {
1415
static final String SHA256_ANNOTATION = "weblogic.sha256";
16+
private static Function<V1Pod, String> HASH_FUNCTION =
17+
pod -> DigestUtils.sha256Hex(Yaml.dump(pod));
1518

1619
/**
1720
* Marks metadata with annotations that let Prometheus know how to retrieve metrics from the
@@ -29,14 +32,10 @@ static void annotateForPrometheus(V1ObjectMeta meta, int httpPort) {
2932
}
3033

3134
static V1Pod withSha256Hash(V1Pod pod) {
32-
pod.getMetadata().putAnnotationsItem(SHA256_ANNOTATION, computeHash(pod));
35+
pod.getMetadata().putAnnotationsItem(SHA256_ANNOTATION, HASH_FUNCTION.apply(pod));
3336
return pod;
3437
}
3538

36-
static String computeHash(V1Pod pod) {
37-
return DigestUtils.sha256Hex(Yaml.dump(pod));
38-
}
39-
4039
static String getHash(V1Pod pod) {
4140
return pod.getMetadata().getAnnotations().get(SHA256_ANNOTATION);
4241
}

operator/src/test/java/oracle/kubernetes/operator/helpers/PodHelperTestBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.util.Map;
6666
import java.util.Objects;
6767
import java.util.Set;
68+
import java.util.function.Function;
6869
import java.util.logging.Level;
6970
import java.util.logging.LogRecord;
7071
import oracle.kubernetes.TestUtils;
@@ -160,6 +161,8 @@ public void setUp() throws Exception {
160161
.withLogLevel(Level.FINE));
161162
mementos.add(testSupport.installRequestStepFactory());
162163
mementos.add(TuningParametersStub.install());
164+
mementos.add(
165+
StaticStubSupport.install(AnnotationHelper.class, "HASH_FUNCTION", new UnitTestHash()));
163166

164167
WlsDomainConfigSupport configSupport = new WlsDomainConfigSupport(DOMAIN_NAME);
165168
configSupport.addWlsServer(ADMIN_SERVER, ADMIN_PORT);
@@ -1109,4 +1112,11 @@ public boolean matches(Object actualBody) {
11091112
return actualInstructions.equals(expectedInstructions);
11101113
}
11111114
}
1115+
1116+
static class UnitTestHash implements Function<V1Pod, String> {
1117+
@Override
1118+
public String apply(V1Pod v1Pod) {
1119+
return Integer.toString(v1Pod.hashCode());
1120+
}
1121+
}
11121122
}

0 commit comments

Comments
 (0)