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
resolves issue #110 by adding connection mode #111
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
docker/src/main/java/org/arquillian/cube/impl/client/ConnectionMode.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,21 @@ | ||
package org.arquillian.cube.impl.client; | ||
|
||
public enum ConnectionMode { | ||
STARTANDSTOP(false, true), STARTORCONNECT(true, true), STARTORCONNECTANDLEAVE(true, false); | ||
|
||
private boolean allowReconnect = false; | ||
private boolean stoppable = true; | ||
|
||
private ConnectionMode(boolean allowReconnect, boolean stoppable) { | ||
this.allowReconnect = allowReconnect; | ||
this.stoppable = stoppable; | ||
} | ||
|
||
public boolean isAllowReconnect() { | ||
return allowReconnect; | ||
} | ||
|
||
public boolean isStoppable() { | ||
return stoppable; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,21 +35,21 @@ public class CubeSuiteLifecycleController { | |
|
||
public void startAutoContainers(@Observes(precedence = 100) BeforeSuite event, final CubeConfiguration configuration) { | ||
List<String[]> autoStartSteps = AutoStartOrderUtil.getAutoStartOrder(configuration); | ||
startAllSteps(autoStartSteps, configuration.shouldAllowToConnectToRunningContainers()); | ||
startAllSteps(autoStartSteps, configuration.getConnectionMode()); | ||
} | ||
|
||
public void stopAutoContainers(@Observes(precedence = -100) AfterSuite event, CubeConfiguration configuration) { | ||
List<String[]> autoStopSteps = AutoStartOrderUtil.getAutoStopOrder(configuration); | ||
stopAllSteps(autoStopSteps); | ||
} | ||
|
||
private void startAllSteps(List<String[]> autoStartSteps, boolean allowToConnectToRunningContainers) { | ||
private void startAllSteps(List<String[]> autoStartSteps, ConnectionMode connectionMode) { | ||
for(final String[] cubeIds : autoStartSteps) { | ||
Map<String, Future<RuntimeException>> stepStatus = new HashMap<>(); | ||
|
||
// Start | ||
for(final String cubeId : cubeIds) { | ||
Future<RuntimeException> result = executorServiceInst.get().submit(new StartCubes(cubeId, allowToConnectToRunningContainers)); | ||
Future<RuntimeException> result = executorServiceInst.get().submit(new StartCubes(cubeId, connectionMode)); | ||
stepStatus.put(cubeId, result); | ||
} | ||
|
||
|
@@ -100,22 +100,28 @@ private boolean isCubeRunning(String cube) { | |
} | ||
|
||
private final class StartCubes implements Callable<RuntimeException> { | ||
private final boolean allowToConnectToRunningContainers; | ||
private final ConnectionMode connectionMode; | ||
private final String cubeId; | ||
|
||
private StartCubes(String cubeId, boolean shouldAllowToConnectToRunningContainers) { | ||
private StartCubes(String cubeId, ConnectionMode connectionMode) { | ||
this.cubeId = cubeId; | ||
this.allowToConnectToRunningContainers = shouldAllowToConnectToRunningContainers; | ||
this.connectionMode = connectionMode; | ||
} | ||
|
||
@Override | ||
public RuntimeException call() throws Exception { | ||
try { | ||
if(allowToConnectToRunningContainers && isCubeRunning(cubeId)) { | ||
if(connectionMode.isAllowReconnect() && isCubeRunning(cubeId)) { | ||
controlEvent.fire(new PreRunningCube(cubeId)); | ||
} else { | ||
controlEvent.fire(new CreateCube(cubeId)); | ||
controlEvent.fire(new StartCube(cubeId)); | ||
return null; | ||
} | ||
controlEvent.fire(new CreateCube(cubeId)); | ||
controlEvent.fire(new StartCube(cubeId)); | ||
|
||
if(connectionMode.isAllowReconnect() && !connectionMode.isStoppable()) { | ||
// If we allow reconnections and containers are none stoppable which means that they will be able to be | ||
// reused in next executions then at this point we can assume that the container is a prerunning container. | ||
controlEvent.fire(new PreRunningCube(cubeId)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm.. are we missing some else or something here? Why create/start then call PreRunningCube? |
||
} | ||
} catch(RuntimeException e) { | ||
return e; | ||
|
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
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.
Add some better Exception handling then just the default IllegalArgumentException("No Enum constant " + type...) coming from valueOf
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.
Agreed