Merge pull request #19803 from elastic/fix/transportClientTests
Fix PreBuiltTransportClientTests to run and pass
This commit is contained in:
commit
3f6a3c01da
|
@ -34,6 +34,7 @@ dependencies {
|
||||||
compile "org.elasticsearch.plugin:percolator-client:${version}"
|
compile "org.elasticsearch.plugin:percolator-client:${version}"
|
||||||
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
||||||
testCompile "junit:junit:${versions.junit}"
|
testCompile "junit:junit:${versions.junit}"
|
||||||
|
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyLicenses {
|
dependencyLicenses {
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
package org.elasticsearch.transport.client;
|
package org.elasticsearch.transport.client;
|
||||||
|
|
||||||
|
import io.netty.util.ThreadDeathWatcher;
|
||||||
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.common.network.NetworkModule;
|
import org.elasticsearch.common.network.NetworkModule;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
|
@ -34,6 +37,7 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder to create an instance of {@link TransportClient}
|
* A builder to create an instance of {@link TransportClient}
|
||||||
|
@ -79,13 +83,28 @@ public class PreBuiltTransportClient extends TransportClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Settings additionalSettings() {
|
public Settings additionalSettings() {
|
||||||
return Settings.builder()
|
return Settings.builder().put("netty.assert.buglevel", true)
|
||||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
|
|
||||||
.put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
|
|
||||||
.put("netty.assert.buglevel", true)
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
super.close();
|
||||||
|
if (NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings) == false
|
||||||
|
|| NetworkModule.TRANSPORT_TYPE_SETTING.get(settings).equals(Netty4Plugin.NETTY_TRANSPORT_NAME)) {
|
||||||
|
try {
|
||||||
|
GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,13 @@ import org.elasticsearch.index.reindex.ReindexPlugin;
|
||||||
import org.elasticsearch.percolator.PercolatorPlugin;
|
import org.elasticsearch.percolator.PercolatorPlugin;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.script.mustache.MustachePlugin;
|
import org.elasticsearch.script.mustache.MustachePlugin;
|
||||||
import org.elasticsearch.transport.Netty3Plugin;
|
import org.elasticsearch.transport.Netty4Plugin;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class PreBuiltTransportClientTests extends RandomizedTest {
|
public class PreBuiltTransportClientTests extends RandomizedTest {
|
||||||
|
@ -41,7 +42,8 @@ public class PreBuiltTransportClientTests extends RandomizedTest {
|
||||||
public void testPluginInstalled() {
|
public void testPluginInstalled() {
|
||||||
try (TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)) {
|
try (TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)) {
|
||||||
Settings settings = client.settings();
|
Settings settings = client.settings();
|
||||||
assertEquals(Netty3Plugin.NETTY_TRANSPORT_NAME, NetworkModule.HTTP_DEFAULT_TYPE_SETTING.get(settings));
|
assertEquals(Netty4Plugin.NETTY_TRANSPORT_NAME, NetworkModule.HTTP_DEFAULT_TYPE_SETTING.get(settings));
|
||||||
|
assertEquals(Netty4Plugin.NETTY_TRANSPORT_NAME, NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.get(settings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +56,8 @@ public class PreBuiltTransportClientTests extends RandomizedTest {
|
||||||
new PreBuiltTransportClient(Settings.EMPTY, plugin);
|
new PreBuiltTransportClient(Settings.EMPTY, plugin);
|
||||||
fail("exception expected");
|
fail("exception expected");
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
assertEquals("plugin is already installed", ex.getMessage());
|
assertTrue("Expected message to start with [plugin already exists: ] but was instead [" + ex.getMessage() + "]",
|
||||||
|
ex.getMessage().startsWith("plugin already exists: "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.inject.AbstractModule;
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.util.Providers;
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
|
@ -57,9 +56,12 @@ public class NetworkModule extends AbstractModule {
|
||||||
public static final String TRANSPORT_SERVICE_TYPE_KEY = "transport.service.type";
|
public static final String TRANSPORT_SERVICE_TYPE_KEY = "transport.service.type";
|
||||||
public static final String HTTP_TYPE_KEY = "http.type";
|
public static final String HTTP_TYPE_KEY = "http.type";
|
||||||
public static final String LOCAL_TRANSPORT = "local";
|
public static final String LOCAL_TRANSPORT = "local";
|
||||||
|
public static final String HTTP_TYPE_DEFAULT_KEY = "http.type.default";
|
||||||
|
public static final String TRANSPORT_TYPE_DEFAULT_KEY = "transport.type.default";
|
||||||
|
|
||||||
public static final Setting<String> TRANSPORT_DEFAULT_TYPE_SETTING = Setting.simpleString("transport.type.default", Property.NodeScope);
|
public static final Setting<String> TRANSPORT_DEFAULT_TYPE_SETTING = Setting.simpleString(TRANSPORT_TYPE_DEFAULT_KEY,
|
||||||
public static final Setting<String> HTTP_DEFAULT_TYPE_SETTING = Setting.simpleString("http.type.default", Property.NodeScope);
|
Property.NodeScope);
|
||||||
|
public static final Setting<String> HTTP_DEFAULT_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_DEFAULT_KEY, Property.NodeScope);
|
||||||
public static final Setting<String> HTTP_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_KEY, Property.NodeScope);
|
public static final Setting<String> HTTP_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_KEY, Property.NodeScope);
|
||||||
public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true, Property.NodeScope);
|
public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true, Property.NodeScope);
|
||||||
public static final Setting<String> TRANSPORT_SERVICE_TYPE_SETTING =
|
public static final Setting<String> TRANSPORT_SERVICE_TYPE_SETTING =
|
||||||
|
|
Loading…
Reference in New Issue