Cut over NoMasterNodeTests to AbstractIntegrationTest
This commit is contained in:
parent
1a34172a6c
commit
e97aa9918a
|
@ -26,10 +26,10 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.discovery.Discovery;
|
import org.elasticsearch.discovery.Discovery;
|
||||||
import org.elasticsearch.node.Node;
|
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.test.AbstractNodesTests;
|
import org.elasticsearch.test.AbstractIntegrationTest;
|
||||||
import org.junit.After;
|
import org.elasticsearch.test.AbstractIntegrationTest.ClusterScope;
|
||||||
|
import org.elasticsearch.test.AbstractIntegrationTest.Scope;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -40,12 +40,8 @@ import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class NoMasterNodeTests extends AbstractNodesTests {
|
@ClusterScope(scope=Scope.TEST, numNodes=0)
|
||||||
|
public class NoMasterNodeTests extends AbstractIntegrationTest {
|
||||||
@After
|
|
||||||
public void cleanAndCloseNodes() throws Exception {
|
|
||||||
closeAllNodes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoMasterActions() throws Exception {
|
public void testNoMasterActions() throws Exception {
|
||||||
|
@ -60,32 +56,30 @@ public class NoMasterNodeTests extends AbstractNodesTests {
|
||||||
|
|
||||||
TimeValue timeout = TimeValue.timeValueMillis(200);
|
TimeValue timeout = TimeValue.timeValueMillis(200);
|
||||||
|
|
||||||
final Node node = startNode("node1", settings);
|
cluster().startNode(settings);
|
||||||
// start a second node, create an index, and then shut it down so we have no master block
|
// start a second node, create an index, and then shut it down so we have no master block
|
||||||
Node node2 = startNode("node2", settings);
|
cluster().startNode(settings);
|
||||||
node.client().admin().indices().prepareCreate("test").execute().actionGet();
|
client().admin().indices().prepareCreate("test").execute().actionGet();
|
||||||
node.client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
|
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
|
||||||
node2.close();
|
cluster().stopRandomNode();
|
||||||
awaitBusy(new Predicate<Object>() {
|
assertThat(awaitBusy(new Predicate<Object>() {
|
||||||
public boolean apply(Object o) {
|
public boolean apply(Object o) {
|
||||||
ClusterState state = node.client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
|
ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
|
||||||
return state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK);
|
return state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK);
|
||||||
}
|
}
|
||||||
});
|
}), equalTo(true));
|
||||||
|
|
||||||
ClusterState state = node.client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
|
|
||||||
assertThat(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK), equalTo(true));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
node.client().prepareGet("test", "type1", "1").execute().actionGet();
|
client().prepareGet("test", "type1", "1").execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
node.client().prepareMultiGet().add("test", "type1", "1").execute().actionGet();
|
client().prepareMultiGet().add("test", "type1", "1").execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
@ -93,41 +87,41 @@ public class NoMasterNodeTests extends AbstractNodesTests {
|
||||||
try {
|
try {
|
||||||
PercolateSourceBuilder percolateSource = new PercolateSourceBuilder();
|
PercolateSourceBuilder percolateSource = new PercolateSourceBuilder();
|
||||||
percolateSource.percolateDocument().setDoc(new HashMap());
|
percolateSource.percolateDocument().setDoc(new HashMap());
|
||||||
node.client().preparePercolate()
|
client().preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type1")
|
.setIndices("test").setDocumentType("type1")
|
||||||
.setSource(percolateSource).execute().actionGet();
|
.setSource(percolateSource).execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
node.client().prepareUpdate("test", "type1", "1").setScript("test script").setTimeout(timeout).execute().actionGet();
|
client().prepareUpdate("test", "type1", "1").setScript("test script").setTimeout(timeout).execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
|
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
node.client().admin().indices().prepareAnalyze("test", "this is a test").execute().actionGet();
|
client().admin().indices().prepareAnalyze("test", "this is a test").execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
node.client().prepareCount("test").execute().actionGet();
|
client().prepareCount("test").execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
now = System.currentTimeMillis();
|
now = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
node.client().prepareIndex("test", "type1", "1").setSource(XContentFactory.jsonBuilder().startObject().endObject()).setTimeout(timeout).execute().actionGet();
|
client().prepareIndex("test", "type1", "1").setSource(XContentFactory.jsonBuilder().startObject().endObject()).setTimeout(timeout).execute().actionGet();
|
||||||
assert false;
|
fail("Expected ClusterBlockException");
|
||||||
} catch (ClusterBlockException e) {
|
} catch (ClusterBlockException e) {
|
||||||
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
|
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
|
||||||
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
|
||||||
|
|
|
@ -155,18 +155,20 @@ public abstract class AbstractIntegrationTest extends ElasticSearchTestCase {
|
||||||
public void after() throws IOException {
|
public void after() throws IOException {
|
||||||
try {
|
try {
|
||||||
logger.info("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName());
|
logger.info("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName());
|
||||||
MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().getMetaData();
|
Scope currentClusterScope = getCurrentClusterScope();
|
||||||
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(), metaData
|
if (currentClusterScope == Scope.TEST) {
|
||||||
.persistentSettings().getAsMap().size(), equalTo(0));
|
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
|
||||||
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(), metaData
|
} else {
|
||||||
.persistentSettings().getAsMap().size(), equalTo(0));
|
MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().getMetaData();
|
||||||
|
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(), metaData
|
||||||
|
.persistentSettings().getAsMap().size(), equalTo(0));
|
||||||
|
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(), metaData
|
||||||
|
.persistentSettings().getAsMap().size(), equalTo(0));
|
||||||
|
|
||||||
|
}
|
||||||
wipeIndices(); // wipe after to make sure we fail in the test that
|
wipeIndices(); // wipe after to make sure we fail in the test that
|
||||||
// didn't ack the delete
|
// didn't ack the delete
|
||||||
wipeTemplates();
|
wipeTemplates();
|
||||||
Scope currentClusterScope = getCurrentClusterScope();
|
|
||||||
if (currentClusterScope == Scope.TEST) {
|
|
||||||
clearClusters();
|
|
||||||
}
|
|
||||||
ensureAllSearchersClosed();
|
ensureAllSearchersClosed();
|
||||||
ensureAllFilesClosed();
|
ensureAllFilesClosed();
|
||||||
logger.info("[{}#{}]: cleaned up after test", getTestClass().getSimpleName(), getTestName());
|
logger.info("[{}#{}]: cleaned up after test", getTestClass().getSimpleName(), getTestName());
|
||||||
|
|
Loading…
Reference in New Issue