Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: net/test/android/javatests/src/org/chromium/net/test/BaseTestServer.java

Issue 867073002: [Android] Add a java version of the test server spawner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: findbugs Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/test/android/javatests/src/org/chromium/net/test/BaseTestServer.java
diff --git a/net/test/android/javatests/src/org/chromium/net/test/BaseTestServer.java b/net/test/android/javatests/src/org/chromium/net/test/BaseTestServer.java
new file mode 100644
index 0000000000000000000000000000000000000000..a9ca6bd6173c71caa9109e36a93fed265bc5ef00
--- /dev/null
+++ b/net/test/android/javatests/src/org/chromium/net/test/BaseTestServer.java
@@ -0,0 +1,37 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.net.test;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/** A base class for simple test servers. */
+public abstract class BaseTestServer implements Runnable {
+ private AtomicBoolean mKeepRunning;
+
+ /** Creates a test server. */
+ public BaseTestServer() {
+ mKeepRunning = new AtomicBoolean(true);
+ }
+
+ /** Accepts incoming connections until stopped via stop(). */
+ public void run() {
+ mKeepRunning.set(true);
+
+ while (mKeepRunning.get()) {
+ accept();
+ }
+ }
+
+ /** Waits for and handles an incoming request. */
+ protected abstract void accept();
+
+ /** Returns the port on which this server is listening for connections. */
+ public abstract int getServerPort();
+
+ /** Stops the server. */
+ public void stop() {
+ mKeepRunning.set(false);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698