Skip to content

Commit 48870c6

Browse files
committed
Don't spin up a whole node to unit test some data structures (#61923)
BytesRefHashTests and LongObjectHashMapTests currently extend ESSingleNodeTestCase, which builds an entire node just to run some unit tests over entirely in-memory data structures. This commit converts them both to extend ESTestCase.
1 parent 3a1e0ed commit 48870c6

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

server/src/test/java/org/elasticsearch/common/util/BytesRefHashTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@
2727
import org.apache.lucene.util.TestUtil;
2828
import org.elasticsearch.common.settings.Settings;
2929
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
30-
import org.elasticsearch.test.ESSingleNodeTestCase;
30+
import org.elasticsearch.test.ESTestCase;
3131

3232
import java.util.HashMap;
3333
import java.util.HashSet;
34-
import java.util.Iterator;
3534
import java.util.Map;
3635
import java.util.Map.Entry;
3736
import java.util.Set;
3837

39-
public class BytesRefHashTests extends ESSingleNodeTestCase {
38+
public class BytesRefHashTests extends ESTestCase {
4039

4140
BytesRefHash hash;
4241

43-
private BigArrays randombigArrays() {
42+
private BigArrays randomBigArrays() {
4443
return new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
4544
}
4645

@@ -50,7 +49,7 @@ private void newHash() {
5049
}
5150
// Test high load factors to make sure that collision resolution works fine
5251
final float maxLoadFactor = 0.6f + randomFloat() * 0.39f;
53-
hash = new BytesRefHash(randomIntBetween(0, 100), maxLoadFactor, randombigArrays());
52+
hash = new BytesRefHash(randomIntBetween(0, 100), maxLoadFactor, randomBigArrays());
5453
}
5554

5655
@Override
@@ -59,7 +58,7 @@ public void setUp() throws Exception {
5958
newHash();
6059
}
6160

62-
public void testDuell() {
61+
public void testDuel() {
6362
final int len = randomIntBetween(1, 100000);
6463
final BytesRef[] values = new BytesRef[len];
6564
for (int i = 0; i < values.length; ++i) {
@@ -80,8 +79,7 @@ public void testDuell() {
8079
}
8180

8281
assertEquals(valueToId.size(), hash.size());
83-
for (Iterator<ObjectLongCursor<BytesRef>> iterator = valueToId.iterator(); iterator.hasNext(); ) {
84-
final ObjectLongCursor<BytesRef> next = iterator.next();
82+
for (final ObjectLongCursor<BytesRef> next : valueToId) {
8583
assertEquals(next.value, hash.find(next.key, next.key.hashCode()));
8684
}
8785

@@ -147,7 +145,7 @@ public void testGet() {
147145
long count = hash.size();
148146
long key = hash.add(ref.get());
149147
if (key >= 0) {
150-
assertNull(strings.put(str, Long.valueOf(key)));
148+
assertNull(strings.put(str, key));
151149
assertEquals(uniqueCount, key);
152150
uniqueCount++;
153151
assertEquals(hash.size(), count + 1);
@@ -158,7 +156,7 @@ public void testGet() {
158156
}
159157
for (Entry<String, Long> entry : strings.entrySet()) {
160158
ref.copyChars(entry.getKey());
161-
assertEquals(ref.get(), hash.get(entry.getValue().longValue(), scratch));
159+
assertEquals(ref.get(), hash.get(entry.getValue(), scratch));
162160
}
163161
newHash();
164162
}
@@ -205,7 +203,7 @@ public void testAdd() {
205203
hash.close();
206204
}
207205

208-
public void testFind() throws Exception {
206+
public void testFind() {
209207
BytesRefBuilder ref = new BytesRefBuilder();
210208
BytesRef scratch = new BytesRef();
211209
int num = scaledRandomIntBetween(2, 20);

server/src/test/java/org/elasticsearch/common/util/LongObjectHashMapTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
import com.carrotsearch.hppc.LongObjectHashMap;
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
25-
import org.elasticsearch.test.ESSingleNodeTestCase;
25+
import org.elasticsearch.test.ESTestCase;
2626

27-
public class LongObjectHashMapTests extends ESSingleNodeTestCase {
27+
public class LongObjectHashMapTests extends ESTestCase {
2828

29-
private BigArrays randombigArrays() {
29+
private BigArrays randomBigArrays() {
3030
return new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
3131
}
3232

3333
public void testDuel() {
3434
final LongObjectHashMap<Object> map1 = new LongObjectHashMap<>();
3535
final LongObjectPagedHashMap<Object> map2 =
36-
new LongObjectPagedHashMap<>(randomInt(42), 0.6f + randomFloat() * 0.39f, randombigArrays());
36+
new LongObjectPagedHashMap<>(randomInt(42), 0.6f + randomFloat() * 0.39f, randomBigArrays());
3737
final int maxKey = randomIntBetween(1, 10000);
3838
final int iters = scaledRandomIntBetween(10000, 100000);
3939
for (int i = 0; i < iters; ++i) {

0 commit comments

Comments
 (0)