Skip to content
Permalink
Browse files
[JENKINS-51523] Fixed test infrastructure for suppressing artifact/st…
…ash deletion.
  • Loading branch information
jglick committed May 29, 2018
1 parent dcd46a2 commit bc31751db95d6057b9169f3b055b3e640d21401e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
@@ -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>

@@ -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() {}
@@ -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
@@ -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;
}

}
@@ -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);
}

}
@@ -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() {
@@ -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 {
@@ -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> {
@@ -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
@@ -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;
@@ -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

0 comments on commit bc31751

Please sign in to comment.