Java Code Examples for org.apache.solr.client.solrj.SolrClient#close()
The following examples show how to use
org.apache.solr.client.solrj.SolrClient#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestQuerySolr.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testSingleFilterQuery() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc"); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty("fq", "id:(doc2 OR doc3)"); runner.enqueue(new byte[0]); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 1); String expectedXml = "<docs><doc><field name=\"id\">doc2</field></doc><doc><field name=\"id\">doc3</field></doc></docs>"; assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0))))); solrClient.close(); }
Example 2
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testStandardResponse() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_QUERY, "id:(doc0 OR doc1)"); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id desc"); runner.setNonLoopConnection(false); runner.run(); runner.assertAllFlowFilesTransferred(QuerySolr.RESULTS, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); String expectedXml = "<docs><doc boost=\"1.0\"><field name=\"id\">doc1</field></doc><doc boost=\"1.0\"><field name=\"id\">doc0</field></doc></docs>"; assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(flowFile)))); solrClient.close(); }
Example 3
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testSingleFilterQuery() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc"); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty("fq", "id:(doc2 OR doc3)"); runner.enqueue(new byte[0]); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 1); String expectedXml = "<docs><doc boost=\"1.0\"><field name=\"id\">doc2</field></doc><doc boost=\"1.0\"><field name=\"id\">doc3</field></doc></docs>"; assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0))))); solrClient.close(); }
Example 4
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testPreserveOriginalContent() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_QUERY, "id:doc0"); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); String content = "test content 123"; runner.enqueue(content); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 1); runner.assertTransferCount(QuerySolr.ORIGINAL, 1); String expectedXml = "<docs><doc boost=\"1.0\"><field name=\"id\">doc0</field></doc></docs>"; assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0))))); assertEquals(content, new String(runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.ORIGINAL).get(0)))); solrClient.close(); }
Example 5
Source File: TestQuerySolr.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testRetrievalOfFullResults2() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc"); runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "3"); runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS); runner.setProperty("facet", "true"); runner.setProperty("stats", "true"); runner.enqueue(new byte[0]); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 4); runner.assertTransferCount(QuerySolr.ORIGINAL, 1); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); solrClient.close(); }
Example 6
Source File: SolrLocatorTest.java From kite with Apache License 2.0 | 6 votes |
@Test public void testSelectsEmbeddedSolrServerAndAddDocument() throws Exception { //Solr locator should select EmbeddedSolrServer only solrHome is specified SolrLocator solrLocator = new SolrLocator(new SolrMorphlineContext.Builder().build()); solrLocator.setSolrHomeDir(RESOURCES_DIR + "/solr"); solrLocator.setCollectionName("collection1"); SolrServerDocumentLoader documentLoader = (SolrServerDocumentLoader)solrLocator.getLoader(); SolrClient solrServer = documentLoader.getSolrServer(); assertTrue(solrServer instanceof EmbeddedSolrServer); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "myId"); doc.addField("text", "myValue"); solrServer.add(doc); solrServer.commit(); SolrDocument resultDoc = solrServer.getById("myId"); assertTrue(resultDoc.getFieldValues("text").contains("myValue")); UpdateResponse deleteResponse = solrServer.deleteById("myId"); assertEquals(0, deleteResponse.getStatus()); solrServer.commit(); solrServer.close(); }
Example 7
Source File: Indexing.java From jate with GNU Lesser General Public License v3.0 | 6 votes |
public static void main(String[] args) throws IOException, JATEException, SolrServerException { Logger logger = Logger.getLogger(Indexing.class.getName()); JATEProperties prop = new JATEProperties(args[0]); boolean deletePrevious = Boolean.valueOf(args[2]); SolrClient solrClient = new EmbeddedSolrServer(Paths.get(args[3]), args[4]); try { if (deletePrevious) { logger.info("DELETING PREVIOUS INDEX"); solrClient.deleteByQuery("*:*"); solrClient.commit(); } logger.info("INDEXING BEGINS"); IndexingHandler m = new IndexingHandler(); List<String> files = new ArrayList<>(); for (File f : new File(args[1]).listFiles()) files.add(f.toString()); m.index(files, prop.getIndexerMaxUnitsToCommit(), new TikaSimpleDocumentCreator(), solrClient, prop); logger.info("INDEXING COMPLETE"); System.exit(0); } finally { solrClient.close(); } }
Example 8
Source File: TestConfigSetsAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testDelete() throws Exception { final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); final SolrClient solrClient = getHttpSolrClient(baseUrl); final String configSet = "configSet"; solrCluster.uploadConfigSet(configset("configset-2"), configSet); SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null); try { ZkConfigManager configManager = new ZkConfigManager(zkClient); assertTrue(configManager.configExists(configSet)); Delete delete = new Delete(); delete.setConfigSetName(configSet); ConfigSetAdminResponse response = delete.process(solrClient); assertNotNull(response.getResponse()); assertFalse(configManager.configExists(configSet)); } finally { zkClient.close(); } solrClient.close(); }
Example 9
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testMultipleFilterQueries() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc"); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty("fq.1", "id:(doc0 OR doc1 OR doc2 OR doc3)"); runner.setProperty("fq.2", "id:(doc1 OR doc2 OR doc3 OR doc4)"); runner.setProperty("fq.3", "id:(doc2 OR doc3 OR doc4 OR doc5)"); runner.enqueue(new byte[0]); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 1); String expectedXml = "<docs><doc boost=\"1.0\"><field name=\"id\">doc2</field></doc><doc boost=\"1.0\"><field name=\"id\">doc3</field></doc></docs>"; assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0))))); solrClient.close(); }
Example 10
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testRetrievalOfFullResults3() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc"); runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "3"); runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS); runner.setProperty("facet", "true"); runner.setProperty("stats", "true"); runner.setNonLoopConnection(false); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 4); runner.assertTransferCount(QuerySolr.ORIGINAL, 0); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); solrClient.close(); }
Example 11
Source File: TestSolrCloudWithDelegationTokens.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked"}) private int getStatusCode(String token, final String user, final String op, HttpSolrClient client) throws Exception { SolrClient delegationTokenClient; if (random().nextBoolean()) delegationTokenClient = new HttpSolrClient.Builder(client.getBaseURL().toString()) .withKerberosDelegationToken(token) .withResponseParser(client.getParser()) .build(); else delegationTokenClient = new CloudSolrClient.Builder(Collections.singletonList(miniCluster.getZkServer().getZkAddress()), Optional.empty()) .withLBHttpSolrClientBuilder(new LBHttpSolrClient.Builder() .withSocketTimeout(30000).withConnectionTimeout(15000) .withResponseParser(client.getParser()) .withHttpSolrClientBuilder( new HttpSolrClient.Builder() .withKerberosDelegationToken(token) )) .build(); try { ModifiableSolrParams p = new ModifiableSolrParams(); if (user != null) p.set(USER_PARAM, user); if (op != null) p.set("op", op); @SuppressWarnings({"rawtypes"}) SolrRequest req = getAdminRequest(p); if (user != null || op != null) { Set<String> queryParams = new HashSet<>(); if (user != null) queryParams.add(USER_PARAM); if (op != null) queryParams.add("op"); req.setQueryParams(queryParams); } try { delegationTokenClient.request(req, null); return HttpStatus.SC_OK; } catch (BaseHttpSolrClient.RemoteSolrException re) { return re.code(); } } finally { delegationTokenClient.close(); } }
Example 12
Source File: TestQuerySolr.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testRetrievalOfFullResults() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id"); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc"); runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "2"); runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS); runner.enqueue(new byte[0]); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 5); runner.assertTransferCount(QuerySolr.ORIGINAL, 1); runner.assertTransferCount(QuerySolr.STATS, 0); runner.assertTransferCount(QuerySolr.FACETS, 0); List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(QuerySolr.RESULTS); Integer documentCounter = 0; Integer startParam = 0; for (MockFlowFile flowFile : flowFiles) { Map<String,String> attributes = flowFile.getAttributes(); assertEquals(attributes.get(QuerySolr.ATTRIBUTE_SOLR_START), startParam.toString()); startParam += 2; StringBuffer expectedXml = new StringBuffer() .append("<docs><doc><field name=\"id\">doc") .append(documentCounter++) .append("</field></doc><doc><field name=\"id\">doc") .append(documentCounter++) .append("</field></doc></docs>"); assertThat(expectedXml.toString(), CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(flowFile)))); } solrClient.close(); }
Example 13
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testStats() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty("stats", "true"); runner.setProperty("stats.field", "integer_single"); runner.enqueue(new ByteArrayInputStream(new byte[0])); runner.run(); runner.assertTransferCount(QuerySolr.STATS, 1); JsonReader reader = new JsonReader(new InputStreamReader(new ByteArrayInputStream( runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0))))); reader.beginObject(); assertEquals(reader.nextName(), "stats_fields"); reader.beginObject(); assertEquals(reader.nextName(), "integer_single"); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case "min": assertEquals(reader.nextString(), "0.0"); break; case "max": assertEquals(reader.nextString(), "9.0"); break; case "count": assertEquals(reader.nextInt(), 10); break; case "sum": assertEquals(reader.nextString(), "45.0"); break; default: reader.skipValue(); break; } } reader.endObject(); reader.endObject(); reader.endObject(); reader.close(); solrClient.close(); }
Example 14
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testExpressionLanguageForProperties() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty(SolrUtils.SOLR_TYPE, SolrUtils.SOLR_TYPE_CLOUD.getValue()); runner.setProperty(QuerySolr.SOLR_PARAM_QUERY, "${query}"); runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "${handler}"); runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "${fields}"); runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "${sort}"); runner.setProperty(QuerySolr.SOLR_PARAM_START, "${start}"); runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "${rows}"); runner.enqueue(new byte[0], new HashMap<String,String>(){{ put("query", "id:(doc0 OR doc1 OR doc2 OR doc3)"); put("handler", "/select"); put("fields", "id"); put("sort", "id desc"); put("start", "1"); put("rows", "2"); }}); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 1); String expectedXml = "<docs><doc boost=\"1.0\"><field name=\"id\">doc2</field></doc><doc boost=\"1.0\"><field name=\"id\">doc1</field></doc></docs>"; assertThat(expectedXml, CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0))))); solrClient.close(); }
Example 15
Source File: DirectSolrClassicInputDocumentWriter.java From hbase-indexer with Apache License 2.0 | 5 votes |
@Override public void close() { for (SolrClient server : solrServers) { try { server.close(); } catch (java.io.IOException e) { throw new RuntimeException(e); } } }
Example 16
Source File: TestQuerySolr.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testFacetTrueButNull() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty("facet", "true"); runner.setProperty("stats", "true"); runner.enqueue(new ByteArrayInputStream(new byte[0])); runner.run(); runner.assertTransferCount(QuerySolr.RESULTS, 1); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); // Check for empty nestet Objects in JSON JsonReader reader = new JsonReader(new InputStreamReader(new ByteArrayInputStream( runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0))))); reader.beginObject(); while (reader.hasNext()) { if (reader.nextName().equals("facet_queries")) { reader.beginArray(); assertFalse(reader.hasNext()); reader.endArray(); } else { reader.beginObject(); assertFalse(reader.hasNext()); reader.endObject(); } } reader.endObject(); JsonReader reader_stats = new JsonReader(new InputStreamReader(new ByteArrayInputStream( runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0))))); reader_stats.beginObject(); assertEquals(reader_stats.nextName(), "stats_fields"); reader_stats.beginObject(); assertFalse(reader_stats.hasNext()); reader_stats.endObject(); reader_stats.endObject(); reader.close(); reader_stats.close(); solrClient.close(); }
Example 17
Source File: QuerySolrIT.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testAllFacetCategories() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty("facet", "true"); runner.setProperty("facet.field", "integer_multi"); runner.setProperty("facet.interval", "integer_single"); runner.setProperty("facet.interval.set.1", "[4,7]"); runner.setProperty("facet.interval.set.2", "[5,7]"); runner.setProperty("facet.range", "created"); runner.setProperty("facet.range.start", "NOW/MINUTE"); runner.setProperty("facet.range.end", "NOW/MINUTE+1MINUTE"); runner.setProperty("facet.range.gap", "+20SECOND"); runner.setProperty("facet.query.1", "*:*"); runner.setProperty("facet.query.2", "integer_multi:2"); runner.setProperty("facet.query.3", "integer_multi:3"); runner.enqueue(new ByteArrayInputStream(new byte[0])); runner.run(); runner.assertTransferCount(QuerySolr.FACETS, 1); JsonReader reader = new JsonReader(new InputStreamReader(new ByteArrayInputStream( runner.getContentAsByteArray(runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0))))); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("facet_queries")) { assertEquals(30, returnCheckSumForArrayOfJsonObjects(reader)); } else if (name.equals("facet_fields")) { reader.beginObject(); assertEquals(reader.nextName(), "integer_multi"); assertEquals(returnCheckSumForArrayOfJsonObjects(reader), 30); reader.endObject(); } else if (name.equals("facet_ranges")) { reader.beginObject(); assertEquals(reader.nextName(), "created"); assertEquals(returnCheckSumForArrayOfJsonObjects(reader), 10); reader.endObject(); } else if (name.equals("facet_intervals")) { reader.beginObject(); assertEquals(reader.nextName(), "integer_single"); assertEquals(returnCheckSumForArrayOfJsonObjects(reader), 7); reader.endObject(); } } reader.endObject(); reader.close(); solrClient.close(); }
Example 18
Source File: RetryingSolrServerTest.java From kite with Apache License 2.0 | 4 votes |
@Test public void testRetries() throws Exception { new DefaultRetryPolicyFactory(); SolrQuery query = getDefaultQuery(); FailingSolrServer failingSolrServer = new FailingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer( failingSolrServer, new DefaultRetryPolicyFactory(new FlexibleBoundedExponentialBackoffRetry( TimeUnit.MILLISECONDS.toNanos(1), TimeUnit.MILLISECONDS.toNanos(1000), 20, TimeUnit.MINUTES.toNanos(5))), getMetricsFacade() ); Assert.assertNotNull(solr.query(query)); Assert.assertEquals(FailingSolrServer.SUCCESS, failingSolrServer.getNumRequests()); Assert.assertEquals(FailingSolrServer.SUCCESS - 1, failingSolrServer.getNumInjectedFailures()); solr.query(query); Assert.assertEquals(FailingSolrServer.SUCCESS + 1, failingSolrServer.getNumRequests()); Assert.assertEquals(FailingSolrServer.SUCCESS - 1, failingSolrServer.getNumInjectedFailures()); failingSolrServer.reset(); Assert.assertNotNull(solr.query(query)); Assert.assertEquals(FailingSolrServer.SUCCESS, failingSolrServer.getNumRequests()); Assert.assertEquals(FailingSolrServer.SUCCESS - 1, failingSolrServer.getNumInjectedFailures()); solr.query(query); Assert.assertEquals(FailingSolrServer.SUCCESS + 1, failingSolrServer.getNumRequests()); Assert.assertEquals(FailingSolrServer.SUCCESS - 1, failingSolrServer.getNumInjectedFailures()); // verify that after shutdown() is called, requests fail immediately without retries failingSolrServer.reset(); solr.close(); try { solr.query(query); fail(); } catch (RetriesExhaustedException e) { assertTrue(e.getCause() instanceof FailingSolrServer.InjectedSolrServerException); Assert.assertEquals(1, failingSolrServer.getNumRequests()); Assert.assertEquals(1, failingSolrServer.getNumInjectedFailures()); } }
Example 19
Source File: TestQuerySolr.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testRelationshipRoutings() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty("facet", "true"); runner.setProperty("stats", "true"); // Set request handler for request failure runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/nonexistentrequesthandler"); // Processor has no input connection and fails runner.setNonLoopConnection(false); runner.run(1, false); runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0); flowFile.assertAttributeExists(QuerySolr.EXCEPTION); flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE); runner.clearTransferState(); // Processor has an input connection and fails runner.setNonLoopConnection(true); runner.enqueue(new byte[0]); runner.run(1, false); runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1); flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0); flowFile.assertAttributeExists(QuerySolr.EXCEPTION); flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE); runner.clearTransferState(); // Set request handler for successful request runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/select"); // Processor has no input connection and succeeds runner.setNonLoopConnection(false); runner.run(1, false); runner.assertTransferCount(QuerySolr.RESULTS, 1); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); runner.clearTransferState(); // Processor has an input connection and succeeds runner.setNonLoopConnection(true); runner.enqueue(new byte[0]); runner.run(1, true); runner.assertTransferCount(QuerySolr.RESULTS, 1); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); runner.assertTransferCount(QuerySolr.ORIGINAL, 1); runner.assertAllFlowFilesContainAttribute(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); flowFile = runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); flowFile = runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); runner.clearTransferState(); solrClient.close(); }
Example 20
Source File: TestConfigSetsAPI.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testUploadErrors() throws Exception { final SolrClient solrClient = getHttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); ByteBuffer emptyData = ByteBuffer.allocate(0); // Checking error when no configuration name is specified in request @SuppressWarnings({"rawtypes"}) Map map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD", emptyData, null, null); assertNotNull(map); long statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status")); assertEquals(400l, statusCode); SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null); // Create dummy config files in zookeeper zkClient.makePath("/configs/myconf", true); zkClient.create("/configs/myconf/firstDummyFile", "first dummy content".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); zkClient.create("/configs/myconf/anotherDummyFile", "second dummy content".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); // Checking error when configuration name specified already exists map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD&name=myconf", emptyData, null, null); assertNotNull(map); statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status")); assertEquals(400l, statusCode); assertTrue("Expected file doesnt exist in zk. It's possibly overwritten", zkClient.exists("/configs/myconf/firstDummyFile", true)); assertTrue("Expected file doesnt exist in zk. It's possibly overwritten", zkClient.exists("/configs/myconf/anotherDummyFile", true)); zkClient.close(); solrClient.close(); }