Add nio-transport as option for http smoke tests (#31162)

This is related to #27260 and #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.
This commit is contained in:
Tim Brooks 2018-06-07 09:46:36 -06:00 committed by GitHub
parent 56207ea43d
commit 237f9b8930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 28 deletions

View File

@ -202,15 +202,7 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
this.maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
this.maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
this.pipeliningMaxEvents = SETTING_PIPELINING_MAX_EVENTS.get(settings);
this.httpHandlingSettings = new HttpHandlingSettings(Math.toIntExact(maxContentLength.getBytes()),
Math.toIntExact(maxChunkSize.getBytes()),
Math.toIntExact(maxHeaderSize.getBytes()),
Math.toIntExact(maxInitialLineLength.getBytes()),
SETTING_HTTP_RESET_COOKIES.get(settings),
SETTING_HTTP_COMPRESSION.get(settings),
SETTING_HTTP_COMPRESSION_LEVEL.get(settings),
SETTING_HTTP_DETAILED_ERRORS_ENABLED.get(settings),
pipeliningMaxEvents);
this.httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);
this.maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS.get(settings);
this.workerCount = SETTING_HTTP_WORKER_COUNT.get(settings);
@ -446,7 +438,7 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
if (handlingSettings.isCompression()) {
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(handlingSettings.getCompressionLevel()));
}
if (SETTING_CORS_ENABLED.get(transport.settings())) {
if (handlingSettings.isCorsEnabled()) {
ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.getCorsConfig()));
}
ch.pipeline().addLast("pipelining", new Netty4HttpPipeliningHandler(transport.logger, transport.pipeliningMaxEvents));

View File

@ -137,15 +137,7 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
ByteSizeValue maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
ByteSizeValue maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
int pipeliningMaxEvents = SETTING_PIPELINING_MAX_EVENTS.get(settings);
this.httpHandlingSettings = new HttpHandlingSettings(Math.toIntExact(maxContentLength.getBytes()),
Math.toIntExact(maxChunkSize.getBytes()),
Math.toIntExact(maxHeaderSize.getBytes()),
Math.toIntExact(maxInitialLineLength.getBytes()),
SETTING_HTTP_RESET_COOKIES.get(settings),
SETTING_HTTP_COMPRESSION.get(settings),
SETTING_HTTP_COMPRESSION_LEVEL.get(settings),
SETTING_HTTP_DETAILED_ERRORS_ENABLED.get(settings),
pipeliningMaxEvents);
this.httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);;
this.corsConfig = buildCorsConfig(settings);
this.tcpNoDelay = SETTING_HTTP_TCP_NO_DELAY.get(settings);

View File

@ -56,6 +56,7 @@ import java.nio.ByteBuffer;
import java.util.List;
import java.util.function.BiConsumer;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ENABLED;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION_LEVEL;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED;
@ -94,7 +95,8 @@ public class HttpReadWriteHandlerTests extends ESTestCase {
SETTING_HTTP_COMPRESSION.getDefault(settings),
SETTING_HTTP_COMPRESSION_LEVEL.getDefault(settings),
SETTING_HTTP_DETAILED_ERRORS_ENABLED.getDefault(settings),
SETTING_PIPELINING_MAX_EVENTS.getDefault(settings));
SETTING_PIPELINING_MAX_EVENTS.getDefault(settings),
SETTING_CORS_ENABLED.getDefault(settings));
ThreadContext threadContext = new ThreadContext(settings);
nioSocketChannel = mock(NioSocketChannel.class);
handler = new HttpReadWriteHandler(nioSocketChannel, transport, httpHandlingSettings, NamedXContentRegistry.EMPTY,

View File

@ -23,6 +23,7 @@ apply plugin: 'elasticsearch.test-with-dependencies'
dependencies {
testCompile project(path: ':modules:transport-netty4', configuration: 'runtime') // for http
testCompile project(path: ':plugins:transport-nio', configuration: 'runtime') // for http
}
integTestRunner {

View File

@ -25,6 +25,7 @@ import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.transport.MockTcpTransportPlugin;
import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.transport.nio.MockNioTransportPlugin;
import org.elasticsearch.transport.nio.NioTransportPlugin;
import org.junit.BeforeClass;
import java.util.Arrays;
@ -39,9 +40,9 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
@SuppressWarnings("unchecked")
@BeforeClass
public static void setUpTransport() {
nodeTransportTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class));
nodeHttpTypeKey = getTypeKey(Netty4Plugin.class);
clientTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class));
nodeTransportTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class));
nodeHttpTypeKey = getHttpTypeKey(randomFrom(Netty4Plugin.class, NioTransportPlugin.class));
clientTypeKey = getTypeKey(randomFrom(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class));
}
private static String getTypeKey(Class<? extends Plugin> clazz) {
@ -49,12 +50,23 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
return MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME;
} else if (clazz.equals(MockNioTransportPlugin.class)) {
return MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
} else if (clazz.equals(NioTransportPlugin.class)) {
return NioTransportPlugin.NIO_TRANSPORT_NAME;
} else {
assert clazz.equals(Netty4Plugin.class);
return Netty4Plugin.NETTY_TRANSPORT_NAME;
}
}
private static String getHttpTypeKey(Class<? extends Plugin> clazz) {
if (clazz.equals(NioTransportPlugin.class)) {
return NioTransportPlugin.NIO_HTTP_TRANSPORT_NAME;
} else {
assert clazz.equals(Netty4Plugin.class);
return Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME;
}
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
@ -70,12 +82,12 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class);
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class);
}
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class);
return Arrays.asList(getTestTransportPlugin(), Netty4Plugin.class, NioTransportPlugin.class);
}
@Override

View File

@ -22,6 +22,7 @@ package org.elasticsearch.http;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ENABLED;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_COMPRESSION_LEVEL;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED;
@ -47,7 +48,7 @@ public class HttpHandlingSettings {
public HttpHandlingSettings(int maxContentLength, int maxChunkSize, int maxHeaderSize, int maxInitialLineLength,
boolean resetCookies, boolean compression, int compressionLevel, boolean detailedErrorsEnabled,
int pipeliningMaxEvents) {
int pipeliningMaxEvents, boolean corsEnabled) {
this.maxContentLength = maxContentLength;
this.maxChunkSize = maxChunkSize;
this.maxHeaderSize = maxHeaderSize;
@ -57,6 +58,7 @@ public class HttpHandlingSettings {
this.compressionLevel = compressionLevel;
this.detailedErrorsEnabled = detailedErrorsEnabled;
this.pipeliningMaxEvents = pipeliningMaxEvents;
this.corsEnabled = corsEnabled;
}
public static HttpHandlingSettings fromSettings(Settings settings) {
@ -68,7 +70,8 @@ public class HttpHandlingSettings {
SETTING_HTTP_COMPRESSION.get(settings),
SETTING_HTTP_COMPRESSION_LEVEL.get(settings),
SETTING_HTTP_DETAILED_ERRORS_ENABLED.get(settings),
SETTING_PIPELINING_MAX_EVENTS.get(settings));
SETTING_PIPELINING_MAX_EVENTS.get(settings),
SETTING_CORS_ENABLED.get(settings));
}
public int getMaxContentLength() {

View File

@ -20,6 +20,7 @@ import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.transport.nio.NioTransportPlugin;
import org.elasticsearch.xpack.sql.plugin.SqlQueryAction;
import org.elasticsearch.xpack.sql.plugin.SqlQueryRequestBuilder;
import org.elasticsearch.xpack.sql.plugin.SqlQueryResponse;
@ -66,9 +67,10 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
// Enable http so we can test JDBC licensing because only exists on the REST layer.
String httpPlugin = randomBoolean() ? Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME : NioTransportPlugin.NIO_TRANSPORT_NAME;
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
.put(NetworkModule.HTTP_TYPE_KEY, httpPlugin)
.build();
}