use of com.koushikdutta.async.AsyncServer in project AndroidAsync by koush.
the class DnsTests method testNoDomain.
public void testNoDomain() throws Exception {
AsyncServer server = new AsyncServer();
try {
final Semaphore semaphore = new Semaphore(0);
server.connectSocket("www.clockworkmod-notfound.com", 8080, new ConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, AsyncSocket socket) {
assertTrue(ex instanceof UnknownHostException);
semaphore.release();
}
});
assertTrue(semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS));
} finally {
server.stop();
}
}
use of com.koushikdutta.async.AsyncServer in project AndroidAsync by koush.
the class HttpClientTests method testProxy.
public void testProxy() throws Exception {
wasProxied = false;
final AsyncServer proxyServer = new AsyncServer();
try {
AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {
@Override
protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
wasProxied = true;
return super.onRequest(request, response);
}
};
AsyncServerSocket socket = httpServer.listen(proxyServer, 0);
// client.getSocketMiddleware().enableProxy("localhost", 5555);
AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
get.enableProxy("localhost", socket.getLocalPort());
Future<String> ret = client.executeString(get, null);
String data;
assertNotNull(data = ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
assertTrue(data.contains("ClockworkMod"));
assertTrue(wasProxied);
} finally {
proxyServer.stop();
}
}
Aggregations