Cut over to JUnit & Randomized Runner from TestNG

For better integration with the Lucene Test Framework and the
availabilty of RandomizedRunner / Randommized Testing this commit
moves over from TestNG to JUnit.
This commit also moves relevant places over to RandomzedRunner for
reproduceability and removes copied classes from the Lucene Test
Framework.
This commit is contained in:
Simon Willnauer 2013-07-19 14:38:59 +02:00
parent 5de9877405
commit ed473e272d
329 changed files with 1889 additions and 2789 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ logs/
.DS_Store
build/
target/
.local-execution-hints.log
## eclipse ignores (use 'mvn eclipse:eclipse' to build eclipse projects)
## The only configuration files which are not ignored are .settings since

133
pom.xml
View File

@ -31,6 +31,9 @@
<properties>
<lucene.version>4.4.0</lucene.version>
<tests.jvms>auto</tests.jvms>
<tests.shuffle>true</tests.shuffle>
<tests.failfast>true</tests.failfast>
</properties>
<repositories>
@ -42,7 +45,18 @@
</repositories>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>${lucene.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
@ -254,30 +268,6 @@
<optional>true</optional>
</dependency>
-->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -326,27 +316,84 @@
</configuration>
</plugin>
<plugin>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>junit4-maven-plugin</artifactId>
<version>2.0.10</version>
<executions>
<execution>
<id>tests</id>
<phase>test</phase>
<goals>
<goal>junit4</goal>
</goals>
<configuration>
<heartbeat>20</heartbeat>
<jvmOutputAction>pipe,warn</jvmOutputAction>
<leaveTemporary>true</leaveTemporary>
<listeners>
<report-ant-xml mavenExtensions="true" dir="${project.build.directory}/surefire-reports" />
<report-text
showThrowable="true"
showStackTraces="true"
showOutput="onerror"
showStatusOk="false"
showStatusError="true"
showStatusFailure="true"
showStatusIgnored="true"
showSuiteSummary="true"
timestamps="false" />
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
</listeners>
<assertions>
<enable />
</assertions>
<parallelism>${tests.jvms}</parallelism>
<balancers>
<execution-times>
<fileset dir="${basedir}" includes=".local-execution-hints.log" />
</execution-times>
</balancers>
<includes>
<include>**/*Tests.class</include>
</includes>
<excludes>
<exclude>**/Abstract*.class</exclude>
</excludes>
<jvmArgs>
<param>-Xmx512m</param>
<param>-Des.logger.prefix=</param>
</jvmArgs>
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
<sysouts>${tests.verbose}</sysouts>
<seed>${tests.seed}</seed>
<haltOnFailure>${tests.failfast}</haltOnFailure>
<systemProperties>
<!-- RandomizedTesting library system properties -->
<tests.iters>${tests.iters}</tests.iters>
<tests.class>${tests.class}</tests.class>
<tests.method>${tests.method}</tests.method>
<tests.nightly>${tests.nightly}</tests.nightly>
<tests.badapples>${tests.badapples}</tests.badapples>
<tests.weekly>${tests.weekly}</tests.weekly>
<tests.slow>${tests.slow}</tests.slow>
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
<tests.slow>${tests.slow}</tests.slow>
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
<es.transport.tcp.compress>${env.ES_TEST_COMPRESS}</es.transport.tcp.compress>
<es.action.wait_on_mapping_change>${env.ES_WAIT_ON_MAPPING_CHANGE}</es.action.wait_on_mapping_change>
<java.awt.headless>true</java.awt.headless>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- we skip surefire to work with randomized testing above -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.3</version>
<version>2.15</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<properties>
<property>
<name>listener</name>
<value>org.elasticsearch.test.TestNGLoggingListener</value>
</property>
</properties>
<argLine>-Xmx512m -Des.logger.prefix=</argLine>
<systemPropertyVariables>
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
<es.transport.tcp.compress>${env.ES_TEST_COMPRESS}</es.transport.tcp.compress>
<es.action.wait_on_mapping_change>${env.ES_WAIT_ON_MAPPING_CHANGE}
</es.action.wait_on_mapping_change>
<java.awt.headless>true</java.awt.headless>
</systemPropertyVariables>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>

View File

@ -19,11 +19,8 @@
package org.elasticsearch.cluster.routing.allocation.allocator;
import org.apache.lucene.util.IntroSorter;
import org.apache.lucene.util.IntroSorter;
import com.google.common.base.Predicate;
import org.apache.lucene.util.IntroSorter;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.MutableShardRouting;
@ -455,6 +452,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
deltas[i] = sorter.delta();
}
new IntroSorter() {
float pivotWeight;
@Override

View File

@ -19,11 +19,13 @@
package org.apache.lucene.analysis.miscellaneous;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.elasticsearch.common.lucene.Lucene;
import org.testng.annotations.Test;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
@ -31,10 +33,9 @@ import java.io.StringReader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*/
@Test
public class TruncateTokenFilterTests {
@Test

View File

@ -19,11 +19,13 @@
package org.apache.lucene.analysis.miscellaneous;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.elasticsearch.common.lucene.Lucene;
import org.testng.annotations.Test;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
@ -34,7 +36,6 @@ import static org.hamcrest.Matchers.equalTo;
/**
*/
@Test
public class UniqueTokenFilterTests {
@Test

View File

@ -1,188 +0,0 @@
package org.apache.lucene.util;
// LUCENE WATCH - if we use the test-framework we can trash this class
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Converts numbers to english strings for testing.
* @lucene.internal
*/
public final class English {
private English() {} // no instance
public static String longToEnglish(long i) {
StringBuilder result = new StringBuilder();
longToEnglish(i, result);
return result.toString();
}
public static void longToEnglish(long i, StringBuilder result) {
if (i == 0) {
result.append("zero");
return;
}
if (i < 0) {
result.append("minus ");
i = -i;
}
if (i >= 1000000000000000000l) { // quadrillion
longToEnglish(i / 1000000000000000000l, result);
result.append("quintillion, ");
i = i % 1000000000000000000l;
}
if (i >= 1000000000000000l) { // quadrillion
longToEnglish(i / 1000000000000000l, result);
result.append("quadrillion, ");
i = i % 1000000000000000l;
}
if (i >= 1000000000000l) { // trillions
longToEnglish(i / 1000000000000l, result);
result.append("trillion, ");
i = i % 1000000000000l;
}
if (i >= 1000000000) { // billions
longToEnglish(i / 1000000000, result);
result.append("billion, ");
i = i % 1000000000;
}
if (i >= 1000000) { // millions
longToEnglish(i / 1000000, result);
result.append("million, ");
i = i % 1000000;
}
if (i >= 1000) { // thousands
longToEnglish(i / 1000, result);
result.append("thousand, ");
i = i % 1000;
}
if (i >= 100) { // hundreds
longToEnglish(i / 100, result);
result.append("hundred ");
i = i % 100;
}
//we know we are smaller here so we can cast
if (i >= 20) {
switch (((int) i) / 10) {
case 9:
result.append("ninety");
break;
case 8:
result.append("eighty");
break;
case 7:
result.append("seventy");
break;
case 6:
result.append("sixty");
break;
case 5:
result.append("fifty");
break;
case 4:
result.append("forty");
break;
case 3:
result.append("thirty");
break;
case 2:
result.append("twenty");
break;
}
i = i % 10;
if (i == 0)
result.append(" ");
else
result.append("-");
}
switch ((int) i) {
case 19:
result.append("nineteen ");
break;
case 18:
result.append("eighteen ");
break;
case 17:
result.append("seventeen ");
break;
case 16:
result.append("sixteen ");
break;
case 15:
result.append("fifteen ");
break;
case 14:
result.append("fourteen ");
break;
case 13:
result.append("thirteen ");
break;
case 12:
result.append("twelve ");
break;
case 11:
result.append("eleven ");
break;
case 10:
result.append("ten ");
break;
case 9:
result.append("nine ");
break;
case 8:
result.append("eight ");
break;
case 7:
result.append("seven ");
break;
case 6:
result.append("six ");
break;
case 5:
result.append("five ");
break;
case 4:
result.append("four ");
break;
case 3:
result.append("three ");
break;
case 2:
result.append("two ");
break;
case 1:
result.append("one ");
break;
case 0:
result.append("");
break;
}
}
public static String intToEnglish(int i) {
StringBuilder result = new StringBuilder();
longToEnglish(i, result);
return result.toString();
}
public static void intToEnglish(int i, StringBuilder result) {
longToEnglish(i, result);
}
}

View File

@ -1,207 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lucene.util;
import java.io.IOException;
import java.util.Collection;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Lock;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
/** A mock {@link Directory} impl that tracks open files. */
public class MockDirectoryWrapper extends Directory {
private final Directory delegate;
private final Multiset<String> openFiles;
public MockDirectoryWrapper(Directory delegate) {
this.delegate = delegate;
this.openFiles = HashMultiset.create();
}
@Override
public void close() throws IOException {
delegate.close();
if (!openFiles.isEmpty()) {
throw new IllegalStateException("There are still open files!!! " + openFiles);
}
}
@Override
public IndexOutput createOutput(String name, IOContext context) throws IOException {
// TODO Auto-generated method stub
return new MockIndexOutput(name, delegate.createOutput(name, context));
}
@Override
public void deleteFile(String name) throws IOException {
delegate.deleteFile(name);
}
@Override
public boolean fileExists(String name) throws IOException {
return delegate.fileExists(name);
}
@Override
public long fileLength(String name) throws IOException {
return delegate.fileLength(name);
}
@Override
public String[] listAll() throws IOException {
return delegate.listAll();
}
@Override
public Lock makeLock(String name) {
return delegate.makeLock(name);
}
@Override
public IndexInput openInput(String name, IOContext context) throws IOException {
return new MockIndexInput(name, delegate.openInput(name, context));
}
@Override
public void sync(Collection<String> files) throws IOException {
delegate.sync(files);
}
private class MockIndexInput extends IndexInput {
private final String name;
private final IndexInput delegate;
protected MockIndexInput(String name, IndexInput delegate) {
super(name);
this.name = name;
openFiles.add(name);
this.delegate = delegate;
}
@Override
public void close() throws IOException {
try {
delegate.close();
} finally {
openFiles.remove(name);
}
}
@Override
public long getFilePointer() {
return delegate.getFilePointer();
}
@Override
public long length() {
return delegate.length();
}
@Override
public void seek(long pointer) throws IOException {
delegate.seek(pointer);
}
@Override
public byte readByte() throws IOException {
return delegate.readByte();
}
@Override
public void readBytes(byte[] b, int o, int l) throws IOException {
delegate.readBytes(b, o, l);
}
@Override
public IndexInput clone() {
// Clones don't need to be closed, nothing to track
return delegate.clone();
}
}
private class MockIndexOutput extends IndexOutput {
private final String name;
private final IndexOutput delegate;
MockIndexOutput(String name, IndexOutput delegate) {
super();
this.name = name;
openFiles.add(name);
this.delegate = delegate;
}
@Override
public void close() throws IOException {
try {
delegate.close();
} finally {
openFiles.remove(name);
}
}
@Override
public void flush() throws IOException {
delegate.flush();
}
@Override
public long getFilePointer() {
return delegate.getFilePointer();
}
@Override
public long length() throws IOException {
return delegate.length();
}
@Override
@Deprecated
public void seek(long pointer) throws IOException {
delegate.seek(pointer);
}
@Override
public void writeByte(byte b) throws IOException {
delegate.writeByte(b);
}
@Override
public void writeBytes(byte[] b, int o, int l) throws IOException {
delegate.writeBytes(b, o, l);
}
}
@Override
public String toString() {
return "MockDirectoryWrapper[" + delegate + "]";
}
}

View File

@ -0,0 +1,61 @@
package org.elasticsearch.junit.listerners;
import com.carrotsearch.randomizedtesting.RandomizedContext;
import com.carrotsearch.randomizedtesting.ReproduceErrorMessageBuilder;
import com.carrotsearch.randomizedtesting.TraceFormatting;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
/**
* A {@link RunListener} that emits to {@link System#err} a string with command
* line parameters allowing quick test re-run under ANT command line.
*/
public class ReproduceInfoPrinter extends RunListener {
@Override
public void testFailure(Failure failure) throws Exception {
// Ignore assumptions.
if (failure.getException() instanceof AssumptionViolatedException) {
return;
}
final Description d = failure.getDescription();
final StringBuilder b = new StringBuilder();
b.append("FAILURE : ").append(d.getDisplayName()).append("\n");
b.append("REPRODUCE WITH : mvn test");
new MavenMessageBuilder(b).appendAllOpts(failure.getDescription());
b.append("\n");
b.append("Throwable:\n");
if (failure.getException() != null) {
TraceFormatting traces = new TraceFormatting();
try {
traces = RandomizedContext.current().getRunner().getTraceFormatting();
} catch (IllegalStateException e) {
// Ignore if no context.
}
traces.formatThrowable(b, failure.getException());
}
System.out.println(b.toString());
}
private static class MavenMessageBuilder extends ReproduceErrorMessageBuilder {
public MavenMessageBuilder(StringBuilder b) {
super(b);
}
/**
* Append a single VM option.
*/
public ReproduceErrorMessageBuilder appendOpt(String sysPropName, String value) {
if (sysPropName.equals("tests.iters")) { // we don't want the iters to be in there!
return this;
}
return super.appendOpt(sysPropName, value);
}
}
}

View File

@ -1,76 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
/**
*/
public class TestNGLoggingListener implements ITestListener {
private ESLogger logger = ESLoggerFactory.getLogger("test");
private String extractTestName(ITestResult result) {
String testName = result.getInstanceName();
if (testName.startsWith("org.elasticsearch.")) {
testName = testName.substring("org.elasticsearch.".length());
}
if (testName.startsWith("test.")) {
testName = testName.substring("test.".length());
}
return testName + "#" + result.getName();
}
@Override
public void onTestStart(ITestResult result) {
logger.info("==> Test Starting [{}]", extractTestName(result));
}
@Override
public void onTestSuccess(ITestResult result) {
logger.info("==> Test Success [{}]", extractTestName(result));
}
@Override
public void onTestFailure(ITestResult result) {
logger.error("==> Test Failure [{}]", extractTestName(result));
}
@Override
public void onTestSkipped(ITestResult result) {
logger.info("==> Test Skipped [{}]", extractTestName(result));
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}
@Override
public void onStart(ITestContext context) {
}
@Override
public void onFinish(ITestContext context) {
}
}

View File

@ -29,32 +29,28 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.node.Node;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import java.util.Map;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
@Ignore
public abstract class AbstractNodesTests extends ElasticsearchTestCase {
private static Map<String, Node> nodes = newHashMap();
private Map<String, Node> nodes = newHashMap();
private Map<String, Client> clients = newHashMap();
private Settings defaultSettings = ImmutableSettings
private static Map<String, Client> clients = newHashMap();
private static final Settings defaultSettings = ImmutableSettings
.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "CHILD_VM=[" + CHILD_VM_ID +"]")
.build();
public void putDefaultSettings(Settings.Builder settings) {
putDefaultSettings(settings.build());
}
public void putDefaultSettings(Settings settings) {
defaultSettings = ImmutableSettings.settingsBuilder().put(defaultSettings).put(settings).build();
}
public Node startNode(String id) {
return buildNode(id).start();
@ -77,59 +73,87 @@ public abstract class AbstractNodesTests extends ElasticsearchTestCase {
}
public Node buildNode(String id, Settings settings) {
String settingsSource = getClass().getName().replace('.', '/') + ".yml";
Settings finalSettings = settingsBuilder()
.loadFromClasspath(settingsSource)
.put(defaultSettings)
.put(settings)
.put("name", id)
.build();
if (finalSettings.get("gateway.type") == null) {
// default to non gateway
finalSettings = settingsBuilder().put(finalSettings).put("gateway.type", "none").build();
synchronized (AbstractNodesTests.class) {
if (nodes.containsKey(id)) {
throw new IllegalArgumentException("Node with id ["+ id + "] already exists");
}
assert !nodes.containsKey(id);
assert !clients.containsKey(id);
String settingsSource = getClass().getName().replace('.', '/') + ".yml";
Settings finalSettings = settingsBuilder()
.loadFromClasspath(settingsSource)
.put(defaultSettings)
.put(getClassDefaultSettings())
.put(settings)
.put("name", id)
.build();
if (finalSettings.get("gateway.type") == null) {
// default to non gateway
finalSettings = settingsBuilder().put(finalSettings).put("gateway.type", "none").build();
}
if (finalSettings.get("cluster.routing.schedule") != null) {
// decrease the routing schedule so new nodes will be added quickly
finalSettings = settingsBuilder().put(finalSettings).put("cluster.routing.schedule", "50ms").build();
}
Node node = nodeBuilder()
.settings(finalSettings)
.build();
nodes.put(id, node);
clients.put(id, node.client());
return node;
}
if (finalSettings.get("cluster.routing.schedule") != null) {
// decrease the routing schedule so new nodes will be added quickly
finalSettings = settingsBuilder().put(finalSettings).put("cluster.routing.schedule", "50ms").build();
}
Node node = nodeBuilder()
.settings(finalSettings)
.build();
nodes.put(id, node);
clients.put(id, node.client());
return node;
}
public void closeNode(String id) {
Client client = clients.remove(id);
Client client;
Node node;
synchronized (AbstractNodesTests.class) {
client = clients.remove(id);
node = nodes.remove(id);
}
if (client != null) {
client.close();
}
Node node = nodes.remove(id);
if (node != null) {
node.close();
}
}
public Node node(String id) {
return nodes.get(id);
synchronized (AbstractNodesTests.class) {
return nodes.get(id);
}
}
public Client client(String id) {
return clients.get(id);
synchronized (AbstractNodesTests.class) {
return clients.get(id);
}
}
public void closeAllNodes() {
for (Client client : clients.values()) {
client.close();
closeAllNodes(false);
}
public void closeAllNodes(boolean preventRelocation) {
synchronized (AbstractNodesTests.class) {
if (preventRelocation) {
Settings build = ImmutableSettings.builder().put("cluster.routing.allocation.disable_allocation", true).build();
Client aClient = client();
if (aClient != null) {
aClient.admin().cluster().prepareUpdateSettings().setTransientSettings(build).execute().actionGet();
}
}
for (Client client : clients.values()) {
client.close();
}
clients.clear();
for (Node node : nodes.values()) {
node.close();
}
nodes.clear();
}
clients.clear();
for (Node node : nodes.values()) {
node.close();
}
nodes.clear();
}
public ImmutableSet<ClusterBlock> waitForNoBlocks(TimeValue timeout, String node) throws InterruptedException {
@ -156,4 +180,49 @@ public abstract class AbstractNodesTests extends ElasticsearchTestCase {
// ignore
}
}
private static volatile AbstractNodesTests testInstance; // this test class only works once per JVM
@BeforeClass
public static void tearDownOnce() throws Exception {
synchronized (AbstractNodesTests.class) {
if (testInstance != null) {
testInstance.afterClass();
testInstance.closeAllNodes();
testInstance = null;
}
}
}
@Before
public final void setUp() throws Exception {
synchronized (AbstractNodesTests.class) {
if (testInstance == null) {
testInstance = this;
testInstance.beforeClass();
} else {
assert testInstance.getClass() == this.getClass();
}
}
}
public Client client() {
synchronized (AbstractNodesTests.class) {
if (clients.isEmpty()) {
return null;
}
return clients.values().iterator().next();
}
}
protected void afterClass() throws Exception {
}
protected Settings getClassDefaultSettings() {
return ImmutableSettings.EMPTY;
}
protected void beforeClass() throws Exception {
}
}

View File

@ -50,10 +50,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndexTemplateMissingException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.junit.*;
import java.io.IOException;
import java.util.HashSet;
@ -62,7 +59,6 @@ import java.util.Set;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -84,23 +80,24 @@ import static org.hamcrest.Matchers.equalTo;
* baseclass. If your test modifies the cluster state with persistent or
* transient settings the baseclass will raise and error.
*/
@Ignore
public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
private static TestCluster cluster;
@BeforeClass
protected static void beforeClass() throws Exception {
public static void beforeClass() throws Exception {
cluster();
}
@BeforeMethod
@Before
public final void before() {
cluster.ensureAtLeastNumNodes(numberOfNodes());
wipeIndices();
wipeTemplates();
}
@AfterMethod
@After
public void after() {
MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().getMetaData();
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(), metaData
@ -111,7 +108,7 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
public static TestCluster cluster() {
if (cluster == null) {
cluster = ClusterManager.accquireCluster();
cluster = ClusterManager.accquireCluster(getRandom());
}
return cluster;
}
@ -121,7 +118,7 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
}
@AfterClass
protected static void afterClass() {
public static void afterClass() {
cluster = null;
ClusterManager.releaseCluster();
}

View File

@ -18,16 +18,18 @@
*/
package org.elasticsearch.test.integration;
import java.util.Random;
public class ClusterManager {
private static TestCluster cluster;
public synchronized static TestCluster accquireCluster() {
public synchronized static TestCluster accquireCluster(Random random) {
if (cluster == null) {
cluster = new TestCluster();
cluster = new TestCluster(random);
}
cluster.reset();
cluster.reset(random);
return cluster;
}

View File

@ -18,13 +18,46 @@
*/
package org.elasticsearch.test.integration;
import com.carrotsearch.randomizedtesting.JUnit4MethodProvider;
import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.ThreadFilter;
import com.carrotsearch.randomizedtesting.annotations.*;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.util.LuceneJUnit3MethodProvider;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.Version;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
public class ElasticsearchTestCase {
import org.elasticsearch.junit.listerners.ReproduceInfoPrinter;
import org.junit.runner.RunWith;
@TestMethodProviders({
LuceneJUnit3MethodProvider.class,
JUnit4MethodProvider.class
})
@Listeners({
ReproduceInfoPrinter.class
})
@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchTestCase.ElasticSearchThreadFilter.class})
@ThreadLeakScope(Scope.NONE)
@RunWith(value = com.carrotsearch.randomizedtesting.RandomizedRunner.class)
public class ElasticsearchTestCase extends RandomizedTest {
public static final Version TEST_VERSION_CURRENT = LuceneTestCase.TEST_VERSION_CURRENT;
protected final ESLogger logger = Loggers.getLogger(getClass());
public static final boolean NIGHLY = Boolean.parseBoolean(System.getProperty("es.tests.nighly", "false")); // disabled by default
public static final String CHILD_VM_ID = System.getProperty("junit4.childvm.id", "" + System.currentTimeMillis());
public static final String SYSPROP_BADAPPLES = "tests.badapples";
public static class ElasticSearchThreadFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
return true;
}
}
}

View File

@ -49,8 +49,8 @@ import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
public class TestCluster {
@ -71,16 +71,21 @@ public class TestCluster {
private final Settings defaultSettings;
private ClientFactory clientFactory = new RandomClientFactory();
private NodeAndClient clientNode;
public TestCluster() {
this("simple-test-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "_" + System.currentTimeMillis(), ImmutableSettings.settingsBuilder().build());
private Random random;
private ClientFactory clientFactory;
public TestCluster(Random random) {
this(random, "shared-test-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "CHILD_VM=[" + ElasticsearchTestCase.CHILD_VM_ID + "]"+ "_" + System.currentTimeMillis(), ImmutableSettings.settingsBuilder().build());
}
private TestCluster(String clusterName, Settings defaultSettings) {
private TestCluster(Random random, String clusterName, Settings defaultSettings) {
this.random = new Random(random.nextLong());
clientFactory = new RandomClientFactory(random);
this.clusterName = clusterName;
if (defaultSettings.get("gateway.type") == null) {
// default to non gateway
@ -273,7 +278,11 @@ public class TestCluster {
}
public static class RandomClientFactory extends ClientFactory {
private final Random random = new Random(0);
private final Random random;
public RandomClientFactory(Random random) {
this.random = random;
}
@Override
public Client client(Node node, String clusterName) {
@ -288,8 +297,9 @@ public class TestCluster {
}
}
void reset() {
this.clientFactory = new RandomClientFactory();
void reset(Random random) {
this.random = new Random(random.nextLong());
this.clientFactory = new RandomClientFactory(this.random);
}
public ClusterService clusterService() {

View File

@ -44,8 +44,8 @@ import org.elasticsearch.search.facet.FacetBuilders;
import org.elasticsearch.search.facet.terms.TermsFacet;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Assert;
import org.junit.Test;
import java.util.Set;
import java.util.concurrent.ExecutorService;
@ -56,22 +56,13 @@ import static com.google.common.collect.Sets.newHashSet;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.index.query.FilterBuilders.termFilter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
/**
*
*/
@Test
public class IndexAliasesTests extends AbstractSharedClusterTest {
@BeforeClass
public void createNodes() throws Exception {
cluster().ensureAtLeastNumNodes(2);
}
@Test
public void testAliases() throws Exception {
// delete all indices
@ -788,7 +779,7 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
try {
client().admin().indices().prepareGetAliases("foo").addIndices("foobar").execute().actionGet();
fail("Exception should have been thrown");
Assert.fail("Exception should have been thrown");
} catch (AliasMissingException e) {
assertThat(e.getMessage(), equalTo("alias [foo] missing"));
}
@ -797,28 +788,28 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
assertThat(existsResponse.exists(), equalTo(false));
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testAddAliasNullIndex() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, "alias1"))
.execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testAddAliasEmptyIndex() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("", "alias1"))
.execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testAddAliasNullAlias() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("index1", null))
.execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testAddAliasEmptyAlias() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction("index1", ""))
@ -849,25 +840,25 @@ public class IndexAliasesTests extends AbstractSharedClusterTest {
}
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasNullIndex() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction(null, "alias1"))
.execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasEmptyIndex() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("", "alias1"))
.execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasNullAlias() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("index1", null))
.execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void tesRemoveAliasEmptyAlias() {
client().admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction("index1", ""))
.execute().actionGet();

View File

@ -33,8 +33,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.util.HashMap;
@ -42,14 +42,13 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
@Test
public class SimpleBlocksTests extends AbstractNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}
@Test
public void verifyIndexAndClusterReadOnly() throws Exception {
Node node1 = startNode("node1");

View File

@ -19,6 +19,7 @@
package org.elasticsearch.test.integration.broadcast;
import com.google.common.base.Charsets;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
@ -29,10 +30,7 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import com.beust.jcommander.Strings;
import com.google.common.base.Charsets;
import org.junit.Test;
import java.io.IOException;

View File

@ -23,7 +23,8 @@ import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.junit.After;
import org.junit.Ignore;
import static org.elasticsearch.client.Requests.createIndexRequest;
@ -34,7 +35,7 @@ public class DiscoveryTransportClientTests extends AbstractNodesTests {
private TransportClient client;
@AfterMethod
@After
public void closeServers() {
if (client != null) {
client.close();
@ -43,7 +44,7 @@ public class DiscoveryTransportClientTests extends AbstractNodesTests {
}
/*@Test*/
@Ignore("fails for some reason?")
public void testWithDiscovery() throws Exception {
startNode("server1");
client = new TransportClient(ImmutableSettings.settingsBuilder()

View File

@ -21,7 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.test.integration.TestCluster;
import org.elasticsearch.test.integration.document.DocumentActionsTests;
import org.testng.annotations.BeforeClass;
import org.junit.BeforeClass;
/**
*

View File

@ -21,7 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.test.integration.TestCluster;
import org.elasticsearch.test.integration.document.DocumentActionsTests;
import org.testng.annotations.BeforeClass;
import org.junit.BeforeClass;
/**
*

View File

@ -19,8 +19,8 @@
package org.elasticsearch.test.integration.cluster;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.BeforeClass;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ -29,10 +29,12 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
*/
public class AbstractZenNodesTests extends AbstractNodesTests {
@BeforeClass
public void setUpZenDiscoSettings() {
@Override
protected final Settings getClassDefaultSettings() {
// we force zen discovery here since it has specific handling for specific master / data nodes
// and disconnections
putDefaultSettings(settingsBuilder().put("discovery.type", "zen"));
return settingsBuilder().put("discovery.type", "zen").build();
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

View File

@ -35,8 +35,8 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.threadpool.ThreadPool;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.util.*;
import java.util.concurrent.CountDownLatch;
@ -44,16 +44,14 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.Assert.assertTrue;
/**
*
*/
public class ClusterServiceTests extends AbstractZenNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}
@ -143,16 +141,12 @@ public class ClusterServiceTests extends AbstractZenNodesTests {
}
});
invoked1.await();
final CountDownLatch invoked2 = new CountDownLatch(8);
for (int i = 2; i <= 10; i++) {
clusterService.submitStateUpdateTask(Integer.toString(i), new ClusterStateUpdateTask() {
@Override
public ClusterState execute(ClusterState currentState) {
try {
block1.await();
} catch (InterruptedException e) {
assert false;
}
invoked2.countDown();
return currentState;
}
@ -180,6 +174,7 @@ public class ClusterServiceTests extends AbstractZenNodesTests {
}
assertTrue(controlSources.isEmpty());
block1.countDown();
invoked2.await();
pendingClusterTasks = clusterService.pendingTasks();
assertThat(pendingClusterTasks, empty());
@ -187,11 +182,11 @@ public class ClusterServiceTests extends AbstractZenNodesTests {
assertThat(response.pendingTasks(), empty());
final CountDownLatch block2 = new CountDownLatch(1);
final CountDownLatch invoked2 = new CountDownLatch(1);
final CountDownLatch invoked3 = new CountDownLatch(1);
clusterService.submitStateUpdateTask("1", new ClusterStateUpdateTask() {
@Override
public ClusterState execute(ClusterState currentState) {
invoked2.countDown();
invoked3.countDown();
try {
block2.await();
} catch (InterruptedException e) {
@ -202,21 +197,16 @@ public class ClusterServiceTests extends AbstractZenNodesTests {
@Override
public void onFailure(String source, Throwable t) {
invoked2.countDown();
invoked3.countDown();
assert false;
}
});
invoked2.await();
invoked3.await();
for (int i = 2; i <= 5; i++) {
clusterService.submitStateUpdateTask(Integer.toString(i), new ClusterStateUpdateTask() {
@Override
public ClusterState execute(ClusterState currentState) {
try {
block2.await();
} catch (InterruptedException e) {
assert false;
}
return currentState;
}
@ -276,8 +266,7 @@ public class ClusterServiceTests extends AbstractZenNodesTests {
assertThat(clusterService2.state().nodes().localNodeMaster(), is(false));
assertThat(testService2.master(), is(false));
node1.close();
closeNode("node1");
clusterHealth = node2.client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("1").execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));

View File

@ -32,8 +32,8 @@ import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.node.internal.InternalNode;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.util.LinkedList;
import java.util.Set;
@ -43,10 +43,9 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@Test
public class MinimumMasterNodesTests extends AbstractZenNodesTests {
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {

View File

@ -28,8 +28,8 @@ import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.node.Node;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -40,7 +40,7 @@ import static org.hamcrest.Matchers.greaterThan;
*/
public class NoMasterNodeTests extends AbstractNodesTests {
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
closeAllNodes();
}

View File

@ -24,8 +24,8 @@ import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.client.Requests.createIndexRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ -38,7 +38,7 @@ import static org.hamcrest.Matchers.equalTo;
*/
public class SimpleDataNodesTests extends AbstractNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -20,8 +20,8 @@
package org.elasticsearch.test.integration.cluster;
import org.elasticsearch.discovery.MasterNotDiscoveredException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -33,7 +33,7 @@ import static org.hamcrest.Matchers.nullValue;
*/
public class SpecificMasterNodesTests extends AbstractZenNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -23,8 +23,8 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -34,7 +34,7 @@ import static org.hamcrest.Matchers.equalTo;
*/
public class UpdateSettingsValidationTests extends AbstractNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -31,20 +31,19 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*/
@Test
public class AwarenessAllocationTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(AwarenessAllocationTests.class);
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
closeAllNodes();
}

View File

@ -36,8 +36,8 @@ import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.io.File;
@ -47,12 +47,11 @@ import static org.hamcrest.Matchers.equalTo;
/**
*/
@Test
public class ClusterRerouteTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(ClusterRerouteTests.class);
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {
@ -200,4 +199,5 @@ public class ClusterRerouteTests extends AbstractNodesTests {
assertThat(state.routingNodes().node(state.nodes().resolveNode("node1").id()).shards().get(0).state(), equalTo(ShardRoutingState.STARTED));
}
}

View File

@ -30,8 +30,8 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -43,7 +43,7 @@ public class FilteringAllocationTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(FilteringAllocationTests.class);
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
closeAllNodes();
}

View File

@ -19,10 +19,6 @@ package org.elasticsearch.test.integration.cluster.allocation;
* under the License.
*/
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
import org.elasticsearch.cluster.routing.allocation.allocator.EvenShardsCountAllocator;
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
@ -32,13 +28,14 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.Matchers.instanceOf;
@Test
public class ShardsAllocatorModuleTests extends AbstractNodesTests {
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
closeAllNodes();
}
@ -51,7 +48,6 @@ public class ShardsAllocatorModuleTests extends AbstractNodesTests {
Settings build = settingsBuilder().put(ShardsAllocatorModule.TYPE_KEY, ShardsAllocatorModule.EVEN_SHARD_COUNT_ALLOCATOR_KEY)
.build();
assertAllocatorInstance(build, EvenShardsCountAllocator.class);
build = settingsBuilder().put(ShardsAllocatorModule.TYPE_KEY, ShardsAllocatorModule.BALANCED_ALLOCATOR_KEY).build();
assertAllocatorInstance(build, BalancedShardsAllocator.class);
}
@ -66,6 +62,7 @@ public class ShardsAllocatorModuleTests extends AbstractNodesTests {
}
private void assertAllocatorInstance(Settings settings, Class<? extends ShardsAllocator> clazz) {
closeNode("node");
Node _node = startNode("node", settings);
InternalNode node = (InternalNode) _node;
ShardsAllocator instance = node.injector().getInstance(ShardsAllocator.class);

View File

@ -29,7 +29,7 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.routing.RoutingNode;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
public class SimpleAllocationTests extends AbstractSharedClusterTest {

View File

@ -24,9 +24,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasAction;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -35,35 +33,27 @@ import static org.hamcrest.Matchers.equalTo;
/**
*/
public class ClusterSearchShardsTests extends AbstractNodesTests {
private Client client;
@BeforeClass
public void createNodes() throws Exception {
@Override
protected void beforeClass() throws Exception {
startNode("node1", settingsBuilder().put("node.tag", "A"));
startNode("node2", settingsBuilder().put("node.tag", "B"));
client = getClient();
}
@AfterClass
public void closeNodes() {
client.close();
closeAllNodes();
}
protected Client getClient() {
public Client client() {
return client("node1");
}
@Test
public void testSingleShardAllocation() throws Exception {
try {
client.admin().indices().prepareDelete("test").execute().actionGet();
client().admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder()
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder()
.put("index.number_of_shards", "1").put("index.number_of_replicas", 0).put("index.routing.allocation.include.tag", "A")).execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterSearchShardsResponse response = client("node1").admin().cluster().prepareSearchShards("test").execute().actionGet();
assertThat(response.getGroups().length, equalTo(1));
@ -86,13 +76,13 @@ public class ClusterSearchShardsTests extends AbstractNodesTests {
@Test
public void testMultipleShardsSingleNodeAllocation() throws Exception {
try {
client.admin().indices().prepareDelete("test").execute().actionGet();
client().admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder()
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder()
.put("index.number_of_shards", "4").put("index.number_of_replicas", 0).put("index.routing.allocation.include.tag", "A")).execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterSearchShardsResponse response = client("node1").admin().cluster().prepareSearchShards("test").execute().actionGet();
assertThat(response.getGroups().length, equalTo(4));
@ -111,26 +101,26 @@ public class ClusterSearchShardsTests extends AbstractNodesTests {
@Test
public void testMultipleIndicesAllocation() throws Exception {
try {
client.admin().indices().prepareDelete("test1").execute().actionGet();
client().admin().indices().prepareDelete("test1").execute().actionGet();
} catch (Exception e) {
// ignore
}
try {
client.admin().indices().prepareDelete("test2").execute().actionGet();
client().admin().indices().prepareDelete("test2").execute().actionGet();
} catch (Exception e) {
// ignore
}
client.admin().indices().prepareCreate("test1").setSettings(settingsBuilder()
client().admin().indices().prepareCreate("test1").setSettings(settingsBuilder()
.put("index.number_of_shards", "4").put("index.number_of_replicas", 1)).execute().actionGet();
client.admin().indices().prepareCreate("test2").setSettings(settingsBuilder()
client().admin().indices().prepareCreate("test2").setSettings(settingsBuilder()
.put("index.number_of_shards", "4").put("index.number_of_replicas", 1)).execute().actionGet();
client.admin().indices().prepareAliases()
client().admin().indices().prepareAliases()
.addAliasAction(AliasAction.newAddAliasAction("test1", "routing_alias").routing("ABC"))
.addAliasAction(AliasAction.newAddAliasAction("test2", "routing_alias").routing("EFG"))
.execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterSearchShardsResponse response = client.admin().cluster().prepareSearchShards("routing_alias").execute().actionGet();
ClusterSearchShardsResponse response = client().admin().cluster().prepareSearchShards("routing_alias").execute().actionGet();
assertThat(response.getGroups().length, equalTo(2));
assertThat(response.getGroups()[0].getShards().length, equalTo(2));
assertThat(response.getGroups()[1].getShards().length, equalTo(2));

View File

@ -25,12 +25,12 @@ import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.testng.Assert.assertTrue;
/**
*/
@ -61,7 +61,7 @@ public class CodecTests extends AbstractSharedClusterTest {
try {
client().prepareSearch().setQuery(QueryBuilders.matchQuery("field1", "quick brown").type(MatchQueryBuilder.Type.PHRASE).slop(0)).execute().actionGet();
} catch (SearchPhaseExecutionException e) {
assertTrue(e.getMessage().endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }"));
assertThat(e.getMessage(), endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }"));
}
}
@ -88,7 +88,7 @@ public class CodecTests extends AbstractSharedClusterTest {
try {
client().prepareSearch().setQuery(QueryBuilders.matchQuery("field1", "quick brown").type(MatchQueryBuilder.Type.PHRASE).slop(0)).execute().actionGet();
} catch (SearchPhaseExecutionException e) {
assertTrue(e.getMessage().endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }"));
assertThat(e.getMessage(), endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }"));
}
}

View File

@ -26,11 +26,10 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**

View File

@ -27,18 +27,18 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.testng.Assert.fail;
public class DeleteByQueryTests extends AbstractSharedClusterTest {
@BeforeMethod
@Before
public void createNodes() throws Exception {
cluster().ensureAtLeastNumNodes(2);
}
@ -92,7 +92,7 @@ public class DeleteByQueryTests extends AbstractSharedClusterTest {
try {
DeleteByQueryResponse actionGet = deleteByQueryRequestBuilder.execute().actionGet();
fail("Exception should have been thrown.");
Assert.fail("Exception should have been thrown.");
} catch (IndexMissingException e) {
}

View File

@ -23,20 +23,13 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@Test
public class DiscoveryTests extends AbstractNodesTests {
@AfterClass
public void closeNodes() {
closeAllNodes();
}
@Test
public void testUnicastDiscovery() {
Settings settings = ImmutableSettings.settingsBuilder()

View File

@ -10,13 +10,13 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
*/

View File

@ -51,8 +51,8 @@ import org.elasticsearch.action.support.replication.ReplicationType;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.common.base.Charsets;

View File

@ -25,14 +25,14 @@ import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.testng.Assert.*;
import static org.junit.Assert.*;
/**
*/

View File

@ -22,7 +22,7 @@ package org.elasticsearch.test.integration.flt;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisFieldQuery;
@ -30,7 +30,7 @@ import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.testng.Assert.fail;
import static org.junit.Assert.fail;
/**
*

View File

@ -1,27 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration.gateway.fs;
/**
*
*/
public class BlobStoreSmallBufferSizeFsIndexGatewayTests extends AbstractSimpleIndexGatewayTests {
}

View File

@ -1,10 +0,0 @@
cluster:
routing:
schedule: 100ms
gateway:
type: fs
fs:
buffer_size: 1kb
index:
number_of_shards: 1
number_of_replicas: 1

View File

@ -1,27 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration.gateway.fs;
/**
*
*/
public class ChunkFsIndexGatewayTests extends AbstractSimpleIndexGatewayTests {
}

View File

@ -1,10 +0,0 @@
cluster:
routing:
schedule: 100ms
gateway:
type: fs
fs:
chunk_size: 11k
index:
number_of_shards: 1
number_of_replicas: 1

View File

@ -1,81 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration.gateway.fs;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.client.Requests.createIndexRequest;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class FsMetaDataGatewayTests extends AbstractNodesTests {
@AfterMethod
void closeNodes() throws Exception {
node("server1").stop();
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
closeAllNodes();
}
@BeforeMethod
void buildNodeToReset() throws Exception {
buildNode("server1");
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
closeAllNodes();
}
@Test
public void testIndexActions() throws Exception {
startNode("server1");
logger.info("Running Cluster Health (waiting for node to startup properly)");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
closeNode("server1");
startNode("server1");
Thread.sleep(500);
try {
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
assert false : "index should exists";
} catch (IndexAlreadyExistsException e) {
// all is well
}
}
}

View File

@ -1,8 +0,0 @@
cluster:
routing:
schedule: 100ms
gateway:
type: fs
index:
number_of_shards: 5
number_of_replicas: 1

View File

@ -19,6 +19,8 @@
package org.elasticsearch.test.integration.gateway.fs;
import com.carrotsearch.randomizedtesting.annotations.Nightly;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
@ -30,25 +32,28 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*
*/
public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests {
public class IndexGatewayTests extends AbstractNodesTests {
@AfterMethod
@After
public void closeNodes() throws Exception {
node("server1").stop();
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
@ -56,17 +61,20 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
closeAllNodes();
}
@BeforeMethod
@Before
public void buildNode1() throws Exception {
buildNode("server1");
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well
((InternalNode) node("server1")).injector().getInstance(Gateway.class).reset();
closeAllNodes();
}
@Test
@Slow
public void testSnapshotOperations() throws Exception {
startNode("server1");
startNode("server1", getClassDefaultSettings());
// get the environment, so we can clear the work dir when needed
Environment environment = ((InternalNode) node("server1")).injector().getInstance(Environment.class);
@ -223,20 +231,20 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
}
@Test
@Nightly
public void testLoadWithFullRecovery() {
testLoad(true);
}
@Test
@Nightly
public void testLoadWithReuseRecovery() {
testLoad(false);
}
protected boolean isPersistentStorage() {
return true;
}
private void testLoad(boolean fullRecovery) {
logger.info("Running with fullRecover [{}]", fullRecovery);
startNode("server1");
logger.info("Running Cluster Health (waiting for node to startup properly)");
@ -324,4 +332,62 @@ public abstract class AbstractSimpleIndexGatewayTests extends AbstractNodesTests
private String source(String id, String nameValue) {
return "{ type1 : { \"id\" : \"" + id + "\", \"name\" : \"" + nameValue + "\" } }";
}
@Test
@Slow
public void testRandom() {
testLoad(getRandom().nextBoolean());
}
private String storeType;
@Override
protected final Settings getClassDefaultSettings() {
Builder builder = ImmutableSettings.builder();
builder.put("cluster.routing.schedule", "100ms");
builder.put("gateway.type", "fs");
if (between(0, 5) == 0) {
builder.put("gateway.fs.buffer_size", between(1, 100) + "kb");
}
if (between(0, 5) == 0) {
builder.put("gateway.fs.chunk_size", between(1, 100) + "kb");
}
builder.put("index.number_of_replicas", "1");
builder.put("index.number_of_shards", rarely() ? Integer.toString(between(2, 6)) : "1");
storeType = rarely() ? "ram" : "fs";
builder.put("index.store", storeType);
return builder.build();
}
protected boolean isPersistentStorage() {
return "fs".equals(storeType);
}
@Test
@Slow
public void testIndexActions() throws Exception {
startNode("server1");
logger.info("Running Cluster Health (waiting for node to startup properly)");
ClusterHealthResponse clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
closeNode("server1");
startNode("server1");
Thread.sleep(500);
try {
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
assert false : "index should exists";
} catch (IndexAlreadyExistsException e) {
// all is well
}
}
}

View File

@ -1,27 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration.gateway.fs;
/**
*
*/
public class SimpleFsIndexGatewayTests extends AbstractSimpleIndexGatewayTests {
}

View File

@ -1,8 +0,0 @@
cluster:
routing:
schedule: 100ms
gateway:
type: fs
index:
number_of_shards: 1
number_of_replicas: 1

View File

@ -1,31 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration.gateway.fs;
/**
*
*/
public class SimpleFsIndexInRamIndexGatewayTests extends AbstractSimpleIndexGatewayTests {
@Override
protected boolean isPersistentStorage() {
return false;
}
}

View File

@ -1,10 +0,0 @@
cluster:
routing:
schedule: 100ms
gateway:
type: fs
index:
number_of_shards: 1
number_of_replicas: 1
store:
type: ram

View File

@ -37,12 +37,11 @@ import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -52,8 +51,8 @@ import static org.hamcrest.Matchers.nullValue;
public class LocalGatewayIndexStateTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(LocalGatewayIndexStateTests.class);
@AfterMethod
//TODO Randomize this test - lots of tests are duplicates with settings that can be randomized
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.test.integration.gateway.local;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
@ -26,14 +27,13 @@ import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -41,7 +41,7 @@ import static org.hamcrest.Matchers.equalTo;
*/
public class QuorumLocalGatewayTests extends AbstractNodesTests {
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {
@ -54,6 +54,7 @@ public class QuorumLocalGatewayTests extends AbstractNodesTests {
}
@Test
@Slow
public void testChangeInitialShardsRecovery() throws Exception {
// clean three nodes
logger.info("--> cleaning nodes");
@ -111,6 +112,7 @@ public class QuorumLocalGatewayTests extends AbstractNodesTests {
}
@Test
@Slow
public void testQuorumRecovery() throws Exception {
// clean three nodes
logger.info("--> cleaning nodes");

View File

@ -19,8 +19,7 @@
package org.elasticsearch.test.integration.gateway.local;
import org.elasticsearch.action.count.CountResponse;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.status.IndexShardStatus;
@ -31,6 +30,7 @@ import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllo
import org.elasticsearch.cluster.routing.allocation.decider.DisableAllocationDecider;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.index.query.FilterBuilders;
@ -38,16 +38,15 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.*;
/**
@ -55,7 +54,7 @@ import static org.hamcrest.Matchers.*;
*/
public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {
@ -67,12 +66,18 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
closeAllNodes();
}
@Override
protected Settings getClassDefaultSettings() {
return settingsBuilder().put("gateway.type", "local").build();
}
@Test
@Slow
public void testX() throws Exception {
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
cleanAndCloseNodes();
Node node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).build());
Node node1 = startNode("node1", settingsBuilder().put("index.number_of_shards", 1).build());
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("appAccountIds").field("type", "string").endObject().endObject()
@ -99,7 +104,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
assertHitCount(node1.client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
closeNode("node1");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build());
node1 = startNode("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
ClusterHealthResponse clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
@ -108,31 +113,27 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
node1.client().admin().indices().prepareRefresh().execute().actionGet();
CountResponse count = node1.client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet();
assertNoFailures(count);
assertHitCount(count, 2);
assertHitCount(node1.client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
closeNode("node1");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build());
node1 = startNode("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
clusterHealth = node1.client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
node1.client().admin().indices().prepareRefresh().execute().actionGet();
count = node1.client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet();
assertNoFailures(count);
assertHitCount(count, 2);
assertHitCount(node1.client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
}
@Test
@Slow
public void testSingleNodeNoFlush() throws Exception {
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
cleanAndCloseNodes();
Node node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).build());
Node node1 = startNode("node1", settingsBuilder().put("index.number_of_shards", 1).build());
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("field").field("type", "string").endObject().startObject("num").field("type", "integer").endObject().endObject()
@ -153,7 +154,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
closeNode("node1");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build());
node1 = startNode("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
ClusterHealthResponse clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
@ -169,7 +170,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
closeNode("node1");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build());
node1 = startNode("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
@ -187,11 +188,12 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
@Test
@Slow
public void testSingleNodeWithFlush() throws Exception {
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
cleanAndCloseNodes();
Node node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).build());
Node node1 = startNode("node1", settingsBuilder().put("index.number_of_shards", 1).build());
node1.client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).execute().actionGet();
node1.client().admin().indices().prepareFlush().execute().actionGet();
node1.client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("field", "value2").endObject()).execute().actionGet();
@ -200,7 +202,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
assertHitCount(node1.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
closeNode("node1");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build());
node1 = startNode("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
ClusterHealthResponse clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
@ -213,7 +215,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
closeNode("node1");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build());
node1 = startNode("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
@ -227,14 +229,15 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
@Test
@Slow
public void testTwoNodeFirstNodeCleared() throws Exception {
// clean two nodes
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node2", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
buildNode("node2");
cleanAndCloseNodes();
Node node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).build());
Node node2 = startNode("node2", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).build());
Node node1 = startNode("node1", settingsBuilder().put("index.number_of_shards", 1).build());
Node node2 = startNode("node2", settingsBuilder().put("index.number_of_shards", 1).build());
node1.client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).execute().actionGet();
node1.client().admin().indices().prepareFlush().execute().actionGet();
@ -256,11 +259,11 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
closeNode("node2");
logger.info("--> cleaning node1 gateway");
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
cleanAndCloseNodes();
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("gateway.recover_after_nodes", 2).build());
node2 = startNode("node2", settingsBuilder().put("gateway.type", "local").put("gateway.recover_after_nodes", 2).build());
node1 = startNode("node1", settingsBuilder().put("gateway.recover_after_nodes", 2).build());
node2 = startNode("node2", settingsBuilder().put("gateway.recover_after_nodes", 2).build());
logger.info("Running Cluster Health (wait for the shards to startup)");
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForActiveShards(2)).actionGet();
@ -274,14 +277,15 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
@Test
@Slow
public void testLatestVersionLoaded() throws Exception {
// clean two nodes
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node2", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
buildNode("node2");
cleanAndCloseNodes();
Node node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).put("gateway.recover_after_nodes", 2).build());
Node node2 = startNode("node2", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).put("gateway.recover_after_nodes", 2).build());
Node node1 = startNode("node1", settingsBuilder().put("index.number_of_shards", 1).put("gateway.recover_after_nodes", 2).build());
Node node2 = startNode("node2", settingsBuilder().put("index.number_of_shards", 1).put("gateway.recover_after_nodes", 2).build());
node1.client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).execute().actionGet();
node1.client().admin().indices().prepareFlush().execute().actionGet();
@ -328,8 +332,8 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
logger.info("--> starting two nodes back, verifying we got the latest version");
node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("gateway.recover_after_nodes", 2).build());
node2 = startNode("node2", settingsBuilder().put("gateway.type", "local").put("gateway.recover_after_nodes", 2).build());
node1 = startNode("node1", settingsBuilder().put("gateway.recover_after_nodes", 2).build());
node2 = startNode("node2", settingsBuilder().put("gateway.recover_after_nodes", 2).build());
logger.info("--> running cluster_health (wait for the shards to startup)");
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForActiveShards(2)).actionGet();
@ -349,18 +353,19 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
@Test
@Slow
public void testReusePeerRecovery() throws Exception {
buildNode("node1", settingsBuilder().put("gateway.type", "local").build());
buildNode("node2", settingsBuilder().put("gateway.type", "local").build());
buildNode("node3", settingsBuilder().put("gateway.type", "local").build());
buildNode("node4", settingsBuilder().put("gateway.type", "local").build());
buildNode("node1");
buildNode("node2");
buildNode("node3");
buildNode("node4");
cleanAndCloseNodes();
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder()
.put("action.admin.cluster.node.shutdown.delay", "10ms")
.put("gateway.recover_after_nodes", 4)
.put("gateway.type", "local")
.put(BalancedShardsAllocator.SETTING_THRESHOLD, 1.1f); // use less agressive settings
startNode("node1", settings);
@ -433,17 +438,18 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
@Test
@Slow
public void testRecoveryDifferentNodeOrderStartup() throws Exception {
// we need different data paths so we make sure we start the second node fresh
buildNode("node1", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data1").build());
buildNode("node2", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data2").build());
buildNode("node1", settingsBuilder().put("path.data", "data/data1").build());
buildNode("node2", settingsBuilder().put("path.data", "data/data2").build());
cleanAndCloseNodes();
startNode("node1", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data1").build());
startNode("node1", settingsBuilder().put("path.data", "data/data1").build());
client("node1").prepareIndex("test", "type1", "1").setSource("field", "value").execute().actionGet();
startNode("node2", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data2").build());
startNode("node2", settingsBuilder().put("path.data", "data/data2").build());
ClusterHealthResponse health = client("node2").admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(health.isTimedOut(), equalTo(false));
@ -451,7 +457,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
closeNode("node1");
closeNode("node2");
startNode("node2", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data2").build());
startNode("node2", settingsBuilder().put("path.data", "data/data2").build());
health = client("node2").admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
assertThat(health.isTimedOut(), equalTo(false));

View File

@ -23,8 +23,8 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -38,7 +38,7 @@ public class RecoverAfterNodesTests extends AbstractNodesTests {
private final static TimeValue BLOCK_WAIT_TIMEOUT = TimeValue.timeValueSeconds(1);
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -32,11 +32,10 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class GetActionTests extends AbstractSharedClusterTest {
@ -66,7 +65,7 @@ public class GetActionTests extends AbstractSharedClusterTest {
response = client().prepareGet("test", "type1", "1").setFields(Strings.EMPTY_ARRAY).execute().actionGet();
assertThat(response.isExists(), equalTo(true));
assertThat(response.getSourceAsBytes(), nullValue());
logger.info("--> realtime get 1 (no type)");
response = client().prepareGet("test", null, "1").execute().actionGet();
assertThat(response.isExists(), equalTo(true));

View File

@ -23,7 +23,7 @@ import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
@ -33,11 +33,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicIntegerArray;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
*
@ -87,7 +84,7 @@ public class IndexActionTests extends AbstractSharedClusterTest {
final AtomicIntegerArray createdCounts = new AtomicIntegerArray(docCount);
ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
List<Callable<Void>> tasks = new ArrayList<Callable<Void>>(taskCount);
final Random random = new Random();
final Random random = getRandom();
for (int i=0;i< taskCount; i++ ) {
tasks.add(new Callable<Void>() {
@Override

View File

@ -32,15 +32,14 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
@ -51,7 +50,7 @@ public class IndexLifecycleActionTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(IndexLifecycleActionTests.class);
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -27,11 +27,11 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.Assert.fail;
import static org.junit.Assert.fail;
public class IgnoreIndicesTests extends AbstractSharedClusterTest {

View File

@ -19,11 +19,6 @@
package org.elasticsearch.test.integration.indices.analyze;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import java.io.IOException;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder;
@ -31,8 +26,12 @@ import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*

View File

@ -28,8 +28,8 @@ import org.elasticsearch.indices.analysis.HunspellService;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@ -41,7 +41,7 @@ import static org.hamcrest.Matchers.notNullValue;
public class HunspellServiceTests extends AbstractNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -28,9 +28,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.index.query.QueryBuilders.filteredQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
@ -39,151 +37,144 @@ import static org.hamcrest.Matchers.*;
/**
*/
@Test
public class CacheTests extends AbstractNodesTests {
private Client client;
@BeforeClass
public void createNodes() throws Exception {
@Override
protected void beforeClass() throws Exception {
// Filter cache is cleaned periodically, default is 60s, so make sure it runs often. Thread.sleep for 60s is bad
startNode("node1", ImmutableSettings.settingsBuilder().put("indices.cache.filter.clean_interval", "1ms"));
client = getClient();
}
@AfterClass
public void closeNodes() {
client.close();
closeAllNodes();
}
protected Client getClient() {
@Override
public Client client() {
return client("node1");
}
@Test
public void testClearCacheFilterKeys() {
client.admin().indices().prepareDelete().execute().actionGet();
client.admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
client.prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
NodesStatsResponse nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
IndicesStatsResponse indicesStats = client.admin().indices().prepareStats("test").clear().setFilterCache(true).execute().actionGet();
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats("test").clear().setFilterCache(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
SearchResponse searchResponse = client.prepareSearch().setQuery(filteredQuery(matchAllQuery(), FilterBuilders.termFilter("field", "value").cacheKey("test_key"))).execute().actionGet();
SearchResponse searchResponse = client().prepareSearch().setQuery(filteredQuery(matchAllQuery(), FilterBuilders.termFilter("field", "value").cacheKey("test_key"))).execute().actionGet();
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFilterCache().getMemorySizeInBytes(), greaterThan(0l));
indicesStats = client.admin().indices().prepareStats("test").clear().setFilterCache(true).execute().actionGet();
indicesStats = client().admin().indices().prepareStats("test").clear().setFilterCache(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFilterCache().getMemorySizeInBytes(), greaterThan(0l));
client.admin().indices().prepareClearCache().setFilterKeys("test_key").execute().actionGet();
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
client().admin().indices().prepareClearCache().setFilterKeys("test_key").execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
indicesStats = client.admin().indices().prepareStats("test").clear().setFilterCache(true).execute().actionGet();
indicesStats = client().admin().indices().prepareStats("test").clear().setFilterCache(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
}
@Test
public void testFieldDataStats() {
client.admin().indices().prepareDelete().execute().actionGet();
client.admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
client.prepareIndex("test", "type", "1").setSource("field", "value1", "field2", "value1").execute().actionGet();
client.prepareIndex("test", "type", "2").setSource("field", "value2", "field2", "value2").execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
client().prepareIndex("test", "type", "1").setSource("field", "value1", "field2", "value1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "value2", "field2", "value2").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
NodesStatsResponse nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0l));
IndicesStatsResponse indicesStats = client.admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0l));
// sort to load it to field data...
client.prepareSearch().addSort("field", SortOrder.ASC).execute().actionGet();
client.prepareSearch().addSort("field", SortOrder.ASC).execute().actionGet();
client().prepareSearch().addSort("field", SortOrder.ASC).execute().actionGet();
client().prepareSearch().addSort("field", SortOrder.ASC).execute().actionGet();
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), greaterThan(0l));
indicesStats = client.admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), greaterThan(0l));
// sort to load it to field data...
client.prepareSearch().addSort("field2", SortOrder.ASC).execute().actionGet();
client.prepareSearch().addSort("field2", SortOrder.ASC).execute().actionGet();
client().prepareSearch().addSort("field2", SortOrder.ASC).execute().actionGet();
client().prepareSearch().addSort("field2", SortOrder.ASC).execute().actionGet();
// now check the per field stats
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(new CommonStatsFlags().set(CommonStatsFlags.Flag.FieldData, true).fieldDataFields("*")).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(new CommonStatsFlags().set(CommonStatsFlags.Flag.FieldData, true).fieldDataFields("*")).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), greaterThan(0l));
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getFields().get("field"), greaterThan(0l));
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getFields().get("field"), lessThan(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes()));
indicesStats = client.admin().indices().prepareStats("test").clear().setFieldData(true).setFieldDataFields("*").execute().actionGet();
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).setFieldDataFields("*").execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), greaterThan(0l));
assertThat(indicesStats.getTotal().getFieldData().getFields().get("field"), greaterThan(0l));
assertThat(indicesStats.getTotal().getFieldData().getFields().get("field"), lessThan(indicesStats.getTotal().getFieldData().getMemorySizeInBytes()));
client.admin().indices().prepareClearCache().setFieldDataCache(true).execute().actionGet();
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
client().admin().indices().prepareClearCache().setFieldDataCache(true).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0l));
indicesStats = client.admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0l));
}
@Test
public void testClearAllCaches() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();
client.admin().indices().prepareCreate("test")
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test")
.setSettings(ImmutableSettings.settingsBuilder()
.put("index.number_of_replicas", 0)
.put("index.number_of_shards", 1))
.execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
client.prepareIndex("test", "type", "1").setSource("field", "value1").execute().actionGet();
client.prepareIndex("test", "type", "2").setSource("field", "value2").execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
client().prepareIndex("test", "type", "1").setSource("field", "value1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "value2").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
NodesStatsResponse nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true)
NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true)
.execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0l));
assertThat(nodesStats.getNodes()[0].getIndices().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
IndicesStatsResponse indicesStats = client.admin().indices().prepareStats("test")
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats("test")
.clear().setFieldData(true).setFilterCache(true)
.execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0l));
assertThat(indicesStats.getTotal().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
// sort to load it to field data and filter to load filter cache
client.prepareSearch()
client().prepareSearch()
.setFilter(FilterBuilders.termFilter("field", "value1"))
.addSort("field", SortOrder.ASC)
.execute().actionGet();
client.prepareSearch()
client().prepareSearch()
.setFilter(FilterBuilders.termFilter("field", "value2"))
.addSort("field", SortOrder.ASC)
.execute().actionGet();
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true)
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true)
.execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), greaterThan(0l));
assertThat(nodesStats.getNodes()[0].getIndices().getFilterCache().getMemorySizeInBytes(), greaterThan(0l));
indicesStats = client.admin().indices().prepareStats("test")
indicesStats = client().admin().indices().prepareStats("test")
.clear().setFieldData(true).setFilterCache(true)
.execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), greaterThan(0l));
assertThat(indicesStats.getTotal().getFilterCache().getMemorySizeInBytes(), greaterThan(0l));
client.admin().indices().prepareClearCache().execute().actionGet();
client().admin().indices().prepareClearCache().execute().actionGet();
Thread.sleep(100); // Make sure the filter cache entries have been removed...
nodesStats = client.admin().cluster().prepareNodesStats().setIndices(true)
nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true)
.execute().actionGet();
assertThat(nodesStats.getNodes()[0].getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0l));
assertThat(nodesStats.getNodes()[0].getIndices().getFilterCache().getMemorySizeInBytes(), equalTo(0l));
indicesStats = client.admin().indices().prepareStats("test")
indicesStats = client().admin().indices().prepareStats("test")
.clear().setFieldData(true).setFilterCache(true)
.execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0l));

View File

@ -25,12 +25,12 @@ import org.elasticsearch.action.support.IgnoreIndices;
import org.elasticsearch.client.Client;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.testng.Assert.fail;
import static org.junit.Assert.fail;
public class TypesExistsTests extends AbstractSharedClusterTest {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.test.integration.indices.leaks;
import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.mapper.DocumentMapper;
@ -29,29 +30,28 @@ import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
/**
*/
@Test
public class IndicesLeaksTests extends AbstractNodesTests {
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}
@SuppressWarnings({"ConstantConditions", "unchecked"})
@Test
@BadApple
public void testIndexShardLifecycleLeak() throws Exception {
Node node = startNode("node1");

View File

@ -25,7 +25,7 @@ import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;

View File

@ -24,7 +24,7 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;

View File

@ -5,7 +5,7 @@ import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

View File

@ -24,13 +24,12 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.equalTo;
/**
@ -109,9 +108,7 @@ public class UpdateNumberOfReplicasTests extends AbstractSharedClusterTest {
assertThat(clusterHealth.getIndices().get("test").getActiveShards(), equalTo(5));
for (int i = 0; i < 10; i++) {
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
assertThat(countResponse.getShardFailures().toString(), countResponse.getFailedShards(), equalTo(0));
assertThat(countResponse.getCount(), equalTo(10l));
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).execute().actionGet(), 10);
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

View File

@ -26,35 +26,27 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
public class CloseIndexDisableCloseAllTests extends AbstractNodesTests {
@BeforeClass
public void createNodes() {
@Override
protected void beforeClass() {
ImmutableSettings.Builder settings = ImmutableSettings.builder().put("action.disable_close_all_indices", true);
startNode("server1", settings);
startNode("server2", settings);
}
@AfterClass
public void closeNodes() {
closeAllNodes();
}
@AfterMethod
@After
public void wipeAllIndices() {
wipeIndices(client("server1"), "_all");
}
@Test(expectedExceptions = ElasticSearchIllegalArgumentException.class)
@Test(expected = ElasticSearchIllegalArgumentException.class)
public void testCloseAllExplicitly() {
Client client = client("server1");
createIndices(client, "test1", "test2", "test3");
@ -63,7 +55,7 @@ public class CloseIndexDisableCloseAllTests extends AbstractNodesTests {
client.admin().indices().prepareClose("_all").execute().actionGet();
}
@Test(expectedExceptions = ElasticSearchIllegalArgumentException.class)
@Test(expected = ElasticSearchIllegalArgumentException.class)
public void testCloseAllWildcard() {
Client client = client("server2");
createIndices(client, "test1", "test2", "test3");
@ -72,7 +64,7 @@ public class CloseIndexDisableCloseAllTests extends AbstractNodesTests {
client.admin().indices().prepareClose("*").execute().actionGet();
}
@Test(expectedExceptions = ElasticSearchIllegalArgumentException.class)
@Test(expected = ElasticSearchIllegalArgumentException.class)
public void testCloseAllWildcard2() {
Client client = client("server2");
createIndices(client, "test1", "test2", "test3");
@ -92,7 +84,7 @@ public class CloseIndexDisableCloseAllTests extends AbstractNodesTests {
assertIndexIsClosed("test2", "test3");
}
@Test(expectedExceptions = ElasticSearchIllegalArgumentException.class)
@Test(expected = ElasticSearchIllegalArgumentException.class)
public void testCloseWildcardMatchingAll() {
Client client = client("server2");
createIndices(client, "test1", "test2", "test3");

View File

@ -30,7 +30,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@ -54,19 +54,19 @@ public class OpenCloseIndexTests extends AbstractSharedClusterTest {
assertIndexIsOpened("test1");
}
@Test(expectedExceptions = IndexMissingException.class)
@Test(expected = IndexMissingException.class)
public void testSimpleCloseMissingIndex() {
Client client = client();
client.admin().indices().prepareClose("test1").execute().actionGet();
}
@Test(expectedExceptions = IndexMissingException.class)
@Test(expected = IndexMissingException.class)
public void testSimpleOpenMissingIndex() {
Client client = client();
client.admin().indices().prepareOpen("test1").execute().actionGet();
}
@Test(expectedExceptions = IndexMissingException.class)
@Test(expected = IndexMissingException.class)
public void testCloseOneMissingIndex() {
Client client = client();
createIndex("test1");
@ -87,7 +87,7 @@ public class OpenCloseIndexTests extends AbstractSharedClusterTest {
assertIndexIsClosed("test1");
}
@Test(expectedExceptions = IndexMissingException.class)
@Test(expected = IndexMissingException.class)
public void testOpenOneMissingIndex() {
Client client = client();
createIndex("test1");
@ -178,25 +178,25 @@ public class OpenCloseIndexTests extends AbstractSharedClusterTest {
assertIndexIsOpened("test1", "test2", "test3");
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testCloseNoIndex() {
Client client = client();
client.admin().indices().prepareClose().execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testCloseNullIndex() {
Client client = client();
client.admin().indices().prepareClose(null).execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testOpenNoIndex() {
Client client = client();
client.admin().indices().prepareOpen().execute().actionGet();
}
@Test(expectedExceptions = ActionRequestValidationException.class)
@Test(expected = ActionRequestValidationException.class)
public void testOpenNullIndex() {
Client client = client();
client.admin().indices().prepareOpen(null).execute().actionGet();

View File

@ -32,8 +32,8 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
@ -47,7 +47,7 @@ public class SimpleIndexStateTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(SimpleIndexStateTests.class);
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -20,11 +20,8 @@
package org.elasticsearch.test.integration.indices.stats;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
import org.elasticsearch.action.admin.indices.stats.*;
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Priority;
@ -32,15 +29,12 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamInput;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Random;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -48,42 +42,34 @@ import static org.hamcrest.Matchers.*;
*/
public class SimpleIndexStatsTests extends AbstractNodesTests {
private Client client;
@BeforeClass
public void createNodes() throws Exception {
@Override
protected void beforeClass() {
startNode("node1");
startNode("node2");
client = getClient();
}
@AfterClass
public void closeNodes() {
client.close();
closeAllNodes();
}
protected Client getClient() {
@Override
public Client client() {
return client("node2");
}
@Test
public void simpleStats() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareDelete().execute().actionGet();
// rely on 1 replica for this tests
client.admin().indices().prepareCreate("test1").execute().actionGet();
client.admin().indices().prepareCreate("test2").execute().actionGet();
client().admin().indices().prepareCreate("test1").execute().actionGet();
client().admin().indices().prepareCreate("test2").execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
client.prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client.prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client.prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
IndicesStatsResponse stats = client.admin().indices().prepareStats().execute().actionGet();
IndicesStatsResponse stats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(stats.getPrimaries().getDocs().getCount(), equalTo(3l));
assertThat(stats.getTotal().getDocs().getCount(), equalTo(6l));
assertThat(stats.getPrimaries().getIndexing().getTotal().getIndexCount(), equalTo(3l));
@ -111,7 +97,7 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
assertThat(stats.getIndex("test1").getTotal().getSearch().getTotal().getQueryCurrent(), equalTo(0l));
// check flags
stats = client.admin().indices().prepareStats()
stats = client().admin().indices().prepareStats()
.setDocs(false)
.setStore(false)
.setIndexing(false)
@ -128,7 +114,7 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
assertThat(stats.getTotal().getRefresh(), notNullValue());
// check types
stats = client.admin().indices().prepareStats().setTypes("type1", "type").execute().actionGet();
stats = client().admin().indices().prepareStats().setTypes("type1", "type").execute().actionGet();
assertThat(stats.getPrimaries().getIndexing().getTypeStats().get("type1").getIndexCount(), equalTo(1l));
assertThat(stats.getPrimaries().getIndexing().getTypeStats().get("type").getIndexCount(), equalTo(1l));
assertThat(stats.getPrimaries().getIndexing().getTypeStats().get("type2"), nullValue());
@ -137,25 +123,25 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
assertThat(stats.getTotal().getGet().getCount(), equalTo(0l));
// check get
GetResponse getResponse = client.prepareGet("test1", "type1", "1").execute().actionGet();
GetResponse getResponse = client().prepareGet("test1", "type1", "1").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(true));
stats = client.admin().indices().prepareStats().execute().actionGet();
stats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(stats.getTotal().getGet().getCount(), equalTo(1l));
assertThat(stats.getTotal().getGet().getExistsCount(), equalTo(1l));
assertThat(stats.getTotal().getGet().getMissingCount(), equalTo(0l));
// missing get
getResponse = client.prepareGet("test1", "type1", "2").execute().actionGet();
getResponse = client().prepareGet("test1", "type1", "2").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(false));
stats = client.admin().indices().prepareStats().execute().actionGet();
stats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(stats.getTotal().getGet().getCount(), equalTo(2l));
assertThat(stats.getTotal().getGet().getExistsCount(), equalTo(1l));
assertThat(stats.getTotal().getGet().getMissingCount(), equalTo(1l));
// clear all
stats = client.admin().indices().prepareStats()
stats = client().admin().indices().prepareStats()
.setDocs(false)
.setStore(false)
.setIndexing(false)
@ -174,15 +160,15 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
@Test
public void testMergeStats() {
client.admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareDelete().execute().actionGet();
// rely on 1 replica for this tests
client.admin().indices().prepareCreate("test1").execute().actionGet();
client().admin().indices().prepareCreate("test1").execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
// clear all
IndicesStatsResponse stats = client.admin().indices().prepareStats()
IndicesStatsResponse stats = client().admin().indices().prepareStats()
.setDocs(false)
.setStore(false)
.setIndexing(false)
@ -199,12 +185,12 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
assertThat(stats.getTotal().getSearch(), nullValue());
for (int i = 0; i < 20; i++) {
client.prepareIndex("test1", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet();
client.prepareIndex("test1", "type2", Integer.toString(i)).setSource("field", "value").execute().actionGet();
client.admin().indices().prepareFlush().execute().actionGet();
client().prepareIndex("test1", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type2", Integer.toString(i)).setSource("field", "value").execute().actionGet();
client().admin().indices().prepareFlush().execute().actionGet();
}
client.admin().indices().prepareOptimize().setWaitForMerge(true).setMaxNumSegments(1).execute().actionGet();
stats = client.admin().indices().prepareStats()
client().admin().indices().prepareOptimize().setWaitForMerge(true).setMaxNumSegments(1).execute().actionGet();
stats = client().admin().indices().prepareStats()
.setMerge(true)
.execute().actionGet();
@ -214,20 +200,20 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
@Test
public void testAllFlags() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareDelete().execute().actionGet();
// rely on 1 replica for this tests
client.admin().indices().prepareCreate("test1").execute().actionGet();
client.admin().indices().prepareCreate("test2").execute().actionGet();
client().admin().indices().prepareCreate("test1").execute().actionGet();
client().admin().indices().prepareCreate("test2").execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
client.prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client.prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client.prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
IndicesStatsRequestBuilder builder = client.admin().indices().prepareStats();
client().admin().indices().prepareRefresh().execute().actionGet();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
Flag[] values = CommonStatsFlags.Flag.values();
for (Flag flag : values) {
set(flag, builder, false);
@ -247,9 +233,7 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
assertThat(isSet(flag, stats.getTotal()), equalTo(true));
}
long seed = System.currentTimeMillis();
System.out.println("seed: " + seed);
Random random = new Random(seed);
Random random = getRandom();
EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);
for (Flag flag : values) {
if (random.nextBoolean()) {
@ -292,9 +276,7 @@ public class SimpleIndexStatsTests extends AbstractNodesTests {
flags.set(flag, true);
}
assertThat(flags.anySet(), equalTo(true));
long seed = System.currentTimeMillis();
System.out.println("seed: " + seed);
Random random = new Random(seed);
Random random = getRandom();
flags.set(values[random.nextInt(values.length)], false);
assertThat(flags.anySet(), equalTo(true));

View File

@ -21,21 +21,19 @@ package org.elasticsearch.test.integration.indices.store;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import java.io.File;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.client.Requests.createIndexRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -43,41 +41,38 @@ import static org.hamcrest.Matchers.equalTo;
*/
public class IndicesStoreTests extends AbstractNodesTests {
protected Client client1;
@BeforeClass
public void startNodes() {
@Override
protected Settings getClassDefaultSettings() {
// The default (none) gateway cleans the shards on closing
putDefaultSettings(settingsBuilder().put("gateway.type", "local"));
return settingsBuilder().put("gateway.type", "local").build();
}
@Override
protected void beforeClass() {
startNode("server1");
startNode("server2");
client1 = getClient1();
}
@AfterClass
public void closeNodes() {
client1.close();
closeAllNodes();
}
protected Client getClient1() {
@Override
public Client client() {
return client("server1");
}
@Test
public void shardsCleanup() throws Exception {
try {
client1.admin().indices().prepareDelete("test").execute().actionGet();
client().admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception ex) {
// Ignore
}
logger.info("--> creating index [test] with one shard and on replica");
client1.admin().indices().create(createIndexRequest("test")
client().admin().indices().create(createIndexRequest("test")
.settings(settingsBuilder().put("index.numberOfReplicas", 1).put("index.numberOfShards", 1))).actionGet();
logger.info("--> running cluster_health");
ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
ClusterHealthResponse clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
logger.info("--> done cluster_health, status " + clusterHealth.getStatus());
@ -98,7 +93,7 @@ public class IndicesStoreTests extends AbstractNodesTests {
assertThat(server2Shard.exists(), equalTo(true));
logger.info("--> running cluster_health");
clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
logger.info("--> done cluster_health, status " + clusterHealth.getStatus());

View File

@ -27,7 +27,7 @@ import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.*;
import org.junit.*;
import java.io.File;
import java.io.IOException;
@ -42,13 +42,13 @@ import static org.hamcrest.Matchers.*;
public class SimpleDistributorTests extends AbstractNodesTests {
protected Environment environment;
@BeforeMethod
@Before
public void getTestEnvironment() {
environment = ((InternalNode) startNode("node0")).injector().getInstance(Environment.class);
closeNode("node0");
}
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import java.util.Arrays;

View File

@ -32,11 +32,10 @@ import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.hamcrest.Matchers;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -45,7 +44,7 @@ public class LocalGatewayIndicesWarmerTests extends AbstractNodesTests {
private final ESLogger logger = Loggers.getLogger(LocalGatewayIndicesWarmerTests.class);
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {
@ -56,7 +55,7 @@ public class LocalGatewayIndicesWarmerTests extends AbstractNodesTests {
}
}
}
closeAllNodes();
closeAllNodes(false);
}
@Test

View File

@ -29,7 +29,7 @@ import org.elasticsearch.search.warmer.IndexWarmerMissingException;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

View File

@ -21,7 +21,7 @@ package org.elasticsearch.test.integration.mget;
import org.elasticsearch.action.get.MultiGetRequest;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import java.io.IOException;

View File

@ -26,7 +26,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -36,7 +36,7 @@ import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.testng.Assert.fail;
import static org.junit.Assert.fail;
/**
*

View File

@ -39,7 +39,8 @@ import org.elasticsearch.search.facet.termsstats.TermsStatsFacet;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
@ -49,9 +50,7 @@ import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.AssertJUnit.fail;
@Test
public class SimpleNestedTests extends AbstractSharedClusterTest {
@Test
@ -753,7 +752,7 @@ public class SimpleNestedTests extends AbstractSharedClusterTest {
.addSort(SortBuilders.scriptSort("_fields['nested1.field1'].value", "string")
.setNestedPath("nested1").sortMode("sum").order(SortOrder.ASC))
.execute().actionGet();
fail("SearchPhaseExecutionException should have been thrown");
Assert.fail("SearchPhaseExecutionException should have been thrown");
} catch (SearchPhaseExecutionException e) {
assertThat(e.getMessage(), containsString("type [string] doesn't support mode [SUM]"));
}

View File

@ -29,7 +29,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.Test;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -35,8 +35,8 @@ import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.test.integration.nodesinfo.plugin.dummy1.TestPlugin;
import org.elasticsearch.test.integration.nodesinfo.plugin.dummy2.TestNoVersionPlugin;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.io.File;
import java.net.URISyntaxException;
@ -62,7 +62,7 @@ public class SimpleNodesInfoTests extends AbstractNodesTests {
static final String SITE_PLUGIN_NO_DESCRIPTION = "No description found for dummy.";
}
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -33,10 +33,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.Before;
import org.junit.Test;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
@ -48,19 +46,16 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.test.integration.percolator.SimplePercolatorTests.convertFromTextArray;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*
*/
@Test
public class ConcurrentPercolatorTests extends AbstractNodesTests {
private Client client;
@BeforeClass
public void startNodes() throws Exception {
@Override
public void beforeClass() throws Exception {
Settings settings = settingsBuilder()
.put("cluster.name", "percolator-test-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "_" + System.currentTimeMillis())
.put("gateway.type", "none").build();
@ -68,17 +63,13 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
startNode("node1", settings);
startNode("node2", settings);
startNode("node3", settingsBuilder().put(settings).put("node.client", true));
client = client("node3");
}
@AfterClass
public void cleanAndCloseNodes() throws Exception {
closeAllNodes();
}
@BeforeMethod
@Before
public void beforeTest() throws Exception {
client.admin().indices().prepareDelete().execute().actionGet();
setUp();
client().admin().indices().prepareDelete().execute().actionGet();
ensureGreen();
}
@ -199,11 +190,11 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
Thread[] indexThreads = new Thread[numIndexThreads];
for (int i = 0; i < numIndexThreads; i++) {
final Random rand = new Random(getRandom().nextLong());
Runnable r = new Runnable() {
@Override
public void run() {
try {
Random r = new Random();
XContentBuilder onlyField1 = XContentFactory.jsonBuilder().startObject()
.field("query", termQuery("field1", "value")).endObject();
XContentBuilder onlyField2 = XContentFactory.jsonBuilder().startObject()
@ -214,7 +205,7 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
start.await();
while (runningPercolateThreads.get() > 0) {
Thread.sleep(100);
int x = r.nextInt(3);
int x = rand.nextInt(3);
String id = Integer.toString(idGen.incrementAndGet());
IndexResponse response;
switch (x) {
@ -268,7 +259,7 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
.field("field1", "value")
.field("field2", "value")
.endObject().endObject();
Random random = new Random();
Random random = getRandom();
start.await();
for (int counter = 0; counter < numPercolatorOperationsPerThread; counter++) {
int x = random.nextInt(3);
@ -347,13 +338,12 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
@Override
public void run() {
try {
Random r = new Random();
XContentBuilder doc = XContentFactory.jsonBuilder().startObject()
.field("query", termQuery("field1", "value")).endObject();
while (run.get()) {
semaphore.acquire();
try {
if ((indexOperations.get() - deleteOperations.get()) > 0 && r.nextInt(100) < 19) {
if ((indexOperations.get() - deleteOperations.get()) > 0 && getRandom().nextInt(100) < 19) {
String id = Integer.toString(deleteOperations.incrementAndGet());
DeleteResponse response = client().prepareDelete("index", "_percolator", id)
.execute().actionGet();
@ -411,12 +401,13 @@ public class ConcurrentPercolatorTests extends AbstractNodesTests {
assertThat(assertionFailure.get(), equalTo(false));
}
private Client client() {
return client;
@Override
public Client client() {
return client("node3");
}
private void ensureGreen() {
ClusterHealthResponse actionGet = client.admin().cluster()
ClusterHealthResponse actionGet = client().admin().cluster()
.health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
assertThat(actionGet.isTimedOut(), equalTo(false));
assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN));

View File

@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.percolator;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
@ -28,8 +29,8 @@ import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ -37,13 +38,11 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.test.integration.percolator.SimplePercolatorTests.convertFromTextArray;
import static org.elasticsearch.test.integration.percolator.TTLPercolatorTests.ensureGreen;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@Test
public class RecoveryPercolatorTests extends AbstractNodesTests {
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
for (int i = 0; i < 10; i++) {
if (node("node" + i) != null) {
@ -56,15 +55,22 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
}
closeAllNodes();
}
@Override
protected Settings getClassDefaultSettings() {
return settingsBuilder().put("gateway.type", "local").build();
}
@Test
public void testRestartNodePercolator1() throws Exception {
logger.info("--> cleaning nodes");
buildNode("node1", settingsBuilder().put("gateway.type", "local"));
buildNode("node1");
cleanAndCloseNodes();
logger.info("--> starting 1 nodes");
startNode("node1", settingsBuilder().put("gateway.type", "local"));
startNode("node1");
Client client = client("node1");
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
@ -87,7 +93,7 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
client.close();
closeNode("node1");
startNode("node1", settingsBuilder().put("gateway.type", "local").build());
startNode("node1");
client = client("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
@ -106,14 +112,15 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
@Test
public void testRestartNodePercolator2() throws Exception {
logger.info("--> cleaning nodes");
buildNode("node1", settingsBuilder().put("gateway.type", "local"));
buildNode("node1");
cleanAndCloseNodes();
logger.info("--> starting 1 nodes");
startNode("node1", settingsBuilder().put("gateway.type", "local"));
startNode("node1");
Client client = client("node1");
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
client.admin().indices().prepareCreate("test")
.setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
logger.info("--> register a query");
client.prepareIndex("test", "_percolator", "kuku")
@ -135,7 +142,7 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
client.close();
closeNode("node1");
startNode("node1", settingsBuilder().put("gateway.type", "local").build());
startNode("node1");
client = client("node1");
logger.info("Running Cluster Health (wait for the shards to startup)");
@ -146,13 +153,13 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
client.admin().indices().prepareDelete("test").execute().actionGet();
DeleteIndexResponse actionGet = client.admin().indices().prepareDelete("test").execute().actionGet();
assertThat(actionGet.isAcknowledged(), equalTo(true));
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
assertThat(client.prepareCount().setTypes("_percolator").setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc")

View File

@ -34,24 +34,21 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.Assert.assertTrue;
/**
*
*/
public class SimplePercolatorTests extends AbstractSharedClusterTest {
@BeforeClass
public void createNodes() throws Exception {
cluster().ensureAtLeastNumNodes(2);
@Override
protected int numberOfNodes() {
return 2;
}
@Test
@ -559,7 +556,7 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
assertThat(response.getMatches(), arrayWithSize(1));
assertThat(convertFromTextArray(response.getMatches()), arrayContaining("1"));
} while (++counter <= 1000);
assertTrue(moreThanOneMs, "Something is off, we should have spent at least 1ms on percolating...");
assertTrue("Something is off, we should have spent at least 1ms on percolating...", moreThanOneMs);
long percolateSumTime = 0;
nodesResponse = client().admin().cluster().prepareNodesStats().execute().actionGet();

View File

@ -9,8 +9,8 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -86,7 +86,7 @@ public class TTLPercolatorTests extends AbstractNodesTests {
assertThat(percolateResponse.getMatches(), emptyArray());
}
@AfterMethod
@After
public void cleanAndCloseNodes() throws Exception {
closeAllNodes();
}

View File

@ -19,12 +19,7 @@
package org.elasticsearch.test.integration.plugin;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import com.beust.jcommander.internal.Maps;
import com.google.common.collect.Maps;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.node.internal.InternalNode;
@ -33,12 +28,17 @@ import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.test.integration.plugin.responseheader.TestResponseHeaderPlugin;
import org.elasticsearch.test.integration.rest.helper.HttpClient;
import org.elasticsearch.test.integration.rest.helper.HttpClientResponse;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Map;
import static org.elasticsearch.client.Requests.clusterHealthRequest;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
* Test a rest action that sets special response headers
*/
@ -46,14 +46,14 @@ public class ResponseHeaderPluginTests extends AbstractNodesTests {
public static final String NODE_ID = "TEST";
@BeforeMethod
@Before
public void startNode() throws Exception {
ImmutableSettings.Builder settings = settingsBuilder().put("plugin.types", TestResponseHeaderPlugin.class.getName());
startNode(NODE_ID, settings);
client(NODE_ID).admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
}
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -25,15 +25,14 @@ import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.elasticsearch.test.integration.rest.helper.HttpClient;
import org.elasticsearch.test.integration.rest.helper.HttpClientResponse;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.net.URISyntaxException;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@ -43,20 +42,15 @@ import static org.hamcrest.Matchers.equalTo;
public class SitePluginTests extends AbstractNodesTests {
@BeforeClass
public void setupPluginDirectory() throws Exception {
@Before
public void startNodes() throws URISyntaxException {
File pluginDir = new File(SitePluginTests.class.getResource("/org/elasticsearch/test/integration/plugin").toURI());
putDefaultSettings(settingsBuilder()
startNode("test", settingsBuilder()
.put("path.plugins", pluginDir.getAbsolutePath())
.build());
}
@BeforeMethod
public void startNodes() {
startNode("test");
}
@AfterMethod
@After
public void closeNodes() {
closeAllNodes();
}

View File

@ -19,14 +19,14 @@
package org.elasticsearch.test.integration.recovery;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -34,12 +34,13 @@ import static org.hamcrest.Matchers.equalTo;
*/
public class FullRollingRestartTests extends AbstractNodesTests {
@AfterMethod
@After
public void shutdownNodes() {
closeAllNodes();
}
@Test
@Slow
public void testFullRollingRestart() throws Exception {
startNode("node1");
client("node1").admin().indices().prepareCreate("test").execute().actionGet();

View File

@ -19,20 +19,20 @@
package org.elasticsearch.test.integration.recovery;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -43,6 +43,7 @@ public class RecoveryWhileUnderLoadTests extends AbstractSharedClusterTest {
private final ESLogger logger = Loggers.getLogger(RecoveryWhileUnderLoadTests.class);
@Test
@Slow
public void recoverWhileUnderLoadAllocateBackupsTest() throws Exception {
logger.info("--> creating test index ...");
prepareCreate("test", 1);
@ -130,6 +131,7 @@ public class RecoveryWhileUnderLoadTests extends AbstractSharedClusterTest {
}
@Test
@Slow
public void recoverWhileUnderLoadAllocateBackupsRelocatePrimariesTest() throws Exception {
logger.info("--> creating test index ...");
prepareCreate("test", 1);
@ -214,6 +216,7 @@ public class RecoveryWhileUnderLoadTests extends AbstractSharedClusterTest {
}
@Test
@Slow
public void recoverWhileUnderLoadWithNodeShutdown() throws Exception {
logger.info("--> creating test index ...");
prepareCreate("test", 2);

View File

@ -22,6 +22,7 @@ package org.elasticsearch.test.integration.recovery;
import gnu.trove.procedure.TIntProcedure;
import gnu.trove.set.TIntSet;
import gnu.trove.set.hash.TIntHashSet;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
@ -35,10 +36,9 @@ import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Test;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -46,7 +46,6 @@ import java.util.concurrent.atomic.AtomicLong;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -55,9 +54,9 @@ import static org.hamcrest.Matchers.equalTo;
public class RelocationTests extends AbstractNodesTests {
private final TimeValue ACCEPTABLE_RELOCATION_TIME = new TimeValue(5, TimeUnit.MINUTES);
@AfterMethod
@After
public void shutdownNodes() {
closeAllNodes();
closeAllNodes(true);
}
@Test
@ -109,23 +108,17 @@ public class RelocationTests extends AbstractNodesTests {
}
@Test
@Slow
public void testPrimaryRelocationWhileIndexingRandom() throws Exception {
long seed = System.currentTimeMillis();
Random random = new Random();
final int iter = NIGHLY ? 5 : 1;
for (int i = 0; i < iter; i++) {
try {
int numRelocations = 1 + random.nextInt(10);
int numWriters = 1 + random.nextInt(5);
boolean batch = random.nextBoolean();
logger.info("testPrimaryRelocationWhileIndexingRandom(numRelocations={}, numWriters={}, batch={} -- seed={}",
numRelocations, numWriters, batch, seed);
testPrimaryRelocationWhileIndexing(numRelocations, numWriters, batch);
} finally {
closeAllNodes();
}
}
int numRelocations = atLeast(rarely() ? 3 : 1);
int numWriters = atLeast(rarely() ? 3 : 1);
boolean batch = getRandom().nextBoolean();
logger.info("testPrimaryRelocationWhileIndexingRandom(numRelocations={}, numWriters={}, batch={}",
numRelocations, numWriters, batch);
testPrimaryRelocationWhileIndexing(numRelocations, numWriters, batch);
}
private void testPrimaryRelocationWhileIndexing(final int numberOfRelocations, final int numberOfWriters, final boolean batch) throws Exception {
logger.info("--> starting [node1] ...");
@ -265,21 +258,13 @@ public class RelocationTests extends AbstractNodesTests {
}
@Test
@Slow
public void testReplicaRelocationWhileIndexingRandom() throws Exception {
long seed = System.currentTimeMillis();
Random random = new Random();
final int iter = NIGHLY ? 5 : 1;
for (int i = 0; i < iter; i++) {
try {
int numRelocations = 1 + random.nextInt(10);
int numWriters = 1 + random.nextInt(5);
boolean batch = random.nextBoolean();
logger.info("testReplicaRelocationWhileIndexing(numRelocations={}, numWriters={}, batch={} -- seed={}", numRelocations, numWriters, batch, seed);
testReplicaRelocationWhileIndexing(numRelocations, numWriters, batch);
} finally {
closeAllNodes();
}
}
int numRelocations = atLeast(rarely() ? 3 : 1);
int numWriters = atLeast(rarely() ? 3 : 1);
boolean batch = getRandom().nextBoolean();
logger.info("testReplicaRelocationWhileIndexing(numRelocations={}, numWriters={}, batch={}", numRelocations, numWriters, batch);
testReplicaRelocationWhileIndexing(numRelocations, numWriters, batch);
}
private void testReplicaRelocationWhileIndexing(final int numberOfRelocations, final int numberOfWriters, final boolean batch) throws Exception {

View File

@ -27,7 +27,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.client.Requests.*;
import static org.hamcrest.MatcherAssert.assertThat;

View File

@ -22,8 +22,7 @@ package org.elasticsearch.test.integration.routing;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.common.Priority;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import java.util.Map;
import java.util.Set;
@ -40,10 +39,9 @@ import static org.hamcrest.Matchers.nullValue;
*/
public class AliasResolveRoutingTests extends AbstractSharedClusterTest {
@BeforeClass
public void createNodes() throws Exception {
cluster().ensureAtLeastNumNodes(2);
@Override
protected int numberOfNodes() {
return 2;
}
@Test

View File

@ -26,7 +26,7 @@ import org.elasticsearch.client.Requests;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.cluster.metadata.AliasAction.newAddAliasAction;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;

View File

@ -27,8 +27,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Test;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.MatcherAssert.assertThat;
@ -39,9 +38,11 @@ import static org.hamcrest.Matchers.instanceOf;
*
*/
public class SimpleRoutingTests extends AbstractSharedClusterTest {
@BeforeClass
public void createNodes() throws Exception {
cluster().ensureAtLeastNumNodes(2);
@Override
protected int numberOfNodes() {
return 2;
}
@Test

View File

@ -28,7 +28,7 @@ import java.util.Arrays;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;

View File

@ -42,7 +42,7 @@ import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test;
import org.junit.Test;
import com.google.common.base.Charsets;

Some files were not shown because too many files have changed in this diff Show More