Skip to content

Commit

Permalink
Fix tests, pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlowskija committed Dec 20, 2024
1 parent 9b8852a commit b2c1690
Showing 1 changed file with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand All @@ -32,17 +33,19 @@
import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.solr.client.api.model.CollectionStatusResponse;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.SolrCore;
import org.apache.solr.embedded.JettySolrRunner;
import org.apache.solr.jersey.SolrJacksonMapper;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.TimeOut;
Expand Down Expand Up @@ -177,56 +180,42 @@ public void testIntegration() throws Exception {
assertEquals(0, sampledRsp.getStatus());
for (int i : Arrays.asList(1, 2)) {
@SuppressWarnings({"unchecked"})
NamedList<Object> segInfos =
(NamedList<Object>)
rsp.getResponse()
.findRecursive(collection, "shards", "shard" + i, "leader", "segInfos");
@SuppressWarnings({"unchecked"})
NamedList<Object> rawSize = (NamedList<Object>) segInfos.get("rawSize");
final var segInfosRaw =
Utils.getObjectByPath(
rsp.getResponse(),
false,
List.of(collection, "shards", "shard" + i, "leader", "segInfos"));
final var segInfos =
SolrJacksonMapper.getObjectMapper()
.convertValue(segInfosRaw, CollectionStatusResponse.SegmentInfo.class);

final var rawSize = segInfos.rawSize;
assertNotNull("rawSize missing", rawSize);
@SuppressWarnings({"unchecked"})
Map<String, Object> rawSizeMap = rawSize.asMap(10);
@SuppressWarnings({"unchecked"})
Map<String, Object> fieldsBySize =
(Map<String, Object>) rawSizeMap.get(IndexSizeEstimator.FIELDS_BY_SIZE);
Map<String, String> fieldsBySize = rawSize.fieldsBySize;
assertNotNull("fieldsBySize missing", fieldsBySize);
assertEquals(fieldsBySize.toString(), fields.size(), fieldsBySize.size());
fields.forEach(field -> assertNotNull("missing field " + field, fieldsBySize.get(field)));
@SuppressWarnings({"unchecked"})
Map<String, Object> typesBySize =
(Map<String, Object>) rawSizeMap.get(IndexSizeEstimator.TYPES_BY_SIZE);
Map<String, String> typesBySize = rawSize.typesBySize;
assertNotNull("typesBySize missing", typesBySize);
assertTrue("expected at least 8 types: " + typesBySize, typesBySize.size() >= 8);
@SuppressWarnings({"unchecked"})
Map<String, Object> summary =
(Map<String, Object>) rawSizeMap.get(IndexSizeEstimator.SUMMARY);
Map<String, Object> summary = rawSize.summary;
assertNotNull("summary missing", summary);
assertEquals(summary.toString(), fields.size(), summary.size());
fields.forEach(field -> assertNotNull("missing field " + field, summary.get(field)));
@SuppressWarnings({"unchecked"})
Map<String, Object> details =
(Map<String, Object>) rawSizeMap.get(IndexSizeEstimator.DETAILS);
Map<String, Object> details = (Map<String, Object>) rawSize.details;
assertNotNull("details missing", summary);
assertEquals(details.keySet().toString(), 6, details.size());

// compare with sampled
@SuppressWarnings({"unchecked"})
NamedList<Object> sampledRawSize =
(NamedList<Object>)
rsp.getResponse()
.findRecursive(
collection, "shards", "shard" + i, "leader", "segInfos", "rawSize");
final var sampledRawSize = rawSize;
assertNotNull("sampled rawSize missing", sampledRawSize);
@SuppressWarnings({"unchecked"})
Map<String, Object> sampledRawSizeMap = rawSize.asMap(10);
@SuppressWarnings({"unchecked"})
Map<String, Object> sampledFieldsBySize =
(Map<String, Object>) sampledRawSizeMap.get(IndexSizeEstimator.FIELDS_BY_SIZE);
Map<String, String> sampledFieldsBySize = sampledRawSize.fieldsBySize;
assertNotNull("sampled fieldsBySize missing", sampledFieldsBySize);
fieldsBySize.forEach(
(k, v) -> {
double size = fromHumanReadableUnits((String) v);
double sampledSize = fromHumanReadableUnits((String) sampledFieldsBySize.get(k));
double size = fromHumanReadableUnits(v);
double sampledSize = fromHumanReadableUnits(sampledFieldsBySize.get(k));
double delta = size * 0.5;
assertEquals("sampled size of " + k + " is wildly off", size, sampledSize, delta);
});
Expand Down

0 comments on commit b2c1690

Please sign in to comment.