Last active
September 4, 2018 03:18
-
-
Save jmnarloch/68ab1ce0535733a65a1b293f7cd99886 to your computer and use it in GitHub Desktop.
Elasticsearch Rest Integration Test setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.elasticsearch.common.network.NetworkModule; | |
import org.elasticsearch.common.settings.Settings; | |
import org.elasticsearch.plugins.Plugin; | |
import org.elasticsearch.test.ESIntegTestCase; | |
import org.elasticsearch.test.NodeConfigurationSource; | |
import org.elasticsearch.transport.Netty4Plugin; | |
import org.elasticsearch.transport.nio.NioTransportPlugin; | |
import org.junit.Before; | |
import java.nio.file.Path; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.Collections; | |
@ESIntegTestCase.ClusterScope(scope=ESIntegTestCase.Scope.TEST) | |
public abstract class ElasticsearchIntegTest extends ESIntegTestCase { | |
static { | |
System.setProperty("es.set.netty.runtime.available.processors", "false"); | |
} | |
@Override | |
@Before | |
public void setUp() throws Exception { | |
super.setUp(); | |
} | |
@Override | |
protected Collection<Class<? extends Plugin>> nodePlugins() { | |
Collection<Class<? extends Plugin>> plugins = new ArrayList<>(); | |
plugins.add(Netty4Plugin.class); | |
return Collections.unmodifiableCollection(plugins); | |
} | |
@Override | |
protected NodeConfigurationSource getNodeConfigSource() { | |
Settings.Builder networkSettings = Settings.builder(); | |
networkSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType()); | |
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() { | |
@Override | |
public Settings nodeSettings(int nodeOrdinal) { | |
return Settings.builder() | |
.put(NetworkModule.HTTP_ENABLED.getKey(), true) | |
.put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "netty4") | |
.put(NetworkModule.TRANSPORT_TYPE_SETTING.getKey(), "netty4") | |
.put(ElasticsearchIntegTest.this.nodeSettings(nodeOrdinal)).build(); | |
} | |
@Override | |
public Path nodeConfigPath(int nodeOrdinal) { | |
return ElasticsearchIntegTest.this.nodeConfigPath(nodeOrdinal); | |
} | |
@Override | |
public Collection<Class<? extends Plugin>> nodePlugins() { | |
return ElasticsearchIntegTest.this.nodePlugins(); | |
} | |
@Override | |
public Settings transportClientSettings() { | |
return Settings.builder() | |
.put(ElasticsearchIntegTest.this.transportClientSettings()) | |
.put(networkSettings.build()) | |
.build(); | |
} | |
@Override | |
public Collection<Class<? extends Plugin>> transportClientPlugins() { | |
Collection<Class<? extends Plugin>> plugins = new ArrayList<>(); | |
plugins.add(NioTransportPlugin.class); | |
return Collections.unmodifiableCollection(plugins); | |
} | |
}; | |
return nodeConfigurationSource; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment