Skip to content

Commit 3fad3f9

Browse files
committed
Add nio-transport as option for http smoke tests
This is related to elastic#27260 and elastic#28898. This commit adds the transport-nio plugin as a random option when running the http smoke tests. As part of this PR, I identified an issue where cors support was not properly enabled causing these tests to fail when using transport-nio. This commit also fixes that issue.
1 parent 7f0c2e8 commit 3fad3f9

File tree

7 files changed

+32
-28
lines changed

7 files changed

+32
-28
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,7 @@ public Netty4HttpServerTransport(Settings settings, NetworkService networkServic
202202
this.maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
203203
this.maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
204204
this.pipeliningMaxEvents = SETTING_PIPELINING_MAX_EVENTS.get(settings);
205-
this.httpHandlingSettings = new HttpHandlingSettings(Math.toIntExact(maxContentLength.getBytes()),
206-
Math.toIntExact(maxChunkSize.getBytes()),
207-
Math.toIntExact(maxHeaderSize.getBytes()),
208-
Math.toIntExact(maxInitialLineLength.getBytes()),
209-
SETTING_HTTP_RESET_COOKIES.get(settings),
210-
SETTING_HTTP_COMPRESSION.get(settings),
211-
SETTING_HTTP_COMPRESSION_LEVEL.get(settings),
212-
SETTING_HTTP_DETAILED_ERRORS_ENABLED.get(settings),
213-
pipeliningMaxEvents);
205+
this.httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);
214206

215207
this.maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS.get(settings);
216208
this.workerCount = SETTING_HTTP_WORKER_COUNT.get(settings);
@@ -446,7 +438,7 @@ protected void initChannel(Channel ch) throws Exception {
446438
if (handlingSettings.isCompression()) {
447439
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(handlingSettings.getCompressionLevel()));
448440
}
449-
if (SETTING_CORS_ENABLED.get(transport.settings())) {
441+
if (handlingSettings.isCorsEnabled()) {
450442
ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.getCorsConfig()));
451443
}
452444
ch.pipeline().addLast("pipelining", new Netty4HttpPipeliningHandler(transport.logger, transport.pipeliningMaxEvents));

plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,7 @@ public NioHttpServerTransport(Settings settings, NetworkService networkService,
137137
ByteSizeValue maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
138138
ByteSizeValue maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
139139
int pipeliningMaxEvents = SETTING_PIPELINING_MAX_EVENTS.get(settings);
140-
this.httpHandlingSettings = new HttpHandlingSettings(Math.toIntExact(maxContentLength.getBytes()),
141-
Math.toIntExact(maxChunkSize.getBytes()),
142-
Math.toIntExact(maxHeaderSize.getBytes()),
143-
Math.toIntExact(maxInitialLineLength.getBytes()),
144-
SETTING_HTTP_RESET_COOKIES.get(settings),
145-
SETTING_HTTP_COMPRESSION.get(settings),
146-
SETTING_HTTP_COMPRESSION_LEVEL.get(settings),
147-
SETTING_HTTP_DETAILED_ERRORS_ENABLED.get(settings),
148-
pipeliningMaxEvents);
140+
this.httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);;
149141
this.corsConfig = buildCorsConfig(settings);
150142

151143
this.tcpNoDelay = SETTING_HTTP_TCP_NO_DELAY.get(settings);

plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/HttpReadWriteHandlerTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.List;
5757
import java.util.function.BiConsumer;
5858

59+
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ENABLED;
5960
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION;
6061
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION_LEVEL;
6162
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED;
@@ -94,7 +95,8 @@ public void setMocks() {
9495
SETTING_HTTP_COMPRESSION.getDefault(settings),
9596
SETTING_HTTP_COMPRESSION_LEVEL.getDefault(settings),
9697
SETTING_HTTP_DETAILED_ERRORS_ENABLED.getDefault(settings),
97-
SETTING_PIPELINING_MAX_EVENTS.getDefault(settings));
98+
SETTING_PIPELINING_MAX_EVENTS.getDefault(settings),
99+
SETTING_CORS_ENABLED.getDefault(settings));
98100
ThreadContext threadContext = new ThreadContext(settings);
99101
nioSocketChannel = mock(NioSocketChannel.class);
100102
handler = new HttpReadWriteHandler(nioSocketChannel, transport, httpHandlingSettings, NamedXContentRegistry.EMPTY,

qa/smoke-test-http/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ apply plugin: 'elasticsearch.test-with-dependencies'
2323

2424
dependencies {
2525
testCompile project(path: ':modules:transport-netty4', configuration: 'runtime') // for http
26+
testCompile project(path: ':plugins:transport-nio', configuration: 'runtime') // for http
2627
}
2728

2829
integTestRunner {

qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpSmokeTestCase.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.transport.MockTcpTransportPlugin;
2626
import org.elasticsearch.transport.Netty4Plugin;
2727
import org.elasticsearch.transport.nio.MockNioTransportPlugin;
28+
import org.elasticsearch.transport.nio.NioTransportPlugin;
2829
import org.junit.BeforeClass;
2930

3031
import java.util.Arrays;
@@ -39,22 +40,33 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
3940
@SuppressWarnings("unchecked")
4041
@BeforeClass
4142
public static void setUpTransport() {
42-
nodeTransportTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class));
43-
nodeHttpTypeKey = getTypeKey(Netty4Plugin.class);
44-
clientTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class));
43+
nodeTransportTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class));
44+
nodeHttpTypeKey = getHttpTypeKey(randomFrom(Netty4Plugin.class, NioTransportPlugin.class));
45+
clientTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class));
4546
}
4647

4748
private static String getTypeKey(Class<? extends Plugin> clazz) {
4849
if (clazz.equals(MockTcpTransportPlugin.class)) {
4950
return MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME;
5051
} else if (clazz.equals(MockNioTransportPlugin.class)) {
5152
return MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
53+
} else if (clazz.equals(NioTransportPlugin.class)) {
54+
return NioTransportPlugin.NIO_TRANSPORT_NAME;
5255
} else {
5356
assert clazz.equals(Netty4Plugin.class);
5457
return Netty4Plugin.NETTY_TRANSPORT_NAME;
5558
}
5659
}
5760

61+
private static String getHttpTypeKey(Class<? extends Plugin> clazz) {
62+
if (clazz.equals(NioTransportPlugin.class)) {
63+
return NioTransportPlugin.NIO_HTTP_TRANSPORT_NAME;
64+
} else {
65+
assert clazz.equals(Netty4Plugin.class);
66+
return Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME;
67+
}
68+
}
69+
5870
@Override
5971
protected boolean addMockHttpTransport() {
6072
return false; // enable http
@@ -70,12 +82,12 @@ protected Settings nodeSettings(int nodeOrdinal) {
7082

7183
@Override
7284
protected Collection<Class<? extends Plugin>> nodePlugins() {
73-
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class);
85+
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class);
7486
}
7587

7688
@Override
7789
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
78-
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class);
90+
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class);
7991
}
8092

8193
@Override

server/src/main/java/org/elasticsearch/http/HttpHandlingSettings.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.common.settings.Settings;
2323
import org.elasticsearch.common.unit.ByteSizeValue;
2424

25+
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ENABLED;
2526
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION;
2627
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION_LEVEL;
2728
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED;
@@ -47,7 +48,7 @@ public class HttpHandlingSettings {
4748

4849
public HttpHandlingSettings(int maxContentLength, int maxChunkSize, int maxHeaderSize, int maxInitialLineLength,
4950
boolean resetCookies, boolean compression, int compressionLevel, boolean detailedErrorsEnabled,
50-
int pipeliningMaxEvents) {
51+
int pipeliningMaxEvents, boolean corsEnabled) {
5152
this.maxContentLength = maxContentLength;
5253
this.maxChunkSize = maxChunkSize;
5354
this.maxHeaderSize = maxHeaderSize;
@@ -57,6 +58,7 @@ public HttpHandlingSettings(int maxContentLength, int maxChunkSize, int maxHeade
5758
this.compressionLevel = compressionLevel;
5859
this.detailedErrorsEnabled = detailedErrorsEnabled;
5960
this.pipeliningMaxEvents = pipeliningMaxEvents;
61+
this.corsEnabled = corsEnabled;
6062
}
6163

6264
public static HttpHandlingSettings fromSettings(Settings settings) {
@@ -68,7 +70,8 @@ public static HttpHandlingSettings fromSettings(Settings settings) {
6870
SETTING_HTTP_COMPRESSION.get(settings),
6971
SETTING_HTTP_COMPRESSION_LEVEL.get(settings),
7072
SETTING_HTTP_DETAILED_ERRORS_ENABLED.get(settings),
71-
SETTING_PIPELINING_MAX_EVENTS.get(settings));
73+
SETTING_PIPELINING_MAX_EVENTS.get(settings),
74+
SETTING_CORS_ENABLED.get(settings));
7275
}
7376

7477
public int getMaxContentLength() {

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
2121
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
2222
import org.elasticsearch.transport.Netty4Plugin;
23+
import org.elasticsearch.transport.nio.NioTransportPlugin;
2324
import org.elasticsearch.xpack.sql.plugin.SqlQueryAction;
2425
import org.elasticsearch.xpack.sql.plugin.SqlQueryRequestBuilder;
2526
import org.elasticsearch.xpack.sql.plugin.SqlQueryResponse;
@@ -66,9 +67,10 @@ protected boolean addMockHttpTransport() {
6667
@Override
6768
protected Settings nodeSettings(int nodeOrdinal) {
6869
// Enable http so we can test JDBC licensing because only exists on the REST layer.
70+
String httpPlugin = randomBoolean() ? Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME : NioTransportPlugin.NIO_TRANSPORT_NAME;
6971
return Settings.builder()
7072
.put(super.nodeSettings(nodeOrdinal))
71-
.put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
73+
.put(NetworkModule.HTTP_TYPE_KEY, httpPlugin)
7274
.build();
7375
}
7476

0 commit comments

Comments
 (0)