Skip to content

Commit

Permalink
Add tests for reload key method
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Dec 17, 2024
1 parent d9fca10 commit cba86c6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static Set<TestResourceManager.TestResourceComparisonInfo> testResourceCo
private static Set<TestResourceClassEntry> getUniqueTestResourceClassEntries(Class<?> testClass,
Path testClassLocation,
Consumer<Set<TestResourceClassEntry>> afterMetaAnnotationAction) {
Class<?> testClassFromTCCL = alwaysFromTccl(testClass); // TODO this extra classload is annoying, but sort of necessary because we do lots of class == checks and also casting
Class<?> testClassFromTCCL = alwaysFromTccl(testClass); // TODO this extra classload is annoying, but sort of necessary because we do lots of class == checks and also casting. It is possible to get rid of it, with some rewrite.

Set<TestResourceClassEntry> uniqueEntries = new LinkedHashSet<>();

Expand Down Expand Up @@ -549,10 +549,8 @@ public static boolean testResourcesRequireReload(Set<TestResourceComparisonInfo>

public static String testResourcesReloadKey(Set<TestResourceComparisonInfo> existing) {
// For now, we reload if it's restricted to class scope, and don't otherwise
String uniquifier = hasRestrictedToClassScope(existing) ? UUID.randomUUID().toString() : "";
System.out.println("HOLLY unqiueuwfier for " + existing + ": " + uniquifier);
System.out.println("HOLLY stresm " + existing.stream().map(Object::toString).sorted().collect(Collectors.joining()));
return existing.stream().map(Object::toString).sorted().collect(Collectors.joining()) + uniquifier;
String uniqueness = hasRestrictedToClassScope(existing) ? UUID.randomUUID().toString() : "";
return existing.stream().map(Object::toString).sorted().collect(Collectors.joining()) + uniqueness;
}

private static boolean hasRestrictedToClassScope(Set<TestResourceComparisonInfo> existing) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package io.quarkus.test.common;

import static io.quarkus.test.common.TestResourceManager.testResourcesReloadKey;
import static io.quarkus.test.common.TestResourceManager.testResourcesRequireReload;
import static io.quarkus.test.common.TestResourceScope.*;
import static io.quarkus.test.common.TestResourceScope.GLOBAL;
import static io.quarkus.test.common.TestResourceScope.MATCHING_RESOURCES;
import static io.quarkus.test.common.TestResourceScope.RESTRICTED_TO_CLASS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collections;
Expand All @@ -16,72 +21,77 @@ public class TestResourceManagerReloadTest {

@Test
public void emptyResources() {
assertFalse(testResourcesRequireReload(Collections.emptySet(), Set.of()));
Set<TestResourceComparisonInfo> existing = Collections.emptySet();
Set<TestResourceComparisonInfo> next = Set.of();
assertFalse(testResourcesRequireReload(existing, next));
assertEquals(testResourcesReloadKey(existing), testResourcesReloadKey(next));
}

@Test
public void differentCount() {
assertTrue(testResourcesRequireReload(Collections.emptySet(),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS))));
Set<TestResourceComparisonInfo> existing = Collections.emptySet();
Set<TestResourceComparisonInfo> next = Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS));

assertTrue(testResourcesRequireReload(Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS)),
Collections.emptySet()));
assertTrue(testResourcesRequireReload(existing, next));
assertTrue(testResourcesRequireReload(next, existing));

assertNotEquals(testResourcesReloadKey(existing), testResourcesReloadKey(next));
}

@Test
public void sameSingleRestrictedToClassResource() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS)),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS))));
Set<TestResourceComparisonInfo> existing = Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS));
Set<TestResourceComparisonInfo> next = Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS));
assertTrue(testResourcesRequireReload(existing, next));

assertNotEquals(testResourcesReloadKey(existing), testResourcesReloadKey(next));
}

@Test
public void sameSingleMatchingResource() {
assertFalse(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES)),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES))));
Set<TestResourceComparisonInfo> existing = Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES));
Set<TestResourceComparisonInfo> next = Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES));

assertFalse(testResourcesRequireReload(existing, next));

assertEquals(testResourcesReloadKey(existing), testResourcesReloadKey(next));
}

@Test
public void differentSingleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES)),
Set.of(new TestResourceComparisonInfo("test2", MATCHING_RESOURCES))));
Set<TestResourceComparisonInfo> existing = Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES));
Set<TestResourceComparisonInfo> next = Set.of(new TestResourceComparisonInfo("test2", MATCHING_RESOURCES));
assertTrue(testResourcesRequireReload(existing, next));

assertNotEquals(testResourcesReloadKey(existing), testResourcesReloadKey(next));
}

@Test
public void sameMultipleMatchingResource() {
assertFalse(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test", MATCHING_RESOURCES))));
}
Set<TestResourceComparisonInfo> existing = Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL));
Set<TestResourceComparisonInfo> next = Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test", MATCHING_RESOURCES));

assertFalse(testResourcesRequireReload(existing, next));
assertEquals(testResourcesReloadKey(existing), testResourcesReloadKey(next));

@Test
public void differentMultipleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
}

@Test
public void differentGlobalMultipleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test4", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
public void differentMultipleMatchingResource() {
Set<TestResourceComparisonInfo> existing = Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL));
Set<TestResourceComparisonInfo> next = Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES));
assertTrue(testResourcesRequireReload(existing, next));
assertNotEquals(testResourcesReloadKey(existing),
testResourcesReloadKey(next));
}
}

0 comments on commit cba86c6

Please sign in to comment.