Skip to content

Add a method for output streams cleanup #909

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

Merged
merged 2 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,32 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.Nullable;

public final class AppiumDriverLocalService extends DriverService {

private static final String URL_MASK = "http://%s:%d/wd/hub";
private final File nodeJSExec;
private final int nodeJSPort;
private final ImmutableList<String> nodeJSArgs;
private final ImmutableMap<String, String> nodeJSEnvironment;
private final String ipAddress;
private final long startupTimeout;
private final TimeUnit timeUnit;
private final ReentrantLock lock = new ReentrantLock(true); //uses "fair" thread ordering policy
private final ListOutputStream stream = new ListOutputStream().add(System.out);
private final URL url;



private CommandLine process = null;

AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort,
ImmutableList<String> nodeJSArgs, ImmutableMap<String, String> nodeJSEnvironment,
long startupTimeout, TimeUnit timeUnit) throws IOException {
super(nodeJSExec, nodeJSPort, nodeJSArgs, nodeJSEnvironment);
this.ipAddress = ipAddress;
this.nodeJSExec = nodeJSExec;
this.nodeJSPort = nodeJSPort;
this.nodeJSArgs = nodeJSArgs;
this.nodeJSEnvironment = nodeJSEnvironment;
this.startupTimeout = startupTimeout;
this.timeUnit = timeUnit;
this.url = new URL(String.format(URL_MASK, this.ipAddress, this.nodeJSPort));
this.url = new URL(String.format(URL_MASK, ipAddress, nodeJSPort));
}

public static AppiumDriverLocalService buildDefaultService() {
Expand Down Expand Up @@ -185,6 +180,7 @@ private void destroyProcess() {
* @return String logs if the server has been run.
* null is returned otherwise.
*/
@Nullable
public String getStdOut() {
if (process != null) {
return process.getStdOut();
Expand Down Expand Up @@ -215,4 +211,12 @@ public void addOutPutStreams(List<OutputStream> outputStreams) {
}
}

/**
* Remove all existing server output streams.
*
* @return true if at least one output stream has been cleared
*/
public boolean clearOutPutStreams() {
return stream.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ public void close() throws IOException {
stream.close();
}
}

/**
* Clears all the existing output streams.
*
* @return true if at least one output stream has been cleared
*/
public boolean clear() {
if (streams.isEmpty()) {
return false;
}
streams.clear();
return true;
}
}