use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class RecoveryAfterSoftCommitTest method test.
@Test
public void test() throws Exception {
waitForRecoveriesToFinish(DEFAULT_COLLECTION, true);
// flush twice
int i = 0;
for (; i < MAX_BUFFERED_DOCS + 1; i++) {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", String.valueOf(i));
document.addField("a_t", "text_" + i);
cloudClient.add(document);
}
// soft-commit so searchers are open on un-committed but flushed segment files
AbstractUpdateRequest request = new UpdateRequest().setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true, true);
cloudClient.request(request);
Replica notLeader = ensureAllReplicasAreActive(DEFAULT_COLLECTION, "shard1", 1, 2, 30).get(0);
// ok, now introduce a network partition between the leader and the replica
SocketProxy proxy = getProxyForReplica(notLeader);
proxy.close();
// add more than ULOG_NUM_RECORDS_TO_KEEP docs so that peer sync cannot be used for recovery
int MAX_DOCS = 2 + MAX_BUFFERED_DOCS + ULOG_NUM_RECORDS_TO_KEEP;
for (; i < MAX_DOCS; i++) {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", String.valueOf(i));
document.addField("a_t", "text_" + i);
cloudClient.add(document);
}
// Have the partition last at least 1 sec
// While this gives the impression that recovery is timing related, this is
// really only
// to give time for the state to be written to ZK before the test completes.
// In other words,
// without a brief pause, the test finishes so quickly that it doesn't give
// time for the recovery process to kick-in
Thread.sleep(2000L);
proxy.reopen();
List<Replica> notLeaders = ensureAllReplicasAreActive(DEFAULT_COLLECTION, "shard1", 1, 2, 30);
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class MissingSegmentRecoveryTest method setup.
@Before
public void setup() throws SolrServerException, IOException {
CollectionAdminRequest.createCollection(collection, "conf", 1, 2).setMaxShardsPerNode(1).process(cluster.getSolrClient());
waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
cluster.getSolrClient().setDefaultCollection(collection);
List<SolrInputDocument> docs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
docs.add(doc);
}
cluster.getSolrClient().add(docs);
cluster.getSolrClient().commit();
DocCollection state = getCollectionState(collection);
leader = state.getLeader("shard1");
replica = getRandomReplica(state.getSlice("shard1"), (r) -> leader != r);
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class LeaderFailureAfterFreshStartTest method indexDoc.
protected void indexDoc(Object... fields) throws IOException, SolrServerException {
SolrInputDocument doc = new SolrInputDocument();
addFields(doc, fields);
addFields(doc, "rnd_s", RandomStringUtils.random(random().nextInt(100) + 100));
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
ModifiableSolrParams params = new ModifiableSolrParams();
ureq.setParams(params);
ureq.process(cloudClient);
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class SegmentTerminateEarlyTestState method addDocuments.
void addDocuments(CloudSolrClient cloudSolrClient, int numCommits, int numDocsPerCommit, boolean optimize) throws Exception {
for (int cc = 1; cc <= numCommits; ++cc) {
for (int nn = 1; nn <= numDocsPerCommit; ++nn) {
++numDocs;
final Integer docKey = new Integer(numDocs);
SolrInputDocument doc = new SolrInputDocument();
doc.setField(KEY_FIELD, "" + docKey);
// minutes
final int MM = rand.nextInt(60);
if (minTimestampMM == null || MM <= minTimestampMM.intValue()) {
if (minTimestampMM != null && MM < minTimestampMM.intValue()) {
minTimestampDocKeys.clear();
}
minTimestampMM = new Integer(MM);
minTimestampDocKeys.add(docKey);
}
if (maxTimestampMM == null || maxTimestampMM.intValue() <= MM) {
if (maxTimestampMM != null && maxTimestampMM.intValue() < MM) {
maxTimestampDocKeys.clear();
}
maxTimestampMM = new Integer(MM);
maxTimestampDocKeys.add(docKey);
}
doc.setField(TIMESTAMP_FIELD, (Integer) MM);
doc.setField(ODD_FIELD, "" + (numDocs % 2));
doc.setField(QUAD_FIELD, "" + (numDocs % 4) + 1);
cloudSolrClient.add(doc);
}
cloudSolrClient.commit();
}
if (optimize) {
cloudSolrClient.optimize();
}
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class BlobRepositoryCloudTest method setupCluster.
@BeforeClass
public static void setupCluster() throws Exception {
// only sharing *within* a node
configureCluster(1).addConfig("configname", TEST_PATH.resolve("resource-sharing")).configure();
// Thread.sleep(2000);
HashMap<String, String> params = new HashMap<>();
CollectionAdminRequest.createCollection(".system", null, 1, 1).process(cluster.getSolrClient());
// test component will fail if it cant' find a blob with this data by this name
TestBlobHandler.postData(cluster.getSolrClient(), findLiveNodeURI(), "testResource", ByteBuffer.wrap("foo,bar\nbaz,bam".getBytes(StandardCharsets.UTF_8)));
// Thread.sleep(2000);
// if these don't load we probably failed to post the blob above
CollectionAdminRequest.createCollection("col1", "configname", 1, 1).process(cluster.getSolrClient());
CollectionAdminRequest.createCollection("col2", "configname", 1, 1).process(cluster.getSolrClient());
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "1");
document.addField("text", "col1");
CloudSolrClient solrClient = cluster.getSolrClient();
solrClient.add("col1", document);
solrClient.commit("col1");
document = new SolrInputDocument();
document.addField("id", "1");
document.addField("text", "col2");
solrClient.add("col2", document);
solrClient.commit("col2");
Thread.sleep(2000);
}
Aggregations