Merge pull request #16333 from rjernst/single_node_static

Make single node utility methods non-static
This commit is contained in:
Ryan Ernst 2016-02-01 08:46:54 -08:00
commit 01b80b100e
6 changed files with 38 additions and 16 deletions

View File

@ -37,8 +37,8 @@ import java.util.Arrays;
public class BigArraysTests extends ESSingleNodeTestCase { public class BigArraysTests extends ESSingleNodeTestCase {
public static BigArrays randombigArrays() { private BigArrays randombigArrays() {
final PageCacheRecycler recycler = randomBoolean() ? null : ESSingleNodeTestCase.getInstanceFromNode(PageCacheRecycler.class); final PageCacheRecycler recycler = randomBoolean() ? null : getInstanceFromNode(PageCacheRecycler.class);
return new MockBigArrays(recycler, new NoneCircuitBreakerService()); return new MockBigArrays(recycler, new NoneCircuitBreakerService());
} }

View File

@ -25,6 +25,8 @@ import com.carrotsearch.hppc.cursors.ObjectLongCursor;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import java.util.HashMap; import java.util.HashMap;
@ -38,13 +40,18 @@ public class BytesRefHashTests extends ESSingleNodeTestCase {
BytesRefHash hash; BytesRefHash hash;
private BigArrays randombigArrays() {
final PageCacheRecycler recycler = randomBoolean() ? null : getInstanceFromNode(PageCacheRecycler.class);
return new MockBigArrays(recycler, new NoneCircuitBreakerService());
}
private void newHash() { private void newHash() {
if (hash != null) { if (hash != null) {
hash.close(); hash.close();
} }
// Test high load factors to make sure that collision resolution works fine // Test high load factors to make sure that collision resolution works fine
final float maxLoadFactor = 0.6f + randomFloat() * 0.39f; final float maxLoadFactor = 0.6f + randomFloat() * 0.39f;
hash = new BytesRefHash(randomIntBetween(0, 100), maxLoadFactor, BigArraysTests.randombigArrays()); hash = new BytesRefHash(randomIntBetween(0, 100), maxLoadFactor, randombigArrays());
} }
@Override @Override

View File

@ -22,6 +22,8 @@ package org.elasticsearch.common.util;
import com.carrotsearch.hppc.LongLongHashMap; import com.carrotsearch.hppc.LongLongHashMap;
import com.carrotsearch.hppc.LongLongMap; import com.carrotsearch.hppc.LongLongMap;
import com.carrotsearch.hppc.cursors.LongLongCursor; import com.carrotsearch.hppc.cursors.LongLongCursor;
import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import java.util.HashMap; import java.util.HashMap;
@ -33,6 +35,11 @@ import java.util.Set;
public class LongHashTests extends ESSingleNodeTestCase { public class LongHashTests extends ESSingleNodeTestCase {
LongHash hash; LongHash hash;
private BigArrays randombigArrays() {
final PageCacheRecycler recycler = randomBoolean() ? null : getInstanceFromNode(PageCacheRecycler.class);
return new MockBigArrays(recycler, new NoneCircuitBreakerService());
}
private void newHash() { private void newHash() {
if (hash != null) { if (hash != null) {
hash.close(); hash.close();
@ -40,7 +47,7 @@ public class LongHashTests extends ESSingleNodeTestCase {
// Test high load factors to make sure that collision resolution works fine // Test high load factors to make sure that collision resolution works fine
final float maxLoadFactor = 0.6f + randomFloat() * 0.39f; final float maxLoadFactor = 0.6f + randomFloat() * 0.39f;
hash = new LongHash(randomIntBetween(0, 100), maxLoadFactor, BigArraysTests.randombigArrays()); hash = new LongHash(randomIntBetween(0, 100), maxLoadFactor, randombigArrays());
} }
@Override @Override

View File

@ -20,12 +20,20 @@
package org.elasticsearch.common.util; package org.elasticsearch.common.util;
import com.carrotsearch.hppc.LongObjectHashMap; import com.carrotsearch.hppc.LongObjectHashMap;
import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
public class LongObjectHashMapTests extends ESSingleNodeTestCase { public class LongObjectHashMapTests extends ESSingleNodeTestCase {
private BigArrays randombigArrays() {
final PageCacheRecycler recycler = randomBoolean() ? null : getInstanceFromNode(PageCacheRecycler.class);
return new MockBigArrays(recycler, new NoneCircuitBreakerService());
}
public void testDuel() { public void testDuel() {
final LongObjectHashMap<Object> map1 = new LongObjectHashMap<>(); final LongObjectHashMap<Object> map1 = new LongObjectHashMap<>();
final LongObjectPagedHashMap<Object> map2 = new LongObjectPagedHashMap<>(randomInt(42), 0.6f + randomFloat() * 0.39f, BigArraysTests.randombigArrays()); final LongObjectPagedHashMap<Object> map2 = new LongObjectPagedHashMap<>(randomInt(42), 0.6f + randomFloat() * 0.39f, randombigArrays());
final int maxKey = randomIntBetween(1, 10000); final int maxKey = randomIntBetween(1, 10000);
final int iters = scaledRandomIntBetween(10000, 100000); final int iters = scaledRandomIntBetween(10000, 100000);
for (int i = 0; i < iters; ++i) { for (int i = 0; i < iters; ++i) {

View File

@ -115,7 +115,7 @@ public class SimpleThreadPoolIT extends ESIntegTestCase {
for (String threadName : threadNames) { for (String threadName : threadNames) {
// ignore some shared threads we know that are created within the same VM, like the shared discovery one // ignore some shared threads we know that are created within the same VM, like the shared discovery one
// or the ones that are occasionally come up from ESSingleNodeTestCase // or the ones that are occasionally come up from ESSingleNodeTestCase
if (threadName.contains("[" + ESSingleNodeTestCase.nodeName() + "]") if (threadName.contains("[node_s_0]") // TODO: this can't possibly be right! single node and integ test are unrelated!
|| threadName.contains("Keep-Alive-Timer")) { || threadName.contains("Keep-Alive-Timer")) {
continue; continue;
} }

View File

@ -185,49 +185,49 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
/** /**
* Returns a client to the single-node cluster. * Returns a client to the single-node cluster.
*/ */
public static Client client() { public Client client() {
return NODE.client(); return NODE.client();
} }
/** /**
* Returns the single test nodes name. * Returns the single test nodes name.
*/ */
public static String nodeName() { public String nodeName() {
return "node_s_0"; return "node_s_0";
} }
/** /**
* Return a reference to the singleton node. * Return a reference to the singleton node.
*/ */
protected static Node node() { protected Node node() {
return NODE; return NODE;
} }
/** /**
* Get an instance for a particular class using the injector of the singleton node. * Get an instance for a particular class using the injector of the singleton node.
*/ */
protected static <T> T getInstanceFromNode(Class<T> clazz) { protected <T> T getInstanceFromNode(Class<T> clazz) {
return NODE.injector().getInstance(clazz); return NODE.injector().getInstance(clazz);
} }
/** /**
* Create a new index on the singleton node with empty index settings. * Create a new index on the singleton node with empty index settings.
*/ */
protected static IndexService createIndex(String index) { protected IndexService createIndex(String index) {
return createIndex(index, Settings.EMPTY); return createIndex(index, Settings.EMPTY);
} }
/** /**
* Create a new index on the singleton node with the provided index settings. * Create a new index on the singleton node with the provided index settings.
*/ */
protected static IndexService createIndex(String index, Settings settings) { protected IndexService createIndex(String index, Settings settings) {
return createIndex(index, settings, null, (XContentBuilder) null); return createIndex(index, settings, null, (XContentBuilder) null);
} }
/** /**
* Create a new index on the singleton node with the provided index settings. * Create a new index on the singleton node with the provided index settings.
*/ */
protected static IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) { protected IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings); CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
if (type != null && mappings != null) { if (type != null && mappings != null) {
createIndexRequestBuilder.addMapping(type, mappings); createIndexRequestBuilder.addMapping(type, mappings);
@ -238,7 +238,7 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
/** /**
* Create a new index on the singleton node with the provided index settings. * Create a new index on the singleton node with the provided index settings.
*/ */
protected static IndexService createIndex(String index, Settings settings, String type, Object... mappings) { protected IndexService createIndex(String index, Settings settings, String type, Object... mappings) {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings); CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
if (type != null && mappings != null) { if (type != null && mappings != null) {
createIndexRequestBuilder.addMapping(type, mappings); createIndexRequestBuilder.addMapping(type, mappings);
@ -246,7 +246,7 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
return createIndex(index, createIndexRequestBuilder); return createIndex(index, createIndexRequestBuilder);
} }
protected static IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) { protected IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) {
assertAcked(createIndexRequestBuilder.get()); assertAcked(createIndexRequestBuilder.get());
// Wait for the index to be allocated so that cluster state updates don't override // Wait for the index to be allocated so that cluster state updates don't override
// changes that would have been done locally // changes that would have been done locally
@ -261,7 +261,7 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
/** /**
* Create a new search context. * Create a new search context.
*/ */
protected static SearchContext createSearchContext(IndexService indexService) { protected SearchContext createSearchContext(IndexService indexService) {
BigArrays bigArrays = indexService.getIndexServices().getBigArrays(); BigArrays bigArrays = indexService.getIndexServices().getBigArrays();
ThreadPool threadPool = indexService.getIndexServices().getThreadPool(); ThreadPool threadPool = indexService.getIndexServices().getThreadPool();
PageCacheRecycler pageCacheRecycler = node().injector().getInstance(PageCacheRecycler.class); PageCacheRecycler pageCacheRecycler = node().injector().getInstance(PageCacheRecycler.class);