Skip to content

Commit 2992e07

Browse files
committed
🔧 update tests for test site https redirect
1 parent 06a79c9 commit 2992e07

15 files changed

+348
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@
3737
#intellij idea files
3838
.idea
3939
*.iml
40+
/nginx-tomcat9/

project.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
[ring/ring-core "1.7.1"]
5757
[compojure "1.1.6"]
5858
[clj-http "0.7.8"]
59-
[junit/junit "4.11"]
59+
[junit/junit "4.13.1"]
6060
[org.clojure/java.jdbc "0.3.3"]
6161
[mysql/mysql-connector-java "5.1.30"]
6262
[redis.clients/jedis "3.1.0"]
@@ -85,7 +85,7 @@
8585
[ring/ring-core "1.7.1"]
8686
[compojure "1.1.6"]
8787
[clj-http "0.7.8"]
88-
[junit/junit "4.11"]
88+
[junit/junit "4.13.1"]
8989
[org.clojure/java.jdbc "0.3.3"]
9090
[org.codehaus.jackson/jackson-mapper-asl "1.9.13"]
9191
[javax.xml.bind/jaxb-api "2.3.1"]
@@ -113,7 +113,7 @@
113113
[ring/ring-core "1.7.1"]
114114
[compojure "1.1.6"]
115115
[clj-http "0.7.8"]
116-
[junit/junit "4.11"]
116+
[junit/junit "4.13.1"]
117117
[org.clojure/java.jdbc "0.3.3"]
118118
[org.clojure/tools.nrepl "0.2.3"]
119119
;for test file upload with ring-core which need it

test/clojure/nginx/clojure/coroutine_socket_handlers_for_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
(defroutes coroutine-socket-test-handler
5050
(GET "/simple-clj-http-test" []
51-
(let [{:keys [status, headers, body]} (client/get "http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt" {:socket-timeout 50000})]
51+
(let [{:keys [status, headers, body]} (client/get "https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt" {:socket-timeout 50000})]
5252
(println headers)
5353
(println (.length body))
5454
{:status status, :headers (dissoc headers "transfer-encoding" "server" "content-length" "connection" "etag"), :body body}))
@@ -69,8 +69,8 @@
6969
)
7070
(GET "/fetch-two-pages" []
7171
(let [[r1 r2] (co-pvalues
72-
(client/get "http://www.apache.org/dist/httpcomponents/httpclient/KEYS" {:socket-timeout 10000})
73-
(client/get "http://www.apache.org/dist/httpcomponents/httpcore/KEYS" {:socket-timeout 10000}))]
72+
(client/get "https://www.apache.org/dist/httpcomponents/httpclient/KEYS" {:socket-timeout 10000})
73+
(client/get "https://www.apache.org/dist/httpcomponents/httpcore/KEYS" {:socket-timeout 10000}))]
7474
{:status 200,
7575
:headers {"content-type" "text/html"},
7676
:body (str (:body r1) "\n==========================\n" (:body r2)) }))

test/clojure/nginx/clojure/filter_handlers_for_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(throw (RuntimeException. "Hello, exception in header filter!")))
2222

2323
(defn access-remote-header-filter [status request response-headers]
24-
(let [resp (client/get "http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt" {:socket-timeout 50000})
24+
(let [resp (client/get "https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt" {:socket-timeout 50000})
2525
body (:body resp)]
2626
(assoc! response-headers "remote-content-length" (.length body))
2727
phase-done))

test/clojure/nginx/clojure/test_all.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@
436436

437437
(def remote-http-content
438438
(delay
439-
(let [r1 (client/get "http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt" {:socket-timeout 10000})
439+
(let [r1 (client/get "https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt" {:socket-timeout 10000})
440440
b1 (r1 :body)] b1)))
441441

442442
(deftest ^{:async true :remote true} test-asyncsocket

test/java/nginx/clojure/java/AccessHandlerTestSet4NginxJavaRingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public Object[] invoke(Map<String, Object> request) throws SuspendExecution {
101101
CloseableHttpClient httpclient = HttpClients.createDefault();
102102
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(10000).setConnectTimeout(10000)
103103
.setSocketTimeout(10000).build();
104-
HttpGet httpget = new HttpGet("http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
104+
HttpGet httpget = new HttpGet("https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
105105
httpget.setConfig(requestConfig);
106106
httpget.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36");
107107
CloseableHttpResponse response = null;

test/java/nginx/clojure/java/FilterTestSet4NginxJavaHeaderFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static class AccessRemoteHeaderFilter implements NginxJavaHeaderFilter {
7171
public Object[] doFilter(int status, Map<String, Object> request, Map<String, Object> responseHeaders) {
7272

7373
CloseableHttpClient httpclient = HttpClients.createDefault();
74-
HttpGet httpget = new HttpGet("http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
74+
HttpGet httpget = new HttpGet("https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
7575
CloseableHttpResponse response = null;
7676
try {
7777
response = httpclient.execute(httpget);
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* Copyright (C) Zhang,Yuexiang (xfeep)
3+
*
4+
*/
5+
package nginx.clojure.java;
6+
7+
import static nginx.clojure.MiniConstants.HEADERS;
8+
9+
import java.io.IOException;
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
import java.util.Random;
13+
import java.util.UUID;
14+
import java.util.concurrent.ConcurrentHashMap;
15+
16+
import org.apache.http.HttpResponse;
17+
import org.apache.http.client.methods.HttpGet;
18+
import org.apache.http.impl.client.CloseableHttpClient;
19+
import org.apache.http.impl.client.HttpClients;
20+
import org.apache.http.util.EntityUtils;
21+
import org.codehaus.jackson.map.ObjectMapper;
22+
import org.codehaus.jackson.type.TypeReference;
23+
24+
import nginx.clojure.NginxClojureRT;
25+
26+
public class Loadstress {
27+
28+
29+
public static class HeaderEchoHanlder implements NginxJavaRingHandler {
30+
31+
/* (non-Javadoc)
32+
* @see nginx.clojure.java.NginxJavaRingHandler#invoke(java.util.Map)
33+
*/
34+
@Override
35+
public Object[] invoke(Map<String, Object> request) throws IOException {
36+
String processId = NginxClojureRT.processId;
37+
Map requestHeaders = (Map) request.get(HEADERS);
38+
Map<String, String> response = new HashMap();
39+
response.putAll(requestHeaders);
40+
response.put("pid", processId);
41+
// try {
42+
// Thread.sleep(10000);
43+
// } catch (InterruptedException e) {
44+
// // TODO Auto-generated catch block
45+
// e.printStackTrace();
46+
// }
47+
return new Object[] {200,ArrayMap.create(Constants.CONTENT_TYPE, "text/plain"),
48+
new ObjectMapper().writeValueAsString(response)};
49+
}
50+
51+
}
52+
53+
54+
/**
55+
*
56+
*/
57+
public Loadstress() {
58+
// TODO Auto-generated constructor stub
59+
}
60+
61+
/**
62+
* @param args
63+
*/
64+
public static void main(String[] args) {
65+
byte[] prefix = new byte[1024];
66+
Random random = new Random();
67+
68+
for (int i = 0; i < prefix.length; i++) {
69+
prefix[i] = (byte)((Math.abs(random.nextInt()) % 26) + 'a');
70+
}
71+
72+
String prefixStr = new String(prefix);
73+
ConcurrentHashMap<String, String> pids = new ConcurrentHashMap<String, String>();
74+
Thread[] threads = new Thread[50];
75+
int max = 100;
76+
String url = "http://172.16.111.1:8080/java/loadheader";
77+
System.out.println(prefixStr);
78+
System.out.println((prefixStr + UUID.randomUUID().toString()).length());
79+
80+
// if (1 == 1) {
81+
// return;
82+
// }
83+
84+
for (int i = 0; i < threads.length; i++) {
85+
threads[i] = new Thread(()->{
86+
for (int c = 0; c < max; c++) {
87+
String cookie = prefixStr + UUID.randomUUID().toString();
88+
ObjectMapper om = new ObjectMapper();
89+
try(CloseableHttpClient httpClient = HttpClients.custom()
90+
.build()) {
91+
HttpGet httpGet = new HttpGet(url);
92+
httpGet.addHeader("Cookie", "sid="+cookie);
93+
HttpResponse response = httpClient.execute(httpGet);
94+
String body = EntityUtils.toString(response.getEntity());
95+
// System.out.println(body);
96+
Map<String,String> rh = om.readValue(body, new TypeReference<Map<String,String>>() {
97+
});
98+
if (!("sid="+cookie).equals(rh.get("Cookie"))) {
99+
System.err.println("wrong cookie:" + rh.get("Cookie") + ", r:" + cookie);
100+
}
101+
pids.put(rh.get("pid"), "g");
102+
} catch (Throwable e) {
103+
// TODO Auto-generated catch block
104+
e.printStackTrace();
105+
}
106+
107+
}
108+
});
109+
threads[i].start();
110+
}
111+
112+
for (int i = 0; i < threads.length; i++) {
113+
try {
114+
threads[i].join();
115+
} catch (InterruptedException e) {
116+
// TODO Auto-generated catch block
117+
e.printStackTrace();
118+
}
119+
}
120+
121+
System.out.println("pids " + pids.size());
122+
System.out.println(pids);
123+
}
124+
125+
}

test/java/nginx/clojure/java/RewriteHandlerTestSet4NginxJavaRingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public Object[] invoke(Map<String, Object> request) throws IOException, SuspendE
182182

183183
CloseableHttpClient httpclient = HttpClients.createDefault();
184184
// HttpGet httpget = new HttpGet("http://cn.bing.com/");
185-
HttpGet httpget = new HttpGet("http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
185+
HttpGet httpget = new HttpGet("https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
186186
httpget.setConfig(RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build());
187187
CloseableHttpResponse response = null;
188188
try {

test/java/nginx/clojure/java/WebSocketTestSet4NginxJavaRingHandler.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,67 @@ public void onError(NginxHttpServerChannel data, long status) {
8888
}
8989
}
9090

91+
public static class WSCloseHandler implements NginxJavaRingHandler {
92+
93+
/* (non-Javadoc)
94+
* @see nginx.clojure.java.NginxJavaRingHandler#invoke(java.util.Map)
95+
*/
96+
@Override
97+
public Object[] invoke(Map<String, Object> request) throws IOException {
98+
NginxJavaRequest r = (NginxJavaRequest)request;
99+
NginxHttpServerChannel sc = r.hijack(true);
100+
sc.addListener(sc, new MessageAdapter<NginxHttpServerChannel>() {
101+
int total = 0;
102+
@Override
103+
public void onOpen(NginxHttpServerChannel data) {
104+
NginxClojureRT.log.debug("WSCloseHandler onOpen!");
105+
}
106+
107+
@Override
108+
public void onTextMessage(NginxHttpServerChannel sc, String message, boolean remaining) throws IOException {
109+
if (NginxClojureRT.log.isDebugEnabled()) {
110+
NginxClojureRT.log.debug("WSCloseHandler onTextMessage: msg=%s, rem=%s", HackUtils.truncateToDotAppendString(message, 10), remaining);
111+
}
112+
113+
if (total > 0) {
114+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
115+
stream.write(new byte[] {0x11, 0x33}); // code = 4403
116+
stream.write("User Error".getBytes("utf8"));
117+
byte[] closeMessage = stream.toByteArray();
118+
sc.send(closeMessage, 0, closeMessage.length, true, true);
119+
} else {
120+
total += message.length();
121+
sc.send(message, !remaining, false);
122+
}
123+
}
124+
125+
@Override
126+
public void onClose(NginxHttpServerChannel req) {
127+
if (NginxClojureRT.log.isDebugEnabled()) {
128+
NginxClojureRT.log.debug("WSCloseHandler onClose: total=%d", total);
129+
}
130+
131+
}
132+
133+
@Override
134+
public void onClose(NginxHttpServerChannel req, long status, String reason) {
135+
if (NginxClojureRT.log.isDebugEnabled()) {
136+
NginxClojureRT.log.info("WSCloseHandler onClose2: total=%d, status=%d, reason=%s", total, status, reason);
137+
}
138+
}
139+
140+
@Override
141+
public void onError(NginxHttpServerChannel data, long status) {
142+
if (NginxClojureRT.log.isDebugEnabled()) {
143+
NginxClojureRT.log.info("WSCloseHandler onError: total=%d, status=%d", total, status);
144+
}
145+
}
146+
});
147+
return null;
148+
}
149+
150+
}
151+
91152
public static class NonAutoUpgradeWSEcho extends WSEcho {
92153

93154
@Override

test/java/nginx/clojure/net/SimpleHandler4TestHttpClientGetMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public SimpleHandler4TestHttpClientGetMethod() {
2424
public Object[] invoke(Map<String, Object> request) {
2525
CloseableHttpClient httpclient = HttpClients.createDefault();
2626
// HttpGet httpget = new HttpGet("http://cn.bing.com/");
27-
HttpGet httpget = new HttpGet("http://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
27+
HttpGet httpget = new HttpGet("https://www.apache.org/dist/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt");
2828
CloseableHttpResponse response = null;
2929
try {
3030
response = httpclient.execute(httpget);

test/nginx-working-dir/conf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
/nginx-ws-java-clj-tomcat.conf
1111
/tengine-enable-coroutine.conf
1212
/ws-nginx-plain.conf
13+
/nginx-tomcat9.conf

test/nginx-working-dir/conf/nginx-coroutine.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
###you can uncomment next two lines for easy debug
33
daemon off;
44
###Warning: if master_process is off, there will be only one nginx worker running. Only use it for debug propose.
5-
#master_process off;
5+
master_process off;
66

77
#user nobody;
88
###you can set worker_processes =1 for easy debug

test/nginx-working-dir/conf/nginx-plain.conf

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ http {
9090
jvm_options "-Dfile.encoding=UTF-8";
9191

9292
###for enable java remote debug uncomment next two lines, make sure "master_process = off"
93-
jvm_options "-Xdebug";
94-
jvm_options "-Xrunjdwp:server=y,transport=dt_socket,address=840#{pno},suspend=n";
93+
#jvm_options "-Xdebug";
94+
#jvm_options "-Xrunjdwp:server=y,transport=dt_socket,address=840#{pno},suspend=n";
9595

9696
#for outofmemory dump
9797
#jvm_options "-XX:+HeapDumpOnOutOfMemoryError";
@@ -101,8 +101,8 @@ http {
101101
# jvm_options "-XX:MaxGCPauseMillis=25";
102102
#jvm_options "-XX:+UseG1GC";
103103

104-
#jvm_options "-Xms1024m";
105-
#jvm_options "-Xmx1024m";
104+
jvm_options "-Xms512m";
105+
jvm_options "-Xmx512m";
106106

107107
shared_map PubSubTopic tinymap?space=1m&entries=256;
108108

@@ -239,6 +239,11 @@ http {
239239
content_handler_property file testfiles/wcp.html;
240240
send_timeout 10s;
241241
}
242+
243+
location /java/loadheader {
244+
content_handler_type java;
245+
content_handler_name 'nginx.clojure.java.Loadstress$HeaderEchoHanlder';
246+
}
242247

243248
location /groovy {
244249
content_handler_type 'groovy';
@@ -1064,6 +1069,12 @@ http {
10641069
location /java-ws/wh-echo {
10651070
content_handler_name 'nginx.clojure.java.WebSocketTestSet4NginxJavaRingHandler$WSWholeTextHandler';
10661071
}
1072+
1073+
location /java-ws/close {
1074+
auto_upgrade_ws on;
1075+
content_handler_name 'nginx.clojure.java.WebSocketTestSet4NginxJavaRingHandler$WSCloseHandler';
1076+
}
1077+
10671078
location /java-ws/echo.xhtml {
10681079
alias /home/who/git/tomcat80/webapps/examples/websocket/echo.xhtml;
10691080
}

0 commit comments

Comments
 (0)