-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Http2MetricsTest.java
106 lines (96 loc) · 4.19 KB
/
Http2MetricsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http:https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core.http;
import io.vertx.core.ThreadingModel;
import io.vertx.test.core.TestUtils;
import io.vertx.test.fakemetrics.*;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
@RunWith(Parameterized.class)
public class Http2MetricsTest extends HttpMetricsTestBase {
@Parameterized.Parameters
public static Collection<Object[]> params() {
ArrayList<Object[]> params = new ArrayList<>();
// h2
params.add(new Object[] { Http2TestBase.createHttp2ClientOptions(), Http2TestBase.createHttp2ServerOptions(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST), ThreadingModel.EVENT_LOOP });
// h2 + worker
params.add(new Object[] { Http2TestBase.createHttp2ClientOptions(), Http2TestBase.createHttp2ServerOptions(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST), ThreadingModel.WORKER });
// h2c with upgrade
params.add(new Object[] { new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(true), new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST), ThreadingModel.EVENT_LOOP });
// h2c direct
params.add(new Object[] { new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setHttp2ClearTextUpgrade(false), new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST), ThreadingModel.EVENT_LOOP });
return params;
}
private HttpClientOptions clientOptions;
private HttpServerOptions serverOptions;
public Http2MetricsTest(HttpClientOptions clientOptions, HttpServerOptions serverOptions, ThreadingModel threadingModel) {
super(HttpVersion.HTTP_2, threadingModel);
this.clientOptions = clientOptions;
this.serverOptions = serverOptions.setHandle100ContinueAutomatically(true);
}
@Override
protected HttpServerOptions createBaseServerOptions() {
return serverOptions;
}
@Override
protected HttpClientOptions createBaseClientOptions() {
return clientOptions;
}
@Test
public void testPushPromise() throws Exception {
waitFor(2);
int numBuffers = 10;
int contentLength = numBuffers * 1000;
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble").onComplete(ar -> {
HttpServerResponse pushedResp = ar.result();
FakeHttpServerMetrics serverMetrics = FakeMetricsBase.getMetrics(server);
HttpServerMetric serverMetric = serverMetrics.getResponseMetric("/wibble");
assertNotNull(serverMetric);
pushedResp.putHeader("content-length", "" + contentLength);
AtomicInteger numBuffer = new AtomicInteger(numBuffers);
vertx.setPeriodic(1, timerID -> {
if (numBuffer.getAndDecrement() == 0) {
pushedResp.end().onComplete(onSuccess(v -> {
assertNull(serverMetrics.getResponseMetric("/wibble"));
complete();
}));
vertx.cancelTimer(timerID);
} else {
pushedResp.write(TestUtils.randomBuffer(1000));
}
});
});
});
startServer(testAddress);
client = vertx.createHttpClient(createBaseClientOptions());
FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
client.request(requestOptions).onComplete(onSuccess(req -> {
req.pushHandler(pushedReq -> {
HttpClientMetric metric = metrics.getMetric(pushedReq);
assertNotNull(metric);
pushedReq.response().onComplete(onSuccess(resp -> {
resp.endHandler(v -> {
assertNull(metrics.getMetric(pushedReq));
complete();
});
}));
})
.end();
}));
await();
}
}