Skip to content

Commit 09f7950

Browse files
authored
improve: remove resource version comparison from 5.2 (#3050)
Since it is not used in the framework yet internally removing it. We will further discuss the implementation for 5.3 Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent c864078 commit 09f7950

File tree

2 files changed

+0
-87
lines changed

2 files changed

+0
-87
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -450,40 +450,4 @@ public static <P extends HasMetadata> P addFinalizerWithSSA(
450450
e);
451451
}
452452
}
453-
454-
public static int compareResourceVersions(String v1, String v2) {
455-
int v1Length = validateResourceVersion(v1);
456-
int v2Length = validateResourceVersion(v2);
457-
int comparison = v1Length - v2Length;
458-
if (comparison != 0) {
459-
return comparison;
460-
}
461-
for (int i = 0; i < v2Length; i++) {
462-
int comp = v1.charAt(i) - v2.charAt(i);
463-
if (comp != 0) {
464-
return comp;
465-
}
466-
}
467-
return 0;
468-
}
469-
470-
private static int validateResourceVersion(String v1) {
471-
int v1Length = v1.length();
472-
if (v1Length == 0) {
473-
throw new NonComparableResourceVersionException("Resource version is empty");
474-
}
475-
for (int i = 0; i < v1Length; i++) {
476-
char char1 = v1.charAt(i);
477-
if (char1 == '0') {
478-
if (i == 0) {
479-
throw new NonComparableResourceVersionException(
480-
"Resource version cannot begin with 0: " + v1);
481-
}
482-
} else if (char1 < '0' || char1 > '9') {
483-
throw new NonComparableResourceVersionException(
484-
"Non numeric characters in resource version: " + v1);
485-
}
486-
}
487-
return v1Length;
488-
}
489453
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.function.UnaryOperator;
2020

2121
import org.junit.jupiter.api.BeforeEach;
22-
import org.junit.jupiter.api.Disabled;
2322
import org.junit.jupiter.api.Test;
2423
import org.slf4j.Logger;
2524
import org.slf4j.LoggerFactory;
@@ -40,7 +39,6 @@
4039
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
4140

4241
import static io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils.DEFAULT_MAX_RETRY;
43-
import static io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils.compareResourceVersions;
4442
import static org.assertj.core.api.Assertions.assertThat;
4543
import static org.junit.jupiter.api.Assertions.assertThrows;
4644
import static org.mockito.ArgumentMatchers.any;
@@ -182,53 +180,4 @@ void cachePollTimeouts() {
182180
10L));
183181
assertThat(ex.getMessage()).contains("Timeout");
184182
}
185-
186-
@Test
187-
public void compareResourceVersionsTest() {
188-
assertThat(compareResourceVersions("11", "22")).isNegative();
189-
assertThat(compareResourceVersions("22", "11")).isPositive();
190-
assertThat(compareResourceVersions("1", "1")).isZero();
191-
assertThat(compareResourceVersions("11", "11")).isZero();
192-
assertThat(compareResourceVersions("123", "2")).isPositive();
193-
assertThat(compareResourceVersions("3", "211")).isNegative();
194-
195-
assertThrows(
196-
NonComparableResourceVersionException.class, () -> compareResourceVersions("aa", "22"));
197-
assertThrows(
198-
NonComparableResourceVersionException.class, () -> compareResourceVersions("11", "ba"));
199-
assertThrows(
200-
NonComparableResourceVersionException.class, () -> compareResourceVersions("", "22"));
201-
assertThrows(
202-
NonComparableResourceVersionException.class, () -> compareResourceVersions("11", ""));
203-
assertThrows(
204-
NonComparableResourceVersionException.class, () -> compareResourceVersions("01", "123"));
205-
assertThrows(
206-
NonComparableResourceVersionException.class, () -> compareResourceVersions("123", "01"));
207-
assertThrows(
208-
NonComparableResourceVersionException.class, () -> compareResourceVersions("3213", "123a"));
209-
assertThrows(
210-
NonComparableResourceVersionException.class, () -> compareResourceVersions("321", "123a"));
211-
}
212-
213-
// naive performance test that compares the work case scenario for the parsing and non-parsing
214-
// variants
215-
@Test
216-
@Disabled("test sometimes fails, we plan to iterate over it and related features for 5.3")
217-
public void compareResourcePerformanceTest() {
218-
var execNum = 30000000;
219-
var startTime = System.currentTimeMillis();
220-
for (int i = 0; i < execNum; i++) {
221-
var res = compareResourceVersions("123456788", "123456789");
222-
}
223-
var dur1 = System.currentTimeMillis() - startTime;
224-
log.info("Duration without parsing: {}", dur1);
225-
startTime = System.currentTimeMillis();
226-
for (int i = 0; i < execNum; i++) {
227-
var res = Long.parseLong("123456788") > Long.parseLong("123456789");
228-
}
229-
var dur2 = System.currentTimeMillis() - startTime;
230-
log.info("Duration with parsing: {}", dur2);
231-
232-
assertThat(dur1).isLessThan(dur2);
233-
}
234183
}

0 commit comments

Comments
 (0)