use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class DistributedVersionInfoTest method assertDocExists.
/**
* Query the real-time get handler for a specific doc by ID to verify it
* exists in the provided server, using distrib=false so it doesn't route to another replica.
*/
@SuppressWarnings("rawtypes")
protected Long assertDocExists(HttpSolrClient solr, String coll, String docId, Long expVers) throws Exception {
QueryRequest qr = new QueryRequest(params("qt", "/get", "id", docId, "distrib", "false", "fl", "id,_version_"));
NamedList rsp = solr.request(qr);
SolrDocument doc = (SolrDocument) rsp.get("doc");
String match = JSONTestUtil.matchObj("/id", doc, docId);
assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL() + " due to: " + match + "; rsp=" + rsp, match == null);
Long vers = (Long) doc.getFirstValue("_version_");
assertNotNull(vers);
if (expVers != null)
assertEquals("expected version of doc " + docId + " to be " + expVers, expVers, vers);
return vers;
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class HttpPartitionTest method assertDocNotExists.
protected void assertDocNotExists(HttpSolrClient solr, String coll, String docId) throws Exception {
NamedList rsp = realTimeGetDocId(solr, docId);
String match = JSONTestUtil.matchObj("/id", rsp.get("doc"), new Integer(docId));
assertTrue("Doc with id=" + docId + " is found in " + solr.getBaseURL() + " due to: " + match + "; rsp=" + rsp, match != null);
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class CdcrReplicationDistributedZkTest method testTargetCollectionNotAvailable.
@Test
@ShardsFixed(num = 4)
public void testTargetCollectionNotAvailable() throws Exception {
// send start action to first shard
NamedList rsp = invokeCdcrAction(shardToLeaderJetty.get(SOURCE_COLLECTION).get(SHARD1), CdcrParams.CdcrAction.START);
NamedList status = (NamedList) rsp.get(CdcrParams.CdcrAction.STATUS.toLower());
assertEquals(CdcrParams.ProcessState.STARTED.toLower(), status.get(CdcrParams.ProcessState.getParam()));
// check status
this.assertState(SOURCE_COLLECTION, CdcrParams.ProcessState.STARTED, CdcrParams.BufferState.ENABLED);
this.waitForBootstrapToComplete(TARGET_COLLECTION, SHARD2);
// sleep for a bit to ensure that replicator threads are started
Thread.sleep(3000);
// Kill all the servers of the target
this.deleteCollection(TARGET_COLLECTION);
// Index a few documents to trigger the replication
index(SOURCE_COLLECTION, getDoc(id, "a"));
index(SOURCE_COLLECTION, getDoc(id, "b"));
index(SOURCE_COLLECTION, getDoc(id, "c"));
index(SOURCE_COLLECTION, getDoc(id, "d"));
index(SOURCE_COLLECTION, getDoc(id, "e"));
index(SOURCE_COLLECTION, getDoc(id, "f"));
assertNumDocs(6, SOURCE_COLLECTION);
// we need to wait until the replicator thread is triggered
// timeout after 15 seconds
int cnt = 15;
AssertionError lastAssertionError = null;
while (cnt > 0) {
try {
rsp = invokeCdcrAction(shardToLeaderJetty.get(SOURCE_COLLECTION).get(SHARD2), CdcrParams.CdcrAction.ERRORS);
NamedList collections = (NamedList) ((NamedList) rsp.get(CdcrParams.ERRORS)).getVal(0);
NamedList errors = (NamedList) collections.get(TARGET_COLLECTION);
assertTrue(0 < (Long) errors.get(CdcrParams.CONSECUTIVE_ERRORS));
NamedList lastErrors = (NamedList) errors.get(CdcrParams.LAST);
assertNotNull(lastErrors);
assertTrue(0 < lastErrors.size());
return;
} catch (AssertionError e) {
lastAssertionError = e;
cnt--;
Thread.sleep(1000);
}
}
throw new AssertionError("Timeout while trying to assert replication errors", lastAssertionError);
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testCreateAndDeleteCollection.
@Test
public void testCreateAndDeleteCollection() throws Exception {
String collectionName = "solrj_test";
CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(1).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
assertEquals(4, coresStatus.size());
for (int i = 0; i < 4; i++) {
NamedList<Integer> status = coresStatus.get(Assign.buildCoreName(collectionName, "shard" + (i / 2 + 1), Replica.Type.NRT, (i % 2 + 1)));
assertEquals(0, (int) status.get("status"));
assertTrue(status.get("QTime") > 0);
}
response = CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
Map<String, NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
assertEquals(4, nodesStatus.size());
waitForState("Expected " + collectionName + " to disappear from cluster state", collectionName, (n, c) -> c == null);
// Test Creating a collection with new stateformat.
collectionName = "solrj_newstateformat";
response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(2).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
waitForState("Expected " + collectionName + " to appear in cluster state", collectionName, (n, c) -> c != null);
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class TestCollectionAPI method clusterStatusNoCollection.
private void clusterStatusNoCollection() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(COLLECTION_NAME1));
assertEquals(4, collections.size());
List<String> liveNodes = (List<String>) cluster.get("live_nodes");
assertNotNull("Live nodes should not be null", liveNodes);
assertFalse(liveNodes.isEmpty());
}
}
Aggregations