Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,46 @@
import hudson.model.Descriptor;
import jenkins.tasks.SimpleBuildStep;
import org.jenkinsci.plugins.structs.symbolLookupAnticacheTest.TrivialBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.RealJenkinsRule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.jvnet.hudson.test.junit.jupiter.RealJenkinsExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* @author Sam Van Oort
*/
public class SymbolLookupAnticacheTest {
class SymbolLookupAnticacheTest {

@Rule public RealJenkinsRule rjr = new RealJenkinsRule();
@RegisterExtension
private final RealJenkinsExtension rjr = new RealJenkinsExtension();

/** Verify that if we install a new plugin with a Symbol use, that symbol is found.
* Without the plugin we hit the "anticache" i.e. {@link SymbolLookup#noHitCache} that the symbol does not exist.
* Once we add the plugin it should hit the cache.
*/
@Test public void testAnticache() throws Throwable {
var plugin = rjr.createSyntheticPlugin(new RealJenkinsRule.SyntheticPlugin(TrivialBuilder.class).shortName("SymbolLookupAnticacheTest").header("Plugin-Dependencies", "structs:0"));
@Test
void testAnticache() throws Throwable {
var plugin = rjr.createSyntheticPlugin(new RealJenkinsExtension.SyntheticPlugin(TrivialBuilder.class).shortName("SymbolLookupAnticacheTest").header("Plugin-Dependencies", "structs:0"));
rjr.then(rule -> {
Descriptor d = SymbolLookup.get().findDescriptor(SimpleBuildStep.class, "trivialBuilder");
Descriptor stepDescriptor = SymbolLookup.get().find(Descriptor.class, "trivialBuilder");
assertNull(d);
assertNull(stepDescriptor);

rule.jenkins.getPluginManager().dynamicLoad(plugin);

d = SymbolLookup.get().findDescriptor(SimpleBuildStep.class, "trivialBuilder");
stepDescriptor = SymbolLookup.get().find(Descriptor.class, "trivialBuilder");
assertNotNull(d);
assertNotNull(stepDescriptor);
assertEquals("simpleBuild", d.getDisplayName());
assertEquals("TrivialBuilder", stepDescriptor.clazz.getSimpleName());

// Once more just to confirm there's no wackiness when hitting the normal cache too
assertEquals(SymbolLookup.get().findDescriptor(SimpleBuildStep.class, "trivialBuilder"), d);
Descriptor d = SymbolLookup.get().findDescriptor(SimpleBuildStep.class, "trivialBuilder");
Descriptor stepDescriptor = SymbolLookup.get().find(Descriptor.class, "trivialBuilder");
assertNull(d);
assertNull(stepDescriptor);

rule.jenkins.getPluginManager().dynamicLoad(plugin);

d = SymbolLookup.get().findDescriptor(SimpleBuildStep.class, "trivialBuilder");
stepDescriptor = SymbolLookup.get().find(Descriptor.class, "trivialBuilder");
assertNotNull(d);
assertNotNull(stepDescriptor);
assertEquals("simpleBuild", d.getDisplayName());
assertEquals("TrivialBuilder", stepDescriptor.clazz.getSimpleName());

// Once more just to confirm there's no wackiness when hitting the normal cache too
assertEquals(SymbolLookup.get().findDescriptor(SimpleBuildStep.class, "trivialBuilder"), d);
});
}

Expand Down