[TEST] only reset clients on nightly tests
resetting the clients on each test (in after test) makes the tests running, especially in network mode, much slower, since transport client needs to be created each time when randmized to be used. Also, on OSX, the excessive connections causes bind exceptions eventually which makes running the network tests much harder on it. closes #7329
This commit is contained in:
parent
ab9e33e38d
commit
39a64cf4dd
|
@ -37,7 +37,6 @@ import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
|
||||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||||
import org.elasticsearch.cache.recycler.PageCacheRecyclerModule;
|
import org.elasticsearch.cache.recycler.PageCacheRecyclerModule;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.cluster.ClusterName;
|
import org.elasticsearch.cluster.ClusterName;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
|
@ -99,6 +98,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.frequently;
|
import static com.carrotsearch.randomizedtesting.RandomizedTest.frequently;
|
||||||
|
import static com.carrotsearch.randomizedtesting.RandomizedTest.isNightly;
|
||||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
|
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
|
||||||
import static junit.framework.Assert.fail;
|
import static junit.framework.Assert.fail;
|
||||||
import static org.apache.lucene.util.LuceneTestCase.rarely;
|
import static org.apache.lucene.util.LuceneTestCase.rarely;
|
||||||
|
@ -518,7 +518,7 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
.put("tests.mock.version", version)
|
.put("tests.mock.version", version)
|
||||||
.build();
|
.build();
|
||||||
Node node = nodeBuilder().settings(finalSettings).build();
|
Node node = nodeBuilder().settings(finalSettings).build();
|
||||||
return new NodeAndClient(name, node, new RandomClientFactory(settingsSource));
|
return new NodeAndClient(name, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildNodeName(int id) {
|
private String buildNodeName(int id) {
|
||||||
|
@ -667,17 +667,14 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
|
|
||||||
private final class NodeAndClient implements Closeable {
|
private final class NodeAndClient implements Closeable {
|
||||||
private InternalNode node;
|
private InternalNode node;
|
||||||
private Client client;
|
|
||||||
private Client nodeClient;
|
private Client nodeClient;
|
||||||
private Client transportClient;
|
private Client transportClient;
|
||||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||||
private final ClientFactory clientFactory;
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
NodeAndClient(String name, Node node, ClientFactory factory) {
|
NodeAndClient(String name, Node node) {
|
||||||
this.node = (InternalNode) node;
|
this.node = (InternalNode) node;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.clientFactory = factory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node node() {
|
Node node() {
|
||||||
|
@ -691,54 +688,60 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
throw new RuntimeException("already closed");
|
throw new RuntimeException("already closed");
|
||||||
}
|
}
|
||||||
if (client != null) {
|
double nextDouble = random.nextDouble();
|
||||||
return client;
|
if (nextDouble < transportClientRatio) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Using transport client for node [{}] sniff: [{}]", node.settings().get("name"), false);
|
||||||
|
}
|
||||||
|
return getOrBuildTransportClient();
|
||||||
|
} else {
|
||||||
|
return getOrBuildNodeClient();
|
||||||
}
|
}
|
||||||
return client = clientFactory.client(node, clusterName, random);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Client nodeClient() {
|
Client nodeClient() {
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
throw new RuntimeException("already closed");
|
throw new RuntimeException("already closed");
|
||||||
}
|
}
|
||||||
if (nodeClient == null) {
|
return getOrBuildNodeClient();
|
||||||
Client maybeNodeClient = client(random);
|
|
||||||
if (client instanceof NodeClient) {
|
|
||||||
nodeClient = maybeNodeClient;
|
|
||||||
} else {
|
|
||||||
nodeClient = node.client();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodeClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Client transportClient() {
|
Client transportClient() {
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
throw new RuntimeException("already closed");
|
throw new RuntimeException("already closed");
|
||||||
}
|
}
|
||||||
if (transportClient == null) {
|
return getOrBuildTransportClient();
|
||||||
Client maybeTransportClient = client(random);
|
|
||||||
if (maybeTransportClient instanceof TransportClient) {
|
|
||||||
transportClient = maybeTransportClient;
|
|
||||||
} else {
|
|
||||||
transportClient = TransportClientFactory.noSniff(settingsSource.transportClient()).client(node, clusterName, random);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Client getOrBuildNodeClient() {
|
||||||
|
if (nodeClient != null) {
|
||||||
|
return nodeClient;
|
||||||
}
|
}
|
||||||
|
return nodeClient = node.client();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Client getOrBuildTransportClient() {
|
||||||
|
if (transportClient != null) {
|
||||||
return transportClient;
|
return transportClient;
|
||||||
}
|
}
|
||||||
|
/* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down.
|
||||||
|
* we first need support of transportClientRatio as annotations or so
|
||||||
|
*/
|
||||||
|
return transportClient = TransportClientFactory.noSniff(settingsSource.transportClient()).client(node, clusterName, random);
|
||||||
|
}
|
||||||
|
|
||||||
void resetClient() throws IOException {
|
void resetClient() throws IOException {
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
throw new RuntimeException("already closed");
|
throw new RuntimeException("already closed");
|
||||||
}
|
}
|
||||||
Releasables.close(client, nodeClient, transportClient);
|
Releasables.close(nodeClient, transportClient);
|
||||||
client = null;
|
|
||||||
nodeClient = null;
|
nodeClient = null;
|
||||||
transportClient = null;
|
transportClient = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void restart(RestartCallback callback) throws Exception {
|
void restart(RestartCallback callback) throws Exception {
|
||||||
assert callback != null;
|
assert callback != null;
|
||||||
|
resetClient();
|
||||||
if (!node.isClosed()) {
|
if (!node.isClosed()) {
|
||||||
node.close();
|
node.close();
|
||||||
}
|
}
|
||||||
|
@ -753,29 +756,19 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node = (InternalNode) nodeBuilder().settings(node.settings()).settings(newSettings).node();
|
node = (InternalNode) nodeBuilder().settings(node.settings()).settings(newSettings).node();
|
||||||
resetClient();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
resetClient();
|
||||||
closed.set(true);
|
closed.set(true);
|
||||||
Releasables.close(client, nodeClient);
|
|
||||||
client = null;
|
|
||||||
nodeClient = null;
|
|
||||||
node.close();
|
node.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ClientFactory {
|
|
||||||
|
|
||||||
public Client client(Node node, String clusterName, Random random) {
|
|
||||||
return node.client();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String TRANSPORT_CLIENT_PREFIX = "transport_client_";
|
public static final String TRANSPORT_CLIENT_PREFIX = "transport_client_";
|
||||||
static class TransportClientFactory extends ClientFactory {
|
static class TransportClientFactory {
|
||||||
|
|
||||||
private static TransportClientFactory NO_SNIFF_CLIENT_FACTORY = new TransportClientFactory(false, ImmutableSettings.EMPTY);
|
private static TransportClientFactory NO_SNIFF_CLIENT_FACTORY = new TransportClientFactory(false, ImmutableSettings.EMPTY);
|
||||||
private static TransportClientFactory SNIFF_CLIENT_FACTORY = new TransportClientFactory(true, ImmutableSettings.EMPTY);
|
private static TransportClientFactory SNIFF_CLIENT_FACTORY = new TransportClientFactory(true, ImmutableSettings.EMPTY);
|
||||||
|
@ -802,7 +795,6 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
this.settings = settings != null ? settings : ImmutableSettings.EMPTY;
|
this.settings = settings != null ? settings : ImmutableSettings.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Client client(Node node, String clusterName, Random random) {
|
public Client client(Node node, String clusterName, Random random) {
|
||||||
TransportAddress addr = ((InternalNode) node).injector().getInstance(TransportService.class).boundAddress().publishAddress();
|
TransportAddress addr = ((InternalNode) node).injector().getInstance(TransportService.class).boundAddress().publishAddress();
|
||||||
Settings nodeSettings = node.settings();
|
Settings nodeSettings = node.settings();
|
||||||
|
@ -824,31 +816,6 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RandomClientFactory extends ClientFactory {
|
|
||||||
|
|
||||||
private SettingsSource settingsSource;
|
|
||||||
|
|
||||||
RandomClientFactory(SettingsSource settingsSource) {
|
|
||||||
this.settingsSource = settingsSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Client client(Node node, String clusterName, Random random) {
|
|
||||||
double nextDouble = random.nextDouble();
|
|
||||||
if (nextDouble < transportClientRatio) {
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Using transport client for node [{}] sniff: [{}]", node.settings().get("name"), false);
|
|
||||||
}
|
|
||||||
/* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down.
|
|
||||||
* we first need support of transportClientRatio as annotations or so
|
|
||||||
*/
|
|
||||||
return TransportClientFactory.noSniff(settingsSource.transportClient()).client(node, clusterName, random);
|
|
||||||
} else {
|
|
||||||
return node.client();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void beforeTest(Random random, double transportClientRatio) throws IOException {
|
public synchronized void beforeTest(Random random, double transportClientRatio) throws IOException {
|
||||||
super.beforeTest(random, transportClientRatio);
|
super.beforeTest(random, transportClientRatio);
|
||||||
|
@ -856,7 +823,7 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void reset(boolean wipeData) throws IOException {
|
private synchronized void reset(boolean wipeData) throws IOException {
|
||||||
resetClients(); /* reset all clients - each test gets its own client based on the Random instance created above. */
|
randomlyResetClients();
|
||||||
if (wipeData) {
|
if (wipeData) {
|
||||||
wipeDataDirectories();
|
wipeDataDirectories();
|
||||||
}
|
}
|
||||||
|
@ -936,15 +903,18 @@ public final class InternalTestCluster extends TestCluster {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void afterTest() throws IOException {
|
public synchronized void afterTest() throws IOException {
|
||||||
wipeDataDirectories();
|
wipeDataDirectories();
|
||||||
resetClients(); /* reset all clients - each test gets its own client based on the Random instance created above. */
|
randomlyResetClients(); /* reset all clients - each test gets its own client based on the Random instance created above. */
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetClients() throws IOException {
|
private void randomlyResetClients() throws IOException {
|
||||||
|
// only reset the clients on nightly tests, it causes heavy load...
|
||||||
|
if (isNightly() && rarely(random)) {
|
||||||
final Collection<NodeAndClient> nodesAndClients = nodes.values();
|
final Collection<NodeAndClient> nodesAndClients = nodes.values();
|
||||||
for (NodeAndClient nodeAndClient : nodesAndClients) {
|
for (NodeAndClient nodeAndClient : nodesAndClients) {
|
||||||
nodeAndClient.resetClient();
|
nodeAndClient.resetClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void wipeDataDirectories() {
|
private void wipeDataDirectories() {
|
||||||
if (!dataDirToClean.isEmpty()) {
|
if (!dataDirToClean.isEmpty()) {
|
||||||
|
|
Loading…
Reference in New Issue