Skip to content

Commit

Permalink
Remove hppc from o.e.c.util tests (#85406)
Browse files Browse the repository at this point in the history
These tests have no need to use hppc since they do not interact with any
hppc types from server.

relates #84735
  • Loading branch information
rjernst committed Mar 28, 2022
1 parent 434aba8 commit 9e588de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

package org.elasticsearch.common.util;

import com.carrotsearch.hppc.ObjectLongHashMap;
import com.carrotsearch.hppc.ObjectLongMap;
import com.carrotsearch.hppc.cursors.ObjectLongCursor;

import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
Expand Down Expand Up @@ -44,7 +40,7 @@ public void testDuel() {
for (int i = 0; i < values.length; ++i) {
values[i] = new BytesRef(randomAlphaOfLength(5));
}
final ObjectLongMap<BytesRef> valueToId = new ObjectLongHashMap<>();
final Map<BytesRef, Integer> valueToId = new HashMap<>();
final BytesRef[] idToValue = new BytesRef[values.length];
final int iters = randomInt(1000000);
for (int i = 0; i < iters; ++i) {
Expand All @@ -59,8 +55,8 @@ public void testDuel() {
}

assertEquals(valueToId.size(), hash.size());
for (final ObjectLongCursor<BytesRef> next : valueToId) {
assertEquals(next.value, hash.find(next.key, next.key.hashCode()));
for (var entry : valueToId.entrySet()) {
assertEquals(entry.getValue().longValue(), hash.find(entry.getKey(), entry.getKey().hashCode()));
}

for (long i = 0; i < hash.capacity(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@

package org.elasticsearch.common.util;

import com.carrotsearch.hppc.LongLongHashMap;
import com.carrotsearch.hppc.LongLongMap;
import com.carrotsearch.hppc.cursors.LongLongCursor;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ESTestCase;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

Expand All @@ -34,13 +29,13 @@ private LongHash randomHash() {
return new LongHash(randomIntBetween(0, 100), maxLoadFactor, mockBigArrays());
}

public void testDuell() {
public void testDuel() {
try (LongHash hash = randomHash()) {
final Long[] values = new Long[randomIntBetween(1, 100000)];
for (int i = 0; i < values.length; ++i) {
values[i] = randomLong();
}
final LongLongMap valueToId = new LongLongHashMap();
final Map<Long, Integer> valueToId = new HashMap<>();
final long[] idToValue = new long[values.length];
final int iters = randomInt(1000000);
for (int i = 0; i < iters; ++i) {
Expand All @@ -55,9 +50,8 @@ public void testDuell() {
}

assertEquals(valueToId.size(), hash.size());
for (Iterator<LongLongCursor> iterator = valueToId.iterator(); iterator.hasNext();) {
final LongLongCursor next = iterator.next();
assertEquals(next.value, hash.find(next.key));
for (var entry : valueToId.entrySet()) {
assertEquals(entry.getValue().longValue(), hash.find(entry.getKey()));
}

for (long i = 0; i < hash.capacity(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@

package org.elasticsearch.common.util;

import com.carrotsearch.hppc.LongObjectHashMap;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ESTestCase;

import java.util.HashMap;
import java.util.Map;

public class LongObjectPagedHashMapTests extends ESTestCase {

private BigArrays mockBigArrays() {
return new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
}

public void testDuel() {
final LongObjectHashMap<Object> map1 = new LongObjectHashMap<>();
final Map<Long, Object> map1 = new HashMap<>();
final LongObjectPagedHashMap<Object> map2 = new LongObjectPagedHashMap<>(
randomInt(42),
0.6f + randomFloat() * 0.39f,
Expand All @@ -44,10 +45,10 @@ public void testDuel() {
assertEquals(map1.size(), map2.size());
}
}
for (int i = 0; i <= maxKey; ++i) {
for (long i = 0; i <= maxKey; ++i) {
assertSame(map1.get(i), map2.get(i));
}
final LongObjectHashMap<Object> copy = new LongObjectHashMap<>();
final Map<Long, Object> copy = new HashMap<>();
for (LongObjectPagedHashMap.Cursor<Object> cursor : map2) {
copy.put(cursor.key, cursor.value);
}
Expand Down

0 comments on commit 9e588de

Please sign in to comment.