Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-51523] Fixed test infrastructure for suppressing artifact/st…
…ash deletion.
  • Loading branch information
jglick committed May 29, 2018
1 parent dcd46a2 commit bc31751
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -19,7 +19,7 @@
<jclouds.version>2.0.3</jclouds.version>
<jenkins.version>2.121</jenkins.version>
<java.level>8</java.level>
<workflow-api-plugin.version>2.28-rc338.1dfffb24a014</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<workflow-api-plugin.version>2.28-rc341.90cc5dc659de</workflow-api-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/67 -->
<useBeta>true</useBeta>
</properties>

Expand Down
Expand Up @@ -83,12 +83,9 @@ public class S3BlobStore extends BlobStoreProvider {
@SuppressWarnings("FieldMayBeFinal")
private static String REGION = System.getProperty(S3BlobStore.class.getName() + ".region");
@SuppressWarnings("FieldMayBeFinal")
private static boolean DEFAULT_DELETE_BLOBS = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteBlobs");
private static boolean DELETE_BLOBS = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteBlobs");
@SuppressWarnings("FieldMayBeFinal")
private static boolean DEFAULT_DELETE_STASHES = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteStashes");

private transient boolean deleteBlobs = DEFAULT_DELETE_BLOBS;
private transient boolean deleteStashes = DEFAULT_DELETE_STASHES;
private static boolean DELETE_STASHES = Boolean.getBoolean(S3BlobStore.class.getName() + ".deleteStashes");

@DataBoundConstructor
public S3BlobStore() {}
Expand All @@ -105,22 +102,12 @@ public String getContainer() {

@Override
public boolean isDeleteBlobs() {
return deleteBlobs;
}

@Restricted(NoExternalUse.class) // test only
public void setDeleteBlobs(boolean deleteBlobs) {
this.deleteBlobs = deleteBlobs;
return DELETE_BLOBS;
}

@Override
public boolean isDeleteStashes() {
return deleteStashes;
}

@Restricted(NoExternalUse.class) // test only
public void setDeleteStashes(boolean deleteStashes) {
this.deleteStashes = deleteStashes;
return DELETE_STASHES;
}

@Override
Expand Down
Expand Up @@ -155,4 +155,14 @@ public URL toExternalURL(Blob blob, HttpMethod httpMethod) throws IOException {
return new URL(baseURL, blob.getMetadata().getContainer() + "/" + blob.getMetadata().getName() + "?method=" + httpMethod);
}

@Override
public boolean isDeleteBlobs() {
return true;
}

@Override
public boolean isDeleteStashes() {
return true;
}

}
Expand Up @@ -41,7 +41,8 @@ public class MockBlobStoreTest {

@Test
public void smokes() throws Exception {
ArtifactManagerTest.run(j, new JCloudsArtifactManagerFactory(new MockBlobStore()), false, null);
ArtifactManagerTest.artifactArchiveAndDelete(j, new JCloudsArtifactManagerFactory(new MockBlobStore()), false, null);
ArtifactManagerTest.artifactStashAndDelete(j, new JCloudsArtifactManagerFactory(new MockBlobStore()), false, null);
}

}
Expand Up @@ -100,16 +100,19 @@ public static void doPrepareImage() throws Exception {
@Rule
public LoggerRule httpLogging = new LoggerRule();

protected ArtifactManagerFactory getArtifactManagerFactory() {
return new JCloudsArtifactManagerFactory(new CustomPrefixBlobStoreProvider(provider, getPrefix()));
protected ArtifactManagerFactory getArtifactManagerFactory(Boolean deleteBlobs, Boolean deleteStashes) {
return new JCloudsArtifactManagerFactory(new CustomPrefixBlobStoreProvider(provider, getPrefix(), deleteBlobs, deleteStashes));
}

private static final class CustomPrefixBlobStoreProvider extends BlobStoreProvider {
private final BlobStoreProvider delegate;
private final String prefix;
CustomPrefixBlobStoreProvider(BlobStoreProvider delegate, String prefix) {
private final Boolean deleteBlobs, deleteStashes;
CustomPrefixBlobStoreProvider(BlobStoreProvider delegate, String prefix, Boolean deleteBlobs, Boolean deleteStashes) {
this.delegate = delegate;
this.prefix = prefix;
this.deleteBlobs = deleteBlobs;
this.deleteStashes = deleteStashes;
}
@Override
public String getPrefix() {
Expand All @@ -121,11 +124,11 @@ public String getContainer() {
}
@Override
public boolean isDeleteBlobs() {
return delegate.isDeleteBlobs();
return deleteBlobs != null ? deleteBlobs : delegate.isDeleteBlobs();
}
@Override
public boolean isDeleteStashes() {
return delegate.isDeleteStashes();
return deleteStashes != null ? deleteStashes : delegate.isDeleteStashes();
}
@Override
public BlobStoreContext getContext() throws IOException {
Expand Down Expand Up @@ -165,24 +168,22 @@ public void agentPermissions() throws Exception {
@Test
public void artifactArchive() throws Exception {
// To demo class loading performance: loggerRule.record(SlaveComputer.class, Level.FINEST);
ArtifactManagerTest.artifactArchive(j, getArtifactManagerFactory(), /* TODO S3BlobStore.list does not seem to handle weird characters */false, image);
ArtifactManagerTest.artifactArchive(j, getArtifactManagerFactory(null, null), /* TODO S3BlobStore.list does not seem to handle weird characters */false, image);
}

@Test
public void artifactArchiveAndDelete() throws Exception {
((S3BlobStore) provider).setDeleteBlobs(true);
ArtifactManagerTest.artifactArchiveAndDelete(j, getArtifactManagerFactory(), false, image);
ArtifactManagerTest.artifactArchiveAndDelete(j, getArtifactManagerFactory(true, null), false, image);
}

@Test
public void artifactStash() throws Exception {
ArtifactManagerTest.artifactStash(j, getArtifactManagerFactory(), false, image);
ArtifactManagerTest.artifactStash(j, getArtifactManagerFactory(null, null), false, image);
}

@Test
public void artifactStashAndDelete() throws Exception {
((S3BlobStore) provider).setDeleteStashes(true);
ArtifactManagerTest.artifactStashAndDelete(j, getArtifactManagerFactory(), false, image);
ArtifactManagerTest.artifactStashAndDelete(j, getArtifactManagerFactory(null, true), false, image);
}

private static final class LoadS3Credentials extends MasterToSlaveCallable<Void, RuntimeException> {
Expand All @@ -195,7 +196,7 @@ public Void call() {

@Test
public void artifactBrowsingPerformance() throws Exception {
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory(null, null));
FreeStyleProject p = j.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
@Override
Expand Down Expand Up @@ -231,7 +232,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
@Issue({"JENKINS-51390", "JCLOUDS-1200"})
@Test
public void serializationProblem() throws Exception {
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory(null, null));
WorkflowJob p = j.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {writeFile file: 'f', text: 'content'; archiveArtifacts 'f'; dir('d') {try {unarchive mapping: ['f': 'f']} catch (x) {sleep 1; echo(/caught $x/)}}}", true));
S3BlobStore.BREAK_CREDS = true;
Expand All @@ -246,7 +247,7 @@ public void serializationProblem() throws Exception {

//@Test
public void archiveSingleLargeFile() throws Exception {
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory());
ArtifactManagerConfiguration.get().getArtifactManagerFactories().add(getArtifactManagerFactory(null, null));
FreeStyleProject p = j.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
@Override
Expand Down

0 comments on commit bc31751

Please sign in to comment.