Skip to content

Commit f5f50c5

Browse files
committed
Releaser stucks on errors #58
1 parent 571dbf0 commit f5f50c5

File tree

2 files changed

+93
-12
lines changed

2 files changed

+93
-12
lines changed

src/main/java/org/scm4j/releaser/ExtendedStatusBuilder.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ private ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IPro
9494
if (comp.getVersion().isLocked()) {
9595
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<>();
9696
Utils.async(rb.getMDeps(), (mdep) -> {
97-
ExtendedStatus exStatus = getAndCacheStatus(mdep, cache, progress, false);
98-
subComponentsLocal.put(mdep, exStatus);
97+
try {
98+
recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, false);
99+
} catch (Exception e) {
100+
cache.remove(repo.getUrl());
101+
throw e;
102+
}
99103
});
100104

101105
for (Component mdep : rb.getMDeps()) {
@@ -125,6 +129,12 @@ private ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IPro
125129
return new ExtendedStatus(nextVersion, status, subComponents, comp, repo);
126130
}
127131

132+
void recursiveGetAndCacheStatus(CachedStatuses cache, IProgress progress,
133+
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal, Component mdep, Boolean isPatch) throws RuntimeException {
134+
ExtendedStatus exStatus = getAndCacheStatus(mdep, cache, progress, isPatch);
135+
subComponentsLocal.put(mdep, exStatus);
136+
}
137+
128138
private ExtendedStatus getPatchStatus(Component comp, CachedStatuses cache, IProgress progress, VCSRepository repo, DelayedTag dt) {
129139
ReleaseBranchPatch rb = reportDuration(() -> ReleaseBranchFactory.getReleaseBranchPatch(comp.getVersion(), repo),
130140
"RB created", comp, progress);
@@ -147,8 +157,12 @@ private ExtendedStatus getPatchStatus(Component comp, CachedStatuses cache, IPro
147157

148158
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<>();
149159
Utils.async(rb.getMDeps(), (mdep) -> {
150-
ExtendedStatus status = getAndCacheStatus(mdep, cache, progress, true);
151-
subComponentsLocal.put(mdep, status);
160+
try {
161+
recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, true);
162+
} catch (Exception e) {
163+
cache.remove(repo.getUrl());
164+
throw e;
165+
}
152166
});
153167
for (Component mdep : rb.getMDeps()) {
154168
subComponents.put(mdep, subComponentsLocal.get(mdep));
@@ -246,7 +260,6 @@ private boolean areMDepsPatchesActualForPatch(Component rootComp, VCSRepository
246260
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextVersion.toPreviousPatch());
247261
}
248262

249-
250263
DelayedTagsFile mdf = new DelayedTagsFile();
251264
Version verToActualizeOn ;
252265
if (mdf.getDelayedTagByUrl(url) != null) { // if delayed tag
@@ -289,8 +302,12 @@ private Boolean isNeedToFork(Component comp, ReleaseBranchCurrent rb, CachedStat
289302

290303
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<>();
291304
Utils.async(rb.getMDeps(), (mdep) -> {
292-
ExtendedStatus status = getAndCacheStatus(mdep, cache, progress, false);
293-
subComponentsLocal.put(mdep, status);
305+
try {
306+
recursiveGetAndCacheStatus(cache, progress, subComponentsLocal, mdep, false);
307+
} catch (Exception e) {
308+
cache.remove(repo.getUrl());
309+
throw e;
310+
}
294311
});
295312

296313
for (Component mdep : rb.getMDeps()) {

src/test/java/org/scm4j/releaser/WorkflowBuildTest.java

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package org.scm4j.releaser;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
import static org.mockito.Matchers.eq;
6+
import static org.mockito.Mockito.atLeast;
7+
import static org.mockito.Mockito.doThrow;
8+
import static org.mockito.Mockito.spy;
9+
import static org.mockito.Mockito.verify;
10+
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.Map;
13+
import java.util.concurrent.ConcurrentHashMap;
14+
315
import org.apache.commons.io.FileUtils;
416
import org.junit.Test;
17+
import org.scm4j.commons.progress.ProgressConsole;
518
import org.scm4j.releaser.actions.IAction;
619
import org.scm4j.releaser.branch.ReleaseBranchCurrent;
720
import org.scm4j.releaser.branch.ReleaseBranchFactory;
@@ -11,11 +24,6 @@
1124
import org.scm4j.releaser.exceptions.EBuildOnNotForkedRelease;
1225
import org.scm4j.releaser.exceptions.ENoBuilder;
1326
import org.yaml.snakeyaml.Yaml;
14-
15-
import java.nio.charset.StandardCharsets;
16-
import java.util.Map;
17-
18-
import static org.junit.Assert.*;
1927
public class WorkflowBuildTest extends WorkflowTestBase {
2028

2129
@Test
@@ -168,4 +176,60 @@ public void TestMinorUpgradeIsOK() {
168176
// expect no EMinorUpgradeDowngrade exception because areMDepsPatchesActualForMinor should be used for minor
169177
execAndGetAction(CLICommand.STATUS.getCmdLineStr(), compUBL.getCoords().toString());
170178
}
179+
180+
@Test
181+
public void TestShouldRemoveFromCacheOnErrorsOnMinor() {
182+
ExtendedStatusBuilder esb = spy(new ExtendedStatusBuilder(repoFactory));
183+
CachedStatuses cache = spy(new CachedStatuses());
184+
RuntimeException testException = new RuntimeException("");
185+
ProgressConsole pc = new ProgressConsole();
186+
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<Component, ExtendedStatus>();
187+
Component versionedUBL = compUBL.clone("1.0");
188+
doThrow(testException).when(esb).recursiveGetAndCacheStatus(cache, pc, subComponentsLocal, compUnTillDb, false);
189+
190+
try {
191+
esb.getAndCacheStatus(versionedUBL, cache, pc, false);
192+
fail();
193+
} catch (RuntimeException e) {
194+
verify(cache, atLeast(1)).remove(eq(repoUBL.getUrl()));
195+
}
196+
}
197+
198+
@Test
199+
public void TestShouldRemoveFromCacheOnErrorsOnPatch() {
200+
forkAndBuild(compUBL);
201+
ExtendedStatusBuilder esb = spy(new ExtendedStatusBuilder(repoFactory));
202+
CachedStatuses cache = spy(new CachedStatuses());
203+
RuntimeException testException = new RuntimeException("");
204+
ProgressConsole pc = new ProgressConsole();
205+
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<Component, ExtendedStatus>();
206+
ReleaseBranchCurrent crbUBL = ReleaseBranchFactory.getCRB(repoUBL);
207+
Component versionedUBL = compUBL.clone(crbUBL.getVersion());
208+
Component versionedUnTillDb = new Component("eu.untill:unTillDb:2.59.0#comment 3");
209+
210+
doThrow(testException).when(esb).recursiveGetAndCacheStatus(cache, pc, subComponentsLocal, versionedUnTillDb, true);
211+
try {
212+
esb.getAndCacheStatus(versionedUBL, cache, pc, true);
213+
fail();
214+
} catch (RuntimeException e) {
215+
verify(cache, atLeast(1)).remove(eq(repoUBL.getUrl()));
216+
}
217+
}
218+
219+
@Test
220+
public void testSouldRemoveFromCacheOnErrorsIsNeedToFork() {
221+
ExtendedStatusBuilder esb = spy(new ExtendedStatusBuilder(repoFactory));
222+
CachedStatuses cache = spy(new CachedStatuses());
223+
RuntimeException testException = new RuntimeException("");
224+
ProgressConsole pc = new ProgressConsole();
225+
ConcurrentHashMap<Component, ExtendedStatus> subComponentsLocal = new ConcurrentHashMap<Component, ExtendedStatus>();
226+
doThrow(testException).when(esb).recursiveGetAndCacheStatus(cache, pc, subComponentsLocal, compUnTillDb, false);
227+
228+
try {
229+
esb.getAndCacheStatus(compUBL, cache, pc, false);
230+
fail();
231+
} catch (RuntimeException e) {
232+
verify(cache, atLeast(1)).remove(eq(repoUBL.getUrl()));
233+
}
234+
}
171235
}

0 commit comments

Comments
 (0)