Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mkleen committed Oct 8, 2020
1 parent a8261d8 commit 8eeeabe
Showing 1 changed file with 22 additions and 80 deletions.
102 changes: 22 additions & 80 deletions server/src/test/java/org/elasticsearch/index/IndexServiceTests.java
Expand Up @@ -20,70 +20,36 @@
package org.elasticsearch.index;

import io.crate.common.unit.TimeValue;
import io.crate.exceptions.SQLParseException;
import io.crate.integrationtests.SQLHttpIntegrationTest;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TopDocs;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.engine.EngineTestCase;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.IndexShardTestCase;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.Ignore;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import static io.crate.protocols.postgres.PGErrorStatus.INTERNAL_ERROR;
import static io.crate.testing.Asserts.assertThrows;
import static io.crate.testing.SQLErrorMatcher.isSQLError;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static org.elasticsearch.index.shard.IndexShardTestCase.flushShard;
import static org.elasticsearch.index.shard.IndexShardTestCase.getEngine;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.is;

@ESIntegTestCase.ClusterScope(numDataNodes = 1, supportsDedicatedMasters = false, numClientNodes = 0)
public class IndexServiceTests extends SQLHttpIntegrationTest {

IndexService createIndex(String index, Settings settings) {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
assertAcked(createIndexRequestBuilder.get());
// Wait for the index to be allocated so that cluster state updates don't override
// changes that would have been done locally
ClusterHealthResponse health = client().admin().cluster()
.health(Requests.clusterHealthRequest(getFqn(index)).waitForYellowStatus().waitForEvents(Priority.LANGUID)
.waitForNoRelocatingShards(true)).actionGet();
assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW));
assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1));
IndicesService instanceFromNode = internalCluster().getInstances(IndicesService.class).iterator().next();
return getIndexService(index);
}

IndexService getIndexService(String index) {
return getIndicesService().indexServiceSafe(resolveIndex(getFqn(index)));
}

IndicesService getIndicesService() {
return internalCluster().getInstances(IndicesService.class).iterator().next();
}

public void testBaseAsyncTask() throws Exception {
execute("create table test (x int, data text)");
IndexService indexService = getIndexService("test");
Expand Down Expand Up @@ -290,6 +256,7 @@ public void testFsyncTaskIsRunning() throws Exception {
assertNull(indexService.getFsyncTask());
}

@Ignore
public void testRefreshActuallyWorks() throws Exception {
execute("create table test (x int, data text)");
var indexService = getIndexService("test");
Expand Down Expand Up @@ -385,7 +352,8 @@ public void testAsyncTranslogTrimActuallyWorks() throws Exception {
assertBusy(() -> assertThat(EngineTestCase.getTranslog(getEngine(shard)).totalOperations(), equalTo(0)));
}

/* public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {
@Ignore
public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {
execute("create table test(x int, data string) with (\"translog.retention.check_interval\" = '100ms')");
IndexService indexService = getIndexService("test");

Expand Down Expand Up @@ -422,49 +390,23 @@ public void testAsyncTranslogTrimActuallyWorks() throws Exception {
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
assertThat(getEngine(indexService.getShard(0)).getTranslogStats().getTranslogSizeInBytes(),
equalTo((long) Translog.DEFAULT_HEADER_SIZE_IN_BYTES));
}*/

public void testIllegalFsyncInterval() {
try {
execute("create table test(x int, data string) with (\"translog.sync_interval\" = '0ms')");
fail();
} catch (SQLParseException ex) {
assertEquals("failed to parse value [0ms] for setting [index.translog.sync_interval], must be >= [100ms]", ex.getMessage());
}
}

public void testUpdateSyncIntervalDynamically() {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "10s") // very often :)
.build();
IndexService indexService = createIndex("test", settings);
ensureGreen("test");
assertNull(indexService.getFsyncTask());

Settings.Builder builder = Settings.builder().put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "5s")
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC.name());

client()
.admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(builder)
.get();
public void testIllegalFsyncInterval() {
assertThrows(() -> execute("create table test(x int, data string) with (\"translog.sync_interval\" = '0ms')"),
isSQLError(is("failed to parse value [0ms] for setting [index.translog.sync_interval], must be >= [100ms]"),
INTERNAL_ERROR,
BAD_REQUEST,
4000));

assertNotNull(indexService.getFsyncTask());
assertTrue(indexService.getFsyncTask().mustReschedule());
}

IndexMetadata indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertEquals("5s", indexMetadata.getSettings().get(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey()));
private IndexService getIndexService(String index) {
return getIndicesService().indexServiceSafe(resolveIndex(getFqn(index)));
}

execute("alter table test close");
client()
.admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "20s"))
.get();
indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertEquals("20s", indexMetadata.getSettings().get(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey()));
private IndicesService getIndicesService() {
return internalCluster().getInstances(IndicesService.class).iterator().next();
}

}

0 comments on commit 8eeeabe

Please sign in to comment.