|
|
|
@ -1,13 +1,21 @@
|
|
|
|
|
package actor;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
|
|
|
|
|
import core.ConnectionHelper;
|
|
|
|
|
import core.MockSet;
|
|
|
|
|
import core.Ride;
|
|
|
|
|
import core.State;
|
|
|
|
|
import exchange.ExchangeMock;
|
|
|
|
|
|
|
|
|
|
public class UserMock extends ActorRunnable {
|
|
|
|
|
|
|
|
|
|
int requestCount = 0;
|
|
|
|
|
|
|
|
|
|
public UserMock(MockSet mockSet){
|
|
|
|
|
super(mockSet);
|
|
|
|
@ -15,8 +23,16 @@ public class UserMock extends ActorRunnable {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
while (true){
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
sendGetRequest();
|
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
@ -27,4 +43,35 @@ public class UserMock extends ActorRunnable {
|
|
|
|
|
void doPost(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* # send GET (Request)
|
|
|
|
|
* Generated by Loop
|
|
|
|
|
*/
|
|
|
|
|
void sendGetRequest() throws IOException, InterruptedException {
|
|
|
|
|
|
|
|
|
|
// Mock Exchange
|
|
|
|
|
ExchangeMock exchange = new ExchangeMock();
|
|
|
|
|
|
|
|
|
|
exchange.request.setMethod("GET");
|
|
|
|
|
exchange.request.setContentType("application/json");
|
|
|
|
|
String requestBody = "REQUEST-"+requestCount++;
|
|
|
|
|
String jsonString = "{\"request\":\""+requestBody+ "\"}";
|
|
|
|
|
exchange.request.setContent(jsonString.getBytes());
|
|
|
|
|
|
|
|
|
|
synchronized (exchange){
|
|
|
|
|
// Mock GET (Request)
|
|
|
|
|
exchange.notify();
|
|
|
|
|
mockSet.bridgeMock.doGet(exchange.request,exchange.response);
|
|
|
|
|
exchange.wait();
|
|
|
|
|
|
|
|
|
|
// handle OK (Data)
|
|
|
|
|
String data = exchange.response.getContentAsString();
|
|
|
|
|
System.out.println(data + " of REQUEST-"+requestCount);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|