use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class TestUpdate method testUpdateLogThrowsForUnknownTypes.
// SOLR-8866
@Test
public void testUpdateLogThrowsForUnknownTypes() throws IOException {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "444");
//Object shouldn't be serialized later...
doc.addField("text", new Object());
AddUpdateCommand cmd = new AddUpdateCommand(req());
cmd.solrDoc = doc;
try {
// should throw
h.getCore().getUpdateHandler().addDoc(cmd);
} catch (SolrException e) {
if (e.getMessage().contains("serialize")) {
//passed test
return;
}
throw e;
}
fail();
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class UpdateLogTest method testApplyPartialUpdatesDependingOnNonAddShouldThrowException.
@Test
public void testApplyPartialUpdatesDependingOnNonAddShouldThrowException() {
ulogAdd(ulog, null, sdoc("id", "1", "title_s", "title1", "val1_i_dvo", "1", "_version_", "100"));
// dbi
ulogDelete(ulog, "1", 500L, false);
ulogAdd(ulog, 500L, sdoc("id", "1", "val1_i_dvo", "2", "_version_", "501"));
ulogAdd(ulog, 501L, sdoc("id", "1", "val1_i_dvo", "3", "_version_", "502"));
Object partialUpdate = ulog.lookup(DOC_1_INDEXED_ID);
SolrDocument partialDoc = RealTimeGetComponent.toSolrDoc((SolrInputDocument) ((List) partialUpdate).get(4), h.getCore().getLatestSchema());
long prevVersion = (Long) ((List) partialUpdate).get(3);
long prevPointer = (Long) ((List) partialUpdate).get(2);
assertEquals(3L, ((NumericDocValuesField) partialDoc.getFieldValue("val1_i_dvo")).numericValue());
assertEquals(502L, ((NumericDocValuesField) partialDoc.getFieldValue("_version_")).numericValue());
assertFalse(partialDoc.containsKey("title_s"));
// If an in-place update depends on a non-add (i.e. DBI), assert that an exception is thrown.
SolrException ex = expectThrows(SolrException.class, () -> {
long returnVal = ulog.applyPartialUpdates(DOC_1_INDEXED_ID, prevPointer, prevVersion, null, partialDoc);
fail("502 depends on 501, 501 depends on 500, but 500 is a" + " DELETE. This should've generated an exception. returnVal is: " + returnVal);
});
assertEquals(ex.toString(), SolrException.ErrorCode.INVALID_STATE.code, ex.code());
assertThat(ex.getMessage(), containsString("should've been either ADD or UPDATE_INPLACE"));
assertThat(ex.getMessage(), containsString("looking for id=1"));
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class ClassificationUpdateProcessorFactoryTest method init_unsupportedFilterQuery_shouldThrowExceptionWithDetailedMessage.
@Test
public void init_unsupportedFilterQuery_shouldThrowExceptionWithDetailedMessage() {
UpdateRequestProcessor mockProcessor = mock(UpdateRequestProcessor.class);
SolrQueryRequest mockRequest = mock(SolrQueryRequest.class);
SolrQueryResponse mockResponse = mock(SolrQueryResponse.class);
args.add("knn.filterQuery", "not supported query");
try {
cFactoryToTest.init(args);
/* parsing failure happens because of the mocks, fine enough to check a proper exception propagation */
cFactoryToTest.getInstance(mockRequest, mockResponse, mockProcessor);
} catch (SolrException e) {
assertEquals("Classification UpdateProcessor Training Filter Query: 'not supported query' is not supported", e.getMessage());
}
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class SolrExampleTests method testUpdateField.
@Test
public void testUpdateField() throws Exception {
//no versions
SolrClient client = getSolrClient();
client.deleteByQuery("*:*");
client.commit();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("name", "gadget");
doc.addField("price", 1);
client.add(doc);
client.commit();
SolrQuery q = new SolrQuery("*:*");
q.setFields("id", "price", "name", "_version_");
QueryResponse resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
Long version = (Long) resp.getResults().get(0).getFirstValue("_version_");
assertNotNull("no version returned", version);
assertEquals(1.0f, resp.getResults().get(0).getFirstValue("price"));
//update "price" with incorrect version (optimistic locking)
//need better api for this???
HashMap<String, Object> oper = new HashMap<>();
oper.put("set", 100);
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("_version_", version + 1);
doc.addField("price", oper);
try {
client.add(doc);
if (client instanceof HttpSolrClient) {
//XXX concurrent client reports exceptions differently
fail("Operation should throw an exception!");
} else {
//just to be sure the client has sent the doc
client.commit();
ErrorTrackingConcurrentUpdateSolrClient concurrentClient = (ErrorTrackingConcurrentUpdateSolrClient) client;
assertNotNull("ConcurrentUpdateSolrClient did not report an error", concurrentClient.lastError);
assertTrue("ConcurrentUpdateSolrClient did not report an error", concurrentClient.lastError.getMessage().contains("Conflict"));
}
} catch (SolrException se) {
assertTrue("No identifiable error message", se.getMessage().contains("version conflict for unique"));
}
//update "price", use correct version (optimistic locking)
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("_version_", version);
doc.addField("price", oper);
client.add(doc);
client.commit();
resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
assertEquals("price was not updated?", 100.0f, resp.getResults().get(0).getFirstValue("price"));
assertEquals("no name?", "gadget", resp.getResults().get(0).getFirstValue("name"));
//update "price", no version
oper.put("set", 200);
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("price", oper);
client.add(doc);
client.commit();
resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
assertEquals("price was not updated?", 200.0f, resp.getResults().get(0).getFirstValue("price"));
assertEquals("no name?", "gadget", resp.getResults().get(0).getFirstValue("name"));
}
use of org.apache.solr.common.SolrException in project lucene-solr by apache.
the class ZkStateReader method createClusterStateWatchersAndUpdate.
public synchronized void createClusterStateWatchersAndUpdate() throws KeeperException, InterruptedException {
// We need to fetch the current cluster state and the set of live nodes
LOG.debug("Updating cluster state from ZooKeeper... ");
// Sanity check ZK structure.
if (!zkClient.exists(CLUSTER_STATE, true)) {
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Cannot connect to cluster at " + zkClient.getZkServerAddress() + ": cluster not found/not ready");
}
// on reconnect of SolrZkClient force refresh and re-add watches.
loadClusterProperties();
refreshLiveNodes(new LiveNodeWatcher());
refreshLegacyClusterState(new LegacyClusterStateWatcher());
refreshStateFormat2Collections();
refreshCollectionList(new CollectionsChildWatcher());
synchronized (ZkStateReader.this.getUpdateLock()) {
constructState(Collections.emptySet());
zkClient.exists(ALIASES, new Watcher() {
@Override
public void process(WatchedEvent event) {
// session events are not change events, and do not remove the watcher
if (EventType.None.equals(event.getType())) {
return;
}
try {
synchronized (ZkStateReader.this.getUpdateLock()) {
LOG.debug("Updating aliases... ");
// remake watch
final Watcher thisWatch = this;
final Stat stat = new Stat();
final byte[] data = zkClient.getData(ALIASES, thisWatch, stat, true);
ZkStateReader.this.aliases = ClusterState.load(data);
LOG.debug("New alias definition is: " + ZkStateReader.this.aliases.toString());
}
} catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) {
LOG.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: [{}]", e.getMessage());
} catch (KeeperException e) {
LOG.error("A ZK error has occurred", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "A ZK error has occurred", e);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
LOG.warn("Interrupted", e);
}
}
}, true);
}
updateAliases();
if (securityNodeListener != null) {
addSecuritynodeWatcher(pair -> {
ConfigData cd = new ConfigData();
cd.data = pair.first() == null || pair.first().length == 0 ? EMPTY_MAP : Utils.getDeepCopy((Map) fromJSON(pair.first()), 4, false);
cd.version = pair.second() == null ? -1 : pair.second().getVersion();
securityData = cd;
securityNodeListener.run();
});
securityData = getSecurityProps(true);
}
}
Aggregations