-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizations to REST API #1323
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e4a7925
Add a cache for expensive BlueTestSummary calculation
3d0125d
NotExportableException exception thrown in Model::ctor adding many mi…
3803224
Branch metadata did not hit cache
2ab30e5
Move branch issues onto the Branch model where it belongs
f17af17
Remove up to 5ms per call off of constructing date SimpleDateFormat objs
cccef35
Use jodatime for a threadsafe datetimeformatter
bef47fb
Found another 7ms to DateTimeFormatter construction
f619102
Here's a few more SimpleDateFormat usages in hot paths
38a1b29
Remove empty()
51708cd
Move jodatime usage to impl
f878a36
Move BlueTestSummary cache into RunImpl
717cf53
publishHTML
e8eab73
LOL this fixes jacoco
fa90145
Make same as stapler PR
9e80628
Revert Jenkinsfile change
5aa7adf
Fix not null build failure
ae740f5
Remove stapler parts of micro opt
2e717f7
Move branch metadata tests out to own class, fix tests
a02d0ef
Ensure users checkForNull on pull request and branch fetch
c34f393
Invalidate caches
5fb42e0
Fix findbugs... good thing i added @CheckForNull here
9601175
Remove non deterministic assert
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ne-api-impl/src/test/java/io/jenkins/blueocean/rest/impl/pipeline/BranchMetadataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.jenkins.blueocean.rest.impl.pipeline; | ||
|
||
import hudson.model.Job; | ||
import io.jenkins.blueocean.rest.hal.Link; | ||
import io.jenkins.blueocean.rest.model.BlueOrganization; | ||
import jenkins.model.Jenkins; | ||
import jenkins.scm.api.metadata.ObjectMetadataAction; | ||
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(Jenkins.class) | ||
public class BranchMetadataTest { | ||
|
||
Jenkins jenkins; | ||
BlueOrganization org; | ||
Job job; | ||
BranchImpl branch; | ||
|
||
@Before | ||
public void setup() { | ||
Caches.BRANCH_METADATA.invalidateAll(); | ||
|
||
jenkins = mock(Jenkins.class); | ||
|
||
PowerMockito.mockStatic(Jenkins.class); | ||
when(Jenkins.getInstance()).thenReturn(jenkins); | ||
|
||
when(jenkins.getFullName()).thenReturn(""); | ||
|
||
job = mock(Job.class); | ||
when(job.getParent()).thenReturn(jenkins); | ||
when(job.getFullName()).thenReturn("BobsPipeline"); | ||
when(jenkins.getItemByFullName("BobsPipeline", Job.class)).thenReturn(job); | ||
|
||
org = mock(BlueOrganization.class); | ||
branch = new BranchImpl(org, job, new Link("foo")); | ||
} | ||
|
||
@Test | ||
public void testGetURL() { | ||
assertNull(branch.getBranch()); | ||
|
||
ObjectMetadataAction oma = new ObjectMetadataAction( | ||
"My Branch", | ||
"A feature branch", | ||
"https://path/to/branch" | ||
); | ||
when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma); | ||
|
||
Caches.BRANCH_METADATA.invalidateAll(); | ||
|
||
assertNotNull(branch.getBranch()); | ||
assertFalse(branch.getBranch().isPrimary()); | ||
assertEquals("https://path/to/branch", branch.getBranch().getUrl()); | ||
} | ||
|
||
@Test | ||
public void testBranchInfo() { | ||
assertNull(branch.getBranch()); | ||
|
||
ObjectMetadataAction oma = new ObjectMetadataAction( | ||
"My Branch", | ||
"A feature branch", | ||
"https://path/to/branch" | ||
); | ||
when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma); | ||
when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(new PrimaryInstanceMetadataAction()); | ||
|
||
Caches.BRANCH_METADATA.invalidateAll(); | ||
|
||
assertEquals("https://path/to/branch", branch.getBranch().getUrl()); | ||
assertTrue(branch.getBranch().isPrimary()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe declare these as abstract? default implementation returning null can be misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore that comment, for some reason I mistook it as one of the model class. All good here:)