diff --git a/pom.xml b/pom.xml index 70572fd..6cbd27b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,164 +1,164 @@ - 4.0.0 - com.plugtree - solrmeter-parent - Solrmeter parent POM - 0.3.1-SNAPSHOT - pom + 4.0.0 + com.plugtree + solrmeter-parent + Solrmeter parent POM + 0.3.1-SNAPSHOT + pom - - solrmeter - stressTestScope - + + solrmeter + stressTestScope + - - - Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0 - - + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + + - - https://github.com/tflobbe/solrmeter - scm:git:https://github.com/tflobbe/solrmeter.git - scm:git:https://github.com/tflobbe/solrmeter.git - + + https://github.com/tflobbe/solrmeter + scm:git:https://github.com/tflobbe/solrmeter.git + scm:git:https://github.com/tflobbe/solrmeter.git + - - - Google Group - http://groups.google.com/group/solrmeter/topics - solrmeter@googlegroups.com - http://groups.google.com/group/solrmeter/subscribe - http://groups.google.com/group/solrmeter/subscribe - - + + + Google Group + http://groups.google.com/group/solrmeter/topics + solrmeter@googlegroups.com + http://groups.google.com/group/solrmeter/subscribe + http://groups.google.com/group/solrmeter/subscribe + + - - Github issues - https://github.com/tflobbe/solrmeter/issues - + + Github issues + https://github.com/tflobbe/solrmeter/issues + - - Plugtree LLC - www.plugtree.com - + + Plugtree LLC + www.plugtree.com + - http://groups.google.com/group/solrmeter + http://groups.google.com/group/solrmeter - - - Tomás Fernández Löbbe - tflobbe@gmail.com - tflobbe - -3 - - - Juan Grande - juan.grande@gmail.com - jgrande - -3 - - - Emmanuel Espina - emmanuel.espina@plugtree.com - eespina - -3 - - + + + Tomás Fernández Löbbe + tflobbe@gmail.com + tflobbe + -3 + + + Juan Grande + juan.grande@gmail.com + jgrande + -3 + + + Emmanuel Espina + emmanuel.espina@plugtree.com + eespina + -3 + + - - UTF-8 - - - - - com.google.inject - guice - 2.0 - - - com.google.inject.extensions - guice-multibindings - 2.0 - - - com.plugtree - stressTestScope - 1.0.1-SNAPSHOT - - - org.slf4j - slf4j-api - 1.6.1 - - - org.slf4j - slf4j-log4j12 - 1.6.1 - - - solr-solrj - org.apache.solr - 3.6.1 - - - junit - junit - 3.8.1 - test - - - jfree - jfreechart - 1.0.3 - - - org.codehaus.castor - castor-xml - 1.3.0.1 - - - net.sf.opencsv - opencsv - 2.1 - - - org.mockito - mockito-core - 1.8.5 - test - - - commons-lang - commons-lang - 2.6 - - - commons-io - commons-io - 2.0.1 - - - org.apache.solr - solr-commons-csv - 3.5.0 - - - org.apache.httpcomponents - httpclient - 4.1.3 - - - org.apache.httpcomponents - httpmime - 4.0 - - - - - - + + UTF-8 + + + + + com.google.inject + guice + 2.0 + + + com.google.inject.extensions + guice-multibindings + 2.0 + + + com.plugtree + stressTestScope + 1.0.1-SNAPSHOT + + + org.slf4j + slf4j-api + 1.6.1 + + + org.slf4j + slf4j-log4j12 + 1.6.1 + + + solr-solrj + org.apache.solr + 8.11.1 + + + junit + junit + 3.8.1 + test + + + jfree + jfreechart + 1.0.3 + + + org.codehaus.castor + castor-xml + 1.3.0.1 + + + net.sf.opencsv + opencsv + 2.1 + + + org.mockito + mockito-core + 1.8.5 + test + + + commons-lang + commons-lang + 2.6 + + + commons-io + commons-io + 2.5 + + + org.apache.solr + solr-commons-csv + 3.5.0 + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + org.apache.httpcomponents + httpmime + 4.5.13 + + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -167,7 +167,7 @@ 1.8 1.8 true - lines,vars,source + lines,vars,source @@ -175,25 +175,25 @@ maven-assembly-plugin 2.2-beta-5 - - jar-with-dependencies - + + jar-with-dependencies + - - make-assembly - package - - single - - + + make-assembly + package + + single + + - - org.apache.maven.plugins - maven-release-plugin - 2.3.2 - + + org.apache.maven.plugins + maven-release-plugin + 2.3.2 + org.apache.maven.plugins maven-source-plugin @@ -276,74 +276,74 @@ - - - - - - - jenkins - - - jenkins - true - - - - - - - org.apache.maven.plugins - maven-jarsigner-plugin - 1.2 - - - sign - package - - sign - - - false - true - /private/plugtree-org/solrmeter-keystore - solrmeterKey - 123456 - 123456 - - - - - - - - do-all - - - do.all - true - - - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-site-plugin - - - - - + + + + + jenkins + + + jenkins + true + + + + + + + org.apache.maven.plugins + maven-jarsigner-plugin + 1.2 + + + sign + package + + sign + + + false + true + /private/plugtree-org/solrmeter-keystore + solrmeterKey + 123456 + 123456 + + + + + + + + + + do-all + + + do.all + true + + + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-site-plugin + + + + + diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/PreemptiveAuthInterceptor.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/PreemptiveAuthInterceptor.java new file mode 100644 index 0000000..585bdd8 --- /dev/null +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/PreemptiveAuthInterceptor.java @@ -0,0 +1,37 @@ +package com.plugtree.solrmeter.model; + +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.AuthState; +import org.apache.http.auth.Credentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpCoreContext; + +import java.io.IOException; + +class PreemptiveAuthInterceptor implements HttpRequestInterceptor { + + public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { + AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); + // If no auth scheme available yet, try to initialize it + // preemptively + if (authState.getAuthScheme() == null) { + CredentialsProvider credsProvider = (CredentialsProvider) + context.getAttribute(HttpClientContext.CREDS_PROVIDER); + HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); + AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); + Credentials creds = credsProvider.getCredentials(authScope); + if(creds == null){ + + } + authState.update(new BasicScheme(), creds); + } + + } +} \ No newline at end of file diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/QueryExecutor.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/QueryExecutor.java index 64d02bb..2da8004 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/QueryExecutor.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/QueryExecutor.java @@ -15,7 +15,7 @@ */ package com.plugtree.solrmeter.model; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.QueryResponse; import com.plugtree.solrmeter.model.exception.QueryException; @@ -27,17 +27,17 @@ public interface QueryExecutor { /** - * + * * @return The current Solr Server. If there is no current Solr Server, then the method returns a new one. */ - SolrServer getSolrServer(); + SolrClient getSolrServer(); /** * To be executed when a Query succeeds. * @param response */ void notifyQueryExecuted(QueryResponse response, - long clientTime); + long clientTime); /** * To be executed when a query fails @@ -73,8 +73,8 @@ void notifyQueryExecuted(QueryResponse response, void stop(); /** - * Set the number of operations expected per second - */ + * Set the number of operations expected per second + */ void setOperationsPerSecond(int newOperationsPerSecond); /** @@ -82,5 +82,5 @@ void notifyQueryExecuted(QueryResponse response, * @return */ boolean isRunning(); - + } \ No newline at end of file diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/SolrServerRegistry.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/SolrServerRegistry.java index 745a051..6937854 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/SolrServerRegistry.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/SolrServerRegistry.java @@ -15,15 +15,25 @@ */ package com.plugtree.solrmeter.model; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; import java.util.Map; +import org.apache.commons.lang.StringUtils; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.AbstractHttpClient; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient; /** - * This registry holds all the created solr servers. It will be one for each different url + * This registry holds all the created solr servers. It will be one for each different url * and it wont change between tests. * @author tflobbe * @@ -32,29 +42,42 @@ public class SolrServerRegistry { protected static final Logger logger = Logger.getLogger(SolrServerRegistry.class); - private static final Map servers = new HashMap(); + private static final Map servers = new HashMap(); - public static synchronized SolrServer getSolrServer(String url) { - SolrServer server = servers.get(url); + public static synchronized SolrClient getSolrServer(String url) { + SolrClient server = servers.get(url); if(server == null) { logger.info("Connecting to Solr: " + url); - HttpSolrServer httpServer = new HttpSolrServer(url); - httpServer.setSoTimeout(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.soTimeout", "60000"))); // socket read timeout - httpServer.setConnectionTimeout(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.connectionTimeout", "60000"))); - httpServer.setDefaultMaxConnectionsPerHost(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.defaultMaxConnectionsPerHost", "100000"))); - httpServer.setMaxTotalConnections(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.maxTotalConnections", "1000000"))); - httpServer.setFollowRedirects(Boolean.parseBoolean(SolrMeterConfiguration.getProperty("solr.server.configuration.followRedirect", "false"))); // defaults to false - httpServer.setAllowCompression(Boolean.parseBoolean(SolrMeterConfiguration.getProperty("solr.server.configuration.allowCompression", "true"))); - httpServer.setMaxRetries(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.maxRetries", "1"))); // defaults to 0. > 1 not recommended. - setAuthentication(httpServer); - servers.put(url, httpServer); - return httpServer; + String user = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthUser"); + String pass = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthPass"); + HttpSolrClient client; + + HttpClientBuilder builder = HttpClientBuilder.create(); + if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(pass)) { + UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials( + AuthScope.ANY, + creds); + + builder.addInterceptorFirst(new PreemptiveAuthInterceptor()); + builder.setDefaultCredentialsProvider(credsProvider); + } + + CloseableHttpClient httpClient = builder.build(); + + client = new HttpSolrClient.Builder().withBaseSolrUrl(url) + .withHttpClient(httpClient) + .build(); + + servers.put(url, client); + return client; } return server; } - private static void setAuthentication(HttpSolrServer httpServer) { + private static void setAuthentication(HttpSolrClient httpServer) { String user = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthUser"); String pass = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthPass"); if(user != null && !user.isEmpty() && pass != null && !pass.isEmpty()) { @@ -67,9 +90,11 @@ private static void setAuthentication(HttpSolrServer httpServer) { * Drops all existing SolrServers */ public static void invalidate() { - for(SolrServer server:servers.values()) { - if(server instanceof HttpSolrServer) { - ((HttpSolrServer) server).shutdown(); + for(SolrClient server:servers.values()) { + try { + server.close(); + } catch (IOException e) { + e.printStackTrace(); } } servers.clear(); diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/UpdateExecutor.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/UpdateExecutor.java index e430c19..fc82e0e 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/UpdateExecutor.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/UpdateExecutor.java @@ -15,7 +15,7 @@ */ package com.plugtree.solrmeter.model; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.UpdateResponse; import com.plugtree.solrmeter.model.exception.CommitException; @@ -28,10 +28,10 @@ public interface UpdateExecutor { /** - * + * * @return The current Solr Server. If there is no current Solr Server, then the method returns a new one. */ - public SolrServer getSolrServer(); + public SolrClient getSolrServer(); /** * Starts this executor @@ -80,13 +80,13 @@ public interface UpdateExecutor { public int getNotCommitedDocuments(); /** - * Set the number of documents that has to be added before a commit is performed - * by solrmeter. This number is useless when solrmeter doesn't perform commits. - */ + * Set the number of documents that has to be added before a commit is performed + * by solrmeter. This number is useless when solrmeter doesn't perform commits. + */ public void setNumberOfDocumentsBeforeCommit(int value); /** - * + * * @return The number of documents that has to be added before a commit is performed by * solrmeter. */ @@ -100,7 +100,7 @@ public interface UpdateExecutor { public void setMaxTimeBeforeCommit(Integer value); /** - * + * * @return The time interval between commits executed by solrmeter. */ public Integer getMaxTimeBeforeCommit(); @@ -113,21 +113,21 @@ public interface UpdateExecutor { public boolean isAutocommit(); /** - * + * * @return The number of update operations that has to be executed per minute */ public Integer getUpdatesPerMinute(); /** - * + * * @return true if the executor is currently running. * false if the executor is not currently running. */ public boolean isRunning(); /** - * Set the number of updates that has to be executed in a minute. - */ - public void setOperationsPerSecond(int value); + * Set the number of updates that has to be executed in a minute. + */ + public void setOperationsPerSecond(int value); } \ No newline at end of file diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/AbstractRandomExecutor.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/AbstractRandomExecutor.java index 2da103c..f73027b 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/AbstractRandomExecutor.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/AbstractRandomExecutor.java @@ -19,7 +19,7 @@ import java.util.List; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import com.plugtree.solrmeter.model.FileUtils; import com.plugtree.solrmeter.model.SolrMeterConfiguration; @@ -169,7 +169,7 @@ public void stop() { * @return Return the Solr Server instance for the url. There is only one * Solr Server for every difFerent url */ - public SolrServer getSolrServer(String url) { + public SolrClient getSolrServer(String url) { return SolrServerRegistry.getSolrServer(url); } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/OnDemandOptimizeExecutor.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/OnDemandOptimizeExecutor.java index b8d01fa..313c120 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/OnDemandOptimizeExecutor.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/OnDemandOptimizeExecutor.java @@ -19,7 +19,6 @@ import java.util.List; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; import com.plugtree.solrmeter.model.OptimizeExecutor; import com.plugtree.solrmeter.model.OptimizeStatistic; @@ -27,6 +26,8 @@ import com.plugtree.solrmeter.model.SolrServerRegistry; import com.plugtree.solrmeter.model.exception.OptimizeException; import com.plugtree.stressTestScope.StressTestScope; +import org.apache.solr.client.solrj.SolrClient; + /** * Executes an optimize only when the "execute" method is invoked * @author tflobbe @@ -34,37 +35,38 @@ */ @StressTestScope public class OnDemandOptimizeExecutor implements OptimizeExecutor { - + protected final static Logger logger = Logger.getLogger(OnDemandOptimizeExecutor.class); - + /** * The Solr Server were the optimize is going to run. */ - protected SolrServer server = null; - + protected SolrClient server = null; + /** * Indicates whether the index is being optimized or not at this time */ private boolean isOptimizing = false; - + /** * List of Statistics observing the operation */ protected List optimizeObservers; - + public OnDemandOptimizeExecutor() { this(SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_ADD_URL))); } - - public OnDemandOptimizeExecutor(SolrServer server) { + + public OnDemandOptimizeExecutor(SolrClient server) { super(); optimizeObservers = new LinkedList(); this.server = server; } - + /** * {@inheritDoc} */ + @Override public synchronized void execute() { if(isOptimizing) { logger.warn("Trying to optimize while already optimizing"); @@ -118,10 +120,11 @@ private void notifyOptimizeFinished(long delay) { observer.onOptimizeFinished(delay); } } - + /** * {@inheritDoc} */ + @Override public void addStatistic(OptimizeStatistic observer) { this.optimizeObservers.add(observer); } @@ -129,6 +132,7 @@ public void addStatistic(OptimizeStatistic observer) { /** * {@inheritDoc} */ + @Override public boolean isOptimizing() { return isOptimizing; } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorConstantImpl.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorConstantImpl.java index 63b1860..128e0cf 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorConstantImpl.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorConstantImpl.java @@ -18,7 +18,7 @@ import java.util.LinkedList; import java.util.List; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.QueryResponse; import com.google.inject.Inject; @@ -43,39 +43,39 @@ */ @StressTestScope public class QueryExecutorConstantImpl implements QueryExecutor{ - + /** * Solr Server for strings */ - private SolrServer server; - + private SolrClient server; + /** * List of Statistics observing this Executor. */ private List statistics; - + /** * Indicates wether the Executor is running or not */ private boolean running; - + private int operationsPerSecond; - + /** * Thread that execute queries periodically */ private ConstantOperationExecutorThread executerThread; - /** - * The generator that creates a query depending on the query mode selected - */ - private QueryGenerator queryGenerator; + /** + * The generator that creates a query depending on the query mode selected + */ + private QueryGenerator queryGenerator; - @Inject + @Inject public QueryExecutorConstantImpl(@Named("queryGenerator") QueryGenerator queryGenerator) { super(); - this.queryGenerator = queryGenerator; - statistics = new LinkedList(); + this.queryGenerator = queryGenerator; + statistics = new LinkedList(); this.operationsPerSecond = Integer.valueOf(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.QUERIES_PER_SECOND)).intValue(); } @@ -85,13 +85,13 @@ public int getQueriesPerSecond() { } @Override - public synchronized SolrServer getSolrServer() { + public synchronized SolrClient getSolrServer() { if(server == null) { server = SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_SEARCH_URL)); } return server; } - + private void updateThreadWaitTime() { if(executerThread != null) { executerThread.setTimeToWait(1000/operationsPerSecond); @@ -102,7 +102,7 @@ private void updateThreadWaitTime() { public boolean isRunning() { return running; } - + @Override public void prepare() { @@ -122,7 +122,7 @@ public void stop() { executerThread.destroy(); this.stopStatistics(); } - + /** * Logs strings time and all statistics information. */ @@ -145,7 +145,7 @@ public void notifyError(QueryException exception) { statistic.onQueryError(exception); } } - + @Override public void addStatistic(QueryStatistic statistic) { this.statistics.add(statistic); @@ -153,10 +153,10 @@ public void addStatistic(QueryStatistic statistic) { - @Override - public void setOperationsPerSecond(int newOperationsPerSecond) { - this.operationsPerSecond = newOperationsPerSecond; - updateThreadWaitTime(); - } + @Override + public void setOperationsPerSecond(int newOperationsPerSecond) { + this.operationsPerSecond = newOperationsPerSecond; + updateThreadWaitTime(); + } } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorRandomImpl.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorRandomImpl.java index 6b0af54..0da9701 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorRandomImpl.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/QueryExecutorRandomImpl.java @@ -18,7 +18,7 @@ import java.util.LinkedList; import java.util.List; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.QueryResponse; import com.google.inject.Inject; @@ -33,7 +33,7 @@ import com.plugtree.stressTestScope.StressTestScope; /** - * Creates and manages query execution Threads. The queries are executed with + * Creates and manages query execution Threads. The queries are executed with * RandomOperationExectionThread. * @see com.plugtree.solrmeter.model.operation.RandomOperationExecutorThread * @author tflobbe @@ -41,27 +41,27 @@ */ @StressTestScope public class QueryExecutorRandomImpl extends AbstractRandomExecutor implements QueryExecutor { - + /** * Solr Server for strings * TODO implement provider */ - private SolrServer server; - + private SolrClient server; + /** * List of Statistics observing this Executor. */ private List statistics; - - /** - * The generator that creates a query depending on the query mode selected - */ - private QueryGenerator queryGenerator; - @Inject + /** + * The generator that creates a query depending on the query mode selected + */ + private QueryGenerator queryGenerator; + + @Inject public QueryExecutorRandomImpl(@Named("queryGenerator") QueryGenerator queryGenerator) { super(); - this.queryGenerator = queryGenerator; + this.queryGenerator = queryGenerator; this.statistics = new LinkedList(); this.operationsPerSecond = Integer.parseInt(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.QUERIES_PER_SECOND)); super.prepare(); @@ -74,8 +74,8 @@ public QueryExecutorRandomImpl() { this.statistics = new LinkedList(); // operationsPerMinute = Integer.valueOf(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.QUERIES_PER_MINUTE)).intValue(); } - - + + @Override protected RandomOperationExecutorThread createThread() { @@ -93,33 +93,33 @@ protected void stopStatistics() { } @Override - public synchronized SolrServer getSolrServer() { + public synchronized SolrClient getSolrServer() { if(server == null) { server = super.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_SEARCH_URL)); } return server; } - + @Override public void notifyQueryExecuted(QueryResponse response, long clientTime) { for (QueryStatistic statistic:statistics) { statistic.onExecutedQuery(response, clientTime); } } - + @Override public void notifyError(QueryException exception) { for (QueryStatistic statistic:statistics) { statistic.onQueryError(exception); } } - - + + @Override protected String getOperationsPerSecondConfigurationKey() { return "solr.load.queriespersecond"; } - + @Override public void addStatistic(QueryStatistic statistic) { this.statistics.add(statistic); diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorConstantImpl.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorConstantImpl.java index 94676f3..d1609ff 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorConstantImpl.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorConstantImpl.java @@ -19,7 +19,7 @@ import java.util.List; import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.UpdateResponse; import com.google.inject.Inject; @@ -44,32 +44,32 @@ */ @StressTestScope public class UpdateExecutorConstantImpl implements UpdateExecutor { - + private final static Logger logger = Logger.getLogger(UpdateExecutorConstantImpl.class); //TODO DI - private SolrServer server; - + private SolrClient server; + private Integer numberOfDocumentsBeforeCommit; - + private Integer maxTimeBeforeCommit; - + private List statistics; - + protected boolean autocommit; - + private int notCommitedDocuments; - + private ConstantOperationExecutorThread commiterThread; - + private InputDocumentExtractor documentExtractor; - + private int operationsPerMinute; - + private boolean running; - + private ConstantOperationExecutorThread updateExecutorThread; - + @Inject public UpdateExecutorConstantImpl(@Named("updateExtractor") InputDocumentExtractor documentExtractor) { super(); @@ -80,14 +80,15 @@ public UpdateExecutorConstantImpl(@Named("updateExtractor") InputDocumentExtract maxTimeBeforeCommit = Integer.valueOf(SolrMeterConfiguration.getProperty("solr.update.timeToCommit", "10000")); numberOfDocumentsBeforeCommit = Integer.valueOf(SolrMeterConfiguration.getProperty("solr.update.documentsToCommit", "100")); } - - public synchronized SolrServer getSolrServer() { + + @Override + public synchronized SolrClient getSolrServer() { if(server == null) { server = SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_ADD_URL)); } return server; } - + private void prepareCommitter() { if(commiterThread != null) { commiterThread.destroy(); @@ -95,7 +96,8 @@ private void prepareCommitter() { commiterThread = new ConstantOperationExecutorThread(new CommitOperation(this)); commiterThread.setTimeToWait(maxTimeBeforeCommit); } - + + @Override public void start() { if(this.isRunning()) { return; @@ -109,7 +111,8 @@ public void start() { } logger.info("Update Executor started"); } - + + @Override public void stop() { if(!this.isRunning()) { return; @@ -127,6 +130,7 @@ protected void stopStatistics() { } } + @Override public void notifyAddedDocument(UpdateResponse response) { for(UpdateStatistic statistic:statistics) { statistic.onAddedDocument(response); @@ -139,38 +143,45 @@ public void notifyAddedDocument(UpdateResponse response) { } } } - + + @Override public void notifyCommitSuccessfull(UpdateResponse response) { notCommitedDocuments = 0; for(UpdateStatistic statistic:statistics) { statistic.onCommit(response); } } - + + @Override public void notifyCommitError(CommitException exception) { for(UpdateStatistic statistic:statistics) { statistic.onCommitError(exception); } } - + + @Override public void notifyUpdateError(UpdateException updateException) { for(UpdateStatistic statistic:statistics) { statistic.onAddError(updateException); } } - + + @Override public void addStatistic(UpdateStatistic statistic) { this.statistics.add(statistic); } + @Override public int getNotCommitedDocuments() { return notCommitedDocuments; } - + + @Override public Integer getNumberOfDocumentsBeforeCommit() { return numberOfDocumentsBeforeCommit; } - + + @Override public void setMaxTimeBeforeCommit(Integer value) { if(value <= 0) { throw new RuntimeException("Time before commit can't be 0"); @@ -182,22 +193,26 @@ public void setMaxTimeBeforeCommit(Integer value) { } } + @Override public Integer getMaxTimeBeforeCommit() { return maxTimeBeforeCommit; } + @Override public boolean isAutocommit() { return autocommit; } + @Override public Integer getUpdatesPerMinute() { return this.operationsPerMinute; } - + + @Override public boolean isRunning() { return running; } - + private void onOperationsPerMinuteChange() { SolrMeterConfiguration.setProperty("solr.load.updatesperminute", String.valueOf(operationsPerMinute)); if(this.updateExecutorThread != null) { @@ -205,26 +220,26 @@ private void onOperationsPerMinuteChange() { } } - @Override - public void setOperationsPerSecond(int value) { - if (operationsPerMinute < 1) { - throw new IllegalArgumentException("Invalid number of operations per second: " + value); - } - this.operationsPerMinute = value; - onOperationsPerMinuteChange(); - } - - @Override - public void setNumberOfDocumentsBeforeCommit(int value) { - if (value == Integer.MAX_VALUE) { - throw new IllegalArgumentException("Number of documents before commit can't be more than " + Integer.MAX_VALUE); - } - if (value < 0) { - throw new IllegalArgumentException("Number of documents before commit can't be less than 0"); - } - numberOfDocumentsBeforeCommit= value; - SolrMeterConfiguration.setProperty("solr.update.documentsToCommit", String.valueOf(numberOfDocumentsBeforeCommit)); - } - - + @Override + public void setOperationsPerSecond(int value) { + if (operationsPerMinute < 1) { + throw new IllegalArgumentException("Invalid number of operations per second: " + value); + } + this.operationsPerMinute = value; + onOperationsPerMinuteChange(); + } + + @Override + public void setNumberOfDocumentsBeforeCommit(int value) { + if (value == Integer.MAX_VALUE) { + throw new IllegalArgumentException("Number of documents before commit can't be more than " + Integer.MAX_VALUE); + } + if (value < 0) { + throw new IllegalArgumentException("Number of documents before commit can't be less than 0"); + } + numberOfDocumentsBeforeCommit= value; + SolrMeterConfiguration.setProperty("solr.update.documentsToCommit", String.valueOf(numberOfDocumentsBeforeCommit)); + } + + } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorRandomImpl.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorRandomImpl.java index 2ad620d..e5a19aa 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorRandomImpl.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/executor/UpdateExecutorRandomImpl.java @@ -18,7 +18,7 @@ import java.util.LinkedList; import java.util.List; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.UpdateResponse; import com.google.inject.Inject; @@ -35,8 +35,8 @@ import com.plugtree.solrmeter.model.operation.UpdateOperation; import com.plugtree.stressTestScope.StressTestScope; -/** - * manages update execution Threads. The updates are executed with +/** + * manages update execution Threads. The updates are executed with * RandomOperationExectionThread. * @see com.plugtree.solrmeter.model.operation.RandomOperationExecutorThread * @author tflobbe @@ -44,24 +44,23 @@ */ @StressTestScope public class UpdateExecutorRandomImpl extends AbstractRandomExecutor implements UpdateExecutor { - - //TODO DI - private SolrServer server; - + + private SolrClient server; + private Integer numberOfDocumentsBeforeCommit; - + private Integer maxTimeBeforeCommit; - + private List statistics; - + protected boolean autocommit; - + private int notCommitedDocuments; - + private ConstantOperationExecutorThread commiterThread; - + private InputDocumentExtractor documentExtractor; - + @Inject public UpdateExecutorRandomImpl(@Named("updateExtractor") InputDocumentExtractor documentExtractor) { super(); @@ -78,14 +77,16 @@ public UpdateExecutorRandomImpl() { super(); statistics = new LinkedList(); } - - public synchronized SolrServer getSolrServer() { + + @Override + public synchronized SolrClient getSolrServer() { if(server == null) { server = super.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_ADD_URL)); } return server; } - + + @Override protected RandomOperationExecutorThread createThread() { return new RandomOperationExecutorThread(new UpdateOperation(this, documentExtractor), 1000); } @@ -97,7 +98,8 @@ private void prepareCommitter() { commiterThread = new ConstantOperationExecutorThread(new CommitOperation(this)); commiterThread.setTimeToWait(maxTimeBeforeCommit); } - + + @Override public void start() { if(this.isRunning()) { return; @@ -109,7 +111,8 @@ public void start() { } logger.info("Update Executor started"); } - + + @Override public void stop() { if(!this.isRunning()) { return; @@ -120,12 +123,14 @@ public void stop() { super.stop(); } + @Override protected void stopStatistics() { for(UpdateStatistic statistic:statistics) { statistic.onFinishedTest(); } } + @Override public void notifyAddedDocument(UpdateResponse response) { for(UpdateStatistic statistic:statistics) { statistic.onAddedDocument(response); @@ -138,50 +143,57 @@ public void notifyAddedDocument(UpdateResponse response) { } } } - + + @Override public void notifyCommitSuccessfull(UpdateResponse response) { notCommitedDocuments = 0; for(UpdateStatistic statistic:statistics) { statistic.onCommit(response); } } - + + @Override public void notifyCommitError(CommitException exception) { for(UpdateStatistic statistic:statistics) { statistic.onCommitError(exception); } } - + + @Override public void notifyUpdateError(UpdateException updateException) { for(UpdateStatistic statistic:statistics) { statistic.onAddError(updateException); } } - + + @Override public void addStatistic(UpdateStatistic statistic) { this.statistics.add(statistic); } + @Override public int getNotCommitedDocuments() { return notCommitedDocuments; } - + @Override - public void setNumberOfDocumentsBeforeCommit(int value) { - if (value == Integer.MAX_VALUE) { - throw new IllegalArgumentException("Number of documents before commit can't be more than " + Integer.MAX_VALUE); - } - if (value < 0) { - throw new IllegalArgumentException("Number of documents before commit can't be less than 0"); - } - numberOfDocumentsBeforeCommit= value; - SolrMeterConfiguration.setProperty("solr.update.documentsToCommit", String.valueOf(numberOfDocumentsBeforeCommit)); - } + public void setNumberOfDocumentsBeforeCommit(int value) { + if (value == Integer.MAX_VALUE) { + throw new IllegalArgumentException("Number of documents before commit can't be more than " + Integer.MAX_VALUE); + } + if (value < 0) { + throw new IllegalArgumentException("Number of documents before commit can't be less than 0"); + } + numberOfDocumentsBeforeCommit= value; + SolrMeterConfiguration.setProperty("solr.update.documentsToCommit", String.valueOf(numberOfDocumentsBeforeCommit)); + } + @Override public Integer getNumberOfDocumentsBeforeCommit() { return numberOfDocumentsBeforeCommit; } - + + @Override public void setMaxTimeBeforeCommit(Integer value) { if(value <= 0) { throw new RuntimeException("Time before commit can't be 0"); @@ -191,14 +203,17 @@ public void setMaxTimeBeforeCommit(Integer value) { commiterThread.setTimeToWait(value); } + @Override public Integer getMaxTimeBeforeCommit() { return maxTimeBeforeCommit; } + @Override public boolean isAutocommit() { return autocommit; } + @Override public Integer getUpdatesPerMinute() { return this.operationsPerSecond; } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/generator/ComplexQueryGenerator.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/generator/ComplexQueryGenerator.java index 0ced731..ea95ad0 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/generator/ComplexQueryGenerator.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/generator/ComplexQueryGenerator.java @@ -15,100 +15,100 @@ import com.plugtree.solrmeter.model.SolrMeterConfiguration; public class ComplexQueryGenerator implements QueryGenerator { - + private final static Integer facetMinCount = Integer.valueOf(SolrMeterConfiguration.getProperty("solr.query.facet.minCount", "1")); - + private final static Integer facetLimit = Integer.valueOf(SolrMeterConfiguration.getProperty("solr.query.facet.limit", "8")); - + /** * If set, strings are executed adding random felds as facet. */ private final String queryType = SolrMeterConfiguration.getProperty(SolrMeterConfiguration.QUERY_TYPE); - + private boolean useFacets = Boolean.valueOf(SolrMeterConfiguration.getProperty("solr.query.useFacets", "true")); - + private final String facetMethod = SolrMeterConfiguration.getProperty("solr.query.facetMethod"); - + private final boolean useFilterQueries = Boolean.valueOf(SolrMeterConfiguration.getProperty("solr.query.useFilterQueries", "true")); private final boolean forceEchoParamsAll = Boolean.valueOf(SolrMeterConfiguration.getProperty("solr.query.echoParams", "false")); private final boolean addRandomExtraParams = Boolean.valueOf(SolrMeterConfiguration.getProperty("solr.query.addRandomExtraParams", "true")); - + /** * The facet fields extractor */ private final FieldExtractor facetFieldExtractor; - + /** * The filter query extractor */ private final QueryExtractor filterQueryExtractor; - + /** * The standard query extractor */ private final QueryExtractor queryExtractor; - + private final QueryExtractor extraParameterExtractor; - + protected final Map extraParameters = new HashMap();; - - + + @Inject public ComplexQueryGenerator(FieldExtractor facetFieldExtractor, - @Named("filterQueryExtractor") QueryExtractor filterQueryExtractor, - @Named("queryExtractor") QueryExtractor queryExtractor, - @Named("extraParamExtractor")QueryExtractor extraParamExtractor) { + @Named("filterQueryExtractor") QueryExtractor filterQueryExtractor, + @Named("queryExtractor") QueryExtractor queryExtractor, + @Named("extraParamExtractor")QueryExtractor extraParamExtractor) { this.queryExtractor = queryExtractor; this.filterQueryExtractor = filterQueryExtractor; this.facetFieldExtractor = facetFieldExtractor; this.extraParameterExtractor = extraParamExtractor; this.loadExtraParameters(SolrMeterConfiguration.getProperty("solr.query.extraParameters", "")); - + } - + protected ComplexQueryGenerator(){ this.queryExtractor = null; this.extraParameterExtractor = null; this.filterQueryExtractor = null; this.facetFieldExtractor = null; } - - + + protected void loadExtraParameters(String property) { if(property == null || "".equals(property.trim())) { return; } - + String[] values; try { values = CSVUtils.parseLine(property); - + for (String val : values) { val = StringEscapeUtils.unescapeCsv(val); - + int equalSignIndex = val.indexOf("="); if(equalSignIndex > 0) { extraParameters.put(val.substring(0, equalSignIndex).trim(), val.substring(equalSignIndex + 1).trim()); } } - + } catch (IOException e) { e.printStackTrace(); } } - - + + @Override public SolrQuery generate() { SolrQuery query; query = new SolrQuery(); query.setQuery(queryExtractor.getRandomQuery()); - query.setQueryType(queryType); + query.setRequestHandler(queryType); this.addExtraParameters(query); query.setIncludeScore(true); - + if(useFacets) { addFacetParameters(query); } @@ -119,12 +119,12 @@ public SolrQuery generate() { this.addRandomExtraParameters(query); } if(forceEchoParamsAll){ - query.add("echoParams", "all"); + query.add("echoParams", "all"); } return query; } - + /** * Adds extra (not specific) parameters of query * @param query @@ -134,7 +134,7 @@ private void addExtraParameters(SolrQuery query) { query.add(paramKey, extraParameters.get(paramKey)); } } - + /** * Adds a random line of the extra parameters extractor * @param query @@ -151,14 +151,14 @@ private void addRandomExtraParameters(SolrQuery query) { } } } - + private void addFilterQueriesParameters(SolrQuery query) { String filterQString = filterQueryExtractor.getRandomQuery(); if(!"".equals(filterQString.trim())) { query.addFilterQuery(filterQString); } } - + private void addFacetParameters(SolrQuery query) { query.setFacet(true); query.addFacetField(facetFieldExtractor.getRandomFacetField()); @@ -167,13 +167,13 @@ private void addFacetParameters(SolrQuery query) { if(facetMethod != null && !"".equals(facetMethod)) { query.add("facet.method", facetMethod); } - + } - + public boolean isUseFacets() { return useFacets; } - + public void setUseFacets(boolean useFacets) { this.useFacets = useFacets; } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/ConstantOperationExecutorThread.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/ConstantOperationExecutorThread.java index 363de14..a873f83 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/ConstantOperationExecutorThread.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/ConstantOperationExecutorThread.java @@ -38,20 +38,20 @@ */ @StressTestScope public class ConstantOperationExecutorThread extends Thread { - + private final ExecutorService threadPool = Executors.newCachedThreadPool(); - + private final AtomicLong timeToWait = new AtomicLong(1); - + private final AtomicBoolean running = new AtomicBoolean(false); - + private final Operation operation; - + public ConstantOperationExecutorThread(Operation operation) { super(); this.operation = operation; } - + @Override public synchronized void run() { while(running.get()) { @@ -71,25 +71,24 @@ public synchronized void run() { } } } - + @Override public synchronized void start() { this.running.set(true); super.start(); } - + public synchronized void wake() { this.notify(); } - - @Override + public void destroy() { - running.set(false); + running.set(false); } - + private void executeOperation() throws OperationException { Runnable r = new Runnable() { - + @Override public void run() { try { @@ -101,11 +100,11 @@ public void run() { }; threadPool.execute(r); } - + private long getTimeToWait() { return timeToWait.get(); } - + public void setTimeToWait(long timeToWait) { this.timeToWait.set(timeToWait); } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/PingOperation.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/PingOperation.java index cf989dc..d88532c 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/PingOperation.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/PingOperation.java @@ -2,7 +2,7 @@ import java.io.IOException; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.SolrPingResponse; import org.apache.solr.common.SolrException; @@ -15,10 +15,10 @@ * */ public class PingOperation implements Operation { - - private final SolrServer server; - - public PingOperation(SolrServer server) { + + private final SolrClient server; + + public PingOperation(SolrClient server) { this.server = server; } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/QueryOperation.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/QueryOperation.java index 4fd8011..e4f3c5e 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/QueryOperation.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/QueryOperation.java @@ -14,6 +14,7 @@ * limitations under the License. */ package com.plugtree.solrmeter.model.operation; +import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; @@ -33,19 +34,20 @@ * */ public class QueryOperation implements Operation { - + private final static Logger logger = Logger.getLogger(QueryOperation.class); - + private final QueryExecutor executor; - + private final QueryGenerator queryGenerator; - + public QueryOperation(QueryExecutor executor, QueryGenerator queryGenerator) { this.executor = executor; this.queryGenerator = queryGenerator; } - - + + + @Override public boolean execute() { SolrQuery query = queryGenerator.generate(); try { @@ -58,7 +60,7 @@ public boolean execute() { throw new RuntimeException("The query returned less than 0 as q time: " + response.getResponseHeader().get("q") + response.getQTime()); } executor.notifyQueryExecuted(response, clientTime); - } catch (SolrServerException e) { + } catch (SolrServerException | IOException e) { logger.error("Error on Query " + query); e.printStackTrace(); executor.notifyError(new QueryException(e, query)); @@ -66,10 +68,10 @@ public boolean execute() { } return true; } - - protected QueryResponse executeQuery(SolrQuery query) throws SolrServerException { - String requestMethod = SolrMeterConfiguration.getProperty(SolrMeterConfiguration.QUERY_METHOD, "GET"); - return executor.getSolrServer().query(query, METHOD.valueOf(requestMethod)); + + protected QueryResponse executeQuery(SolrQuery query) throws SolrServerException, IOException { + String requestMethod = SolrMeterConfiguration.getProperty(SolrMeterConfiguration.QUERY_METHOD, "GET"); + return executor.getSolrServer().query(query, METHOD.valueOf(requestMethod)); } - + } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/RandomOperationExecutorThread.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/RandomOperationExecutorThread.java index 74c4cbc..5c035c8 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/RandomOperationExecutorThread.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/operation/RandomOperationExecutorThread.java @@ -23,7 +23,7 @@ import com.plugtree.solrmeter.model.exception.OperationException; /** - * + * * An Operation that has to be executed every N milliseconds. The interval of execution * is not precise, it is at least queryInterval (parameter passed to the constructor) * and at most queryInterval + operation time. This is because the instant where the @@ -32,24 +32,25 @@ * */ public class RandomOperationExecutorThread extends Thread { - + protected final static Logger logger = Logger.getLogger(RandomOperationExecutorThread.class); protected final AtomicBoolean stopping = new AtomicBoolean(false); - + private final long operationIntervalInMs; - + /** * Operation to execute */ private Operation operation; - + public RandomOperationExecutorThread(Operation operation, long operationInterval) { super(); this.operationIntervalInMs = operationInterval; this.operation = operation; } - + + @Override public void run() { while(!isStopping()) { long init = System.currentTimeMillis(); @@ -66,24 +67,24 @@ public void run() { executeOperation(); } try { - + long diff = (operationIntervalInMs + init) - System.currentTimeMillis(); if(diff > 0L) { Thread.sleep(diff); } } catch (InterruptedException e) { - logger.error("Thread interrupted", e); - stopping.set(true); - Thread.currentThread().interrupt(); - break; + logger.error("Thread interrupted", e); + stopping.set(true); + Thread.currentThread().interrupt(); + break; } } } - + protected long getRandomSleepTime() { return (long) (Math.random() * operationIntervalInMs); } - + protected void executeOperation() { try { operation.execute(); @@ -95,8 +96,8 @@ protected void executeOperation() { protected boolean isStopping() { return stopping.get(); } - + public void destroy() { - this.stopping.set(true); + this.stopping.set(true); } } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/service/impl/QueryServiceSolrJImpl.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/service/impl/QueryServiceSolrJImpl.java index dae2957..d31cf27 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/service/impl/QueryServiceSolrJImpl.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/service/impl/QueryServiceSolrJImpl.java @@ -15,12 +15,13 @@ */ package com.plugtree.solrmeter.model.service.impl; +import java.io.IOException; import java.util.LinkedList; import java.util.List; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrQuery.ORDER; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.QueryResponse; @@ -40,22 +41,22 @@ public class QueryServiceSolrJImpl implements QueryService { @Override public QueryResponse executeQuery(String q, String fq, String qt, - boolean highlight, String facetFields, String sort, String sortOrder, Integer rows, Integer start, - String otherParams) throws QueryException { - SolrServer server = SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_SEARCH_URL)); + boolean highlight, String facetFields, String sort, String sortOrder, Integer rows, Integer start, + String otherParams) throws QueryException { + SolrClient server = SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_SEARCH_URL)); SolrQuery query = this.createQuery(q, fq, qt, highlight, facetFields, sort, sortOrder, rows, start, otherParams); QueryResponse response = null; try { response = server.query(query); - } catch (SolrServerException e) { + } catch (SolrServerException | IOException e) { throw new QueryException(e); } return response; } protected SolrQuery createQuery(String q, String fq, String qt, - boolean highlight, String facetFields, String sort, String sortOrder, Integer rows, Integer start, - String otherParams) throws QueryException { + boolean highlight, String facetFields, String sort, String sortOrder, Integer rows, Integer start, + String otherParams) throws QueryException { SolrQuery query = new SolrQuery(); if(q != null) { query.setQuery(q); @@ -67,7 +68,7 @@ protected SolrQuery createQuery(String q, String fq, String qt, } } if(qt != null) { - query.setQueryType(qt); + query.setRequestHandler(qt); } query.setHighlight(highlight); if(facetFields == null || "".equals(facetFields)) { @@ -80,7 +81,7 @@ protected SolrQuery createQuery(String q, String fq, String qt, } } if(sort != null && !"".equals(sort)) { - query.setSortField(sort, ORDER.valueOf(sortOrder)); + query.setSort(sort, ORDER.valueOf(sortOrder)); } if(rows != null && rows < 0) { throw new QueryException("Rows can't be less than 0"); @@ -92,7 +93,7 @@ protected SolrQuery createQuery(String q, String fq, String qt, }else if(start != null) { query.setStart(start); } - + if(otherParams != null) { List params = this.getOtherParams(otherParams); for(String param:params) { @@ -166,7 +167,7 @@ private void validateFilterQuery(String filter) throws QueryException { * Returns a list of trings parsing the comma separated values of the parameter string. * @param facetFields * @return - * @throws QueryException + * @throws QueryException */ protected List getFacets(String facetFields) throws QueryException { List list = getCommaSeparatedValues(facetFields); @@ -181,7 +182,7 @@ protected List getFacets(String facetFields) throws QueryException { private boolean hasWitespaces(String facet) { return facet.contains(" "); } - + private List getCommaSeparatedValues(String value) { List list = new LinkedList(); String[] splitted = value.split(","); diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/CacheHistoryStatistic.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/CacheHistoryStatistic.java index 33bb071..4cbaa77 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/CacheHistoryStatistic.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/CacheHistoryStatistic.java @@ -38,7 +38,7 @@ import com.plugtree.stressTestScope.StressTestScope; /** - * + * * Model of the Cache statistic. This statistic will show the evolution of the Solr caches * @author tflobbe * @@ -46,7 +46,7 @@ @StressTestScope public class CacheHistoryStatistic implements QueryStatistic { private static final String SINGLE_COLLECTION = "SINGLE_COLLECTION"; - + private final static Logger logger = Logger.getLogger(CacheHistoryStatistic.class); private static final String collectionsStr = SolrMeterConfiguration.getProperty("solr.collection.names", null); @@ -57,163 +57,163 @@ public class CacheHistoryStatistic implements QueryStatistic { * Stores the historical data of the filterCache */ private Map> filterCacheData = new HashMap<>(); - + /** * Stores the historical data of the documentCache */ private Map> documentCacheData; - + /** * Stores the historical data of the queryResultCache */ private Map> queryResultCacheData; - + /** * Stores the historical data of the fieldValueCache */ private Map> fieldValueCacheData; - + /** * Stores the cumulative data of the filterCache */ private Map filterCacheCumulativeData = new HashMap<>(); - + /** * Stores the cumulative data of the documentCache */ private Map documentCacheCumulativeData = new HashMap<>(); - + /** * Stores the cumulative data of the queryResultCache */ private Map queryResultCacheCumulativeData = new HashMap<>(); - + /** * Stores the cumulative data of the fieldValueCache */ private Map fieldValueCacheCumulativeData = new HashMap<>(); - + /** * Stores the description of the filterCache */ private Map filterCacheDescription = new HashMap<>(); - - - + + + /** * Connection with Solr statistics */ private AbstractStatisticConnection connection; - + private long initTime; - + //TODO @configurable private long refreshInterval = 1000; - + private StatisticUpdateThread updateThread; - + static { List _collections = new ArrayList<>(); stream(ofNullable(collectionsStr).orElse(SINGLE_COLLECTION).split("\\,")).map(String::trim).forEach(_collections::add); collections = Collections.unmodifiableList(_collections); } - + @Inject public CacheHistoryStatistic(AbstractStatisticConnection connection) { super(); - + this.connection = connection; - + collections.forEach(collection -> { filterCacheData = new HashMap<>(); filterCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); - + queryResultCacheData = new HashMap<>(); queryResultCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); documentCacheData = new HashMap<>(); documentCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); - - fieldValueCacheData = new HashMap<>(); + + fieldValueCacheData = new HashMap<>(); fieldValueCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); - + filterCacheDescription = new HashMap<>(); - + this.initTime = System.currentTimeMillis(); }); } - - + + public void updateData() { Long time = System.currentTimeMillis() - initTime; - + for (String collection : collections) { try { Map cacheData = connection.getData().get(collection); - + Map mappedCacheData = filterCacheData.get(collection); if (mappedCacheData == null) { filterCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); } put(time, filterCacheData.get(collection), cacheData, RequestHandlerConnection.FILTER_CACHE_NAME); - + mappedCacheData = queryResultCacheData.get(collection); if (mappedCacheData == null) { queryResultCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); } put(time, queryResultCacheData.get(collection), cacheData, RequestHandlerConnection.QUERY_RESULT_CACHE_NAME); - + mappedCacheData = documentCacheData.get(collection); if (mappedCacheData == null) { documentCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); } put(time, documentCacheData.get(collection), cacheData, RequestHandlerConnection.DOCUMENT_CACHE_NAME); - + mappedCacheData = fieldValueCacheData.get(collection); if (mappedCacheData == null) { fieldValueCacheData.put(collection, Collections.synchronizedSortedMap(new TreeMap())); } put(time, fieldValueCacheData.get(collection), cacheData, RequestHandlerConnection.FIELD_VALUE_CACHE_NAME); - + logger.trace("Adding document cumulative cache for " + collection + " collection: " + cacheData.get(RequestHandlerConnection.CUMULATIVE_DOCUMENT_CACHE_NAME)); - + filterCacheCumulativeData.put(collection, cacheData.get(RequestHandlerConnection.CUMULATIVE_FILTER_CACHE_NAME)); queryResultCacheCumulativeData.put(collection, cacheData.get(RequestHandlerConnection.CUMULATIVE_QUERY_RESULT_CACHE_NAME)); documentCacheCumulativeData.put(collection, cacheData.get(RequestHandlerConnection.CUMULATIVE_DOCUMENT_CACHE_NAME)); fieldValueCacheCumulativeData.put(collection, cacheData.get(RequestHandlerConnection.CUMULATIVE_FIELD_VALUE_CACHE_NAME)); - + } catch (StatisticConnectionException e) { logger.error("Could not update statistic", e); } } - + } - + private void put(Long time, SortedMap destDataMap, Map cacheData, String cacheName) { logger.trace(cacheName); logger.trace(cacheData); - + CacheData cacheDataValue = cacheData.get(cacheName); - if(cacheDataValue != null) { - destDataMap.put(time, cacheDataValue); - } - } + if(cacheDataValue != null) { + destDataMap.put(time, cacheDataValue); + } + } - public Map> getFilterCacheData() { + public Map> getFilterCacheData() { return filterCacheData; } - + public Map> getDocumentCacheData() { return documentCacheData; } public class StatisticUpdateThread extends Thread { - + private boolean running = false; - + public boolean isRunning() { return running; } @@ -232,18 +232,17 @@ public synchronized void run() { } } } - + @Override public synchronized void start() { this.running = true; super.start(); } - + public synchronized void wake() { this.notify(); } - - @Override + public void destroy() { this.running = false; } @@ -306,7 +305,7 @@ public void onExecutedQuery(QueryResponse response, long clientTime) { if(!updateThread.isRunning()) { updateThread.start(); } - + } diff --git a/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/RequestHandlerConnection.java b/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/RequestHandlerConnection.java index 7571c3b..f257af8 100644 --- a/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/RequestHandlerConnection.java +++ b/solrmeter/src/main/java/com/plugtree/solrmeter/model/statistic/RequestHandlerConnection.java @@ -23,13 +23,16 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.OptionalLong; import org.apache.log4j.Logger; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrResponse; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.SolrPingResponse; import org.apache.solr.common.params.ModifiableSolrParams; @@ -51,55 +54,56 @@ public class RequestHandlerConnection extends AbstractStatisticConnection { private static final String SINGLE_COLLECTION = "SINGLE_COLLECTION"; private static final String collectionsStr = SolrMeterConfiguration.getProperty("solr.collection.names", null); - + private final static Logger logger = Logger.getLogger(RequestHandlerConnection.class); private static final List collections; - - private Map solrServer; - + + private Map solrServer; + static { List _collections = new ArrayList<>(); stream(ofNullable(collectionsStr).orElse(SINGLE_COLLECTION).split("\\,")).map(String::trim).forEach(_collections::add); collections = Collections.unmodifiableList(_collections); } - + @Inject public RequestHandlerConnection() { this( - new HashMap() {{ - collections.forEach(collectionName -> { - put(collectionName, - SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_SEARCH_URL) - + (collectionName.equals(SINGLE_COLLECTION) ? "" : collectionName))); - }); - }} + new HashMap() {{ + collections.forEach(collectionName -> { + put(collectionName, + SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_SEARCH_URL) + + (collectionName.equals(SINGLE_COLLECTION) ? "" : collectionName))); + }); + }} ); } - - public RequestHandlerConnection(Map solrServer) { + + public RequestHandlerConnection(Map solrServer) { super(); this.solrServer = solrServer; } - + + @Override public Map> getData() throws StatisticConnectionException { SolrRequest request = new MBeanRequest("CACHE"); Map> cacheData = new HashMap<>(); - + for (String collectionName : collections) { try { Map collectionCacheData = new HashMap<>(); - NamedList namedList = solrServer.get(collectionName).request(request); + NamedList namedList = solrServer.get(collectionName).request(request, collectionName); collectionCacheData.put(FILTER_CACHE_NAME, getCacheData(namedList, "filterCache")); collectionCacheData.put(QUERY_RESULT_CACHE_NAME, getCacheData(namedList, "queryResultCache")); collectionCacheData.put(DOCUMENT_CACHE_NAME, getCacheData(namedList, "documentCache")); collectionCacheData.put(FIELD_VALUE_CACHE_NAME, getCacheData(namedList, "fieldValueCache")); - + collectionCacheData.put(CUMULATIVE_FILTER_CACHE_NAME, getCumulativeCacheData(namedList, "filterCache")); collectionCacheData.put(CUMULATIVE_QUERY_RESULT_CACHE_NAME, getCumulativeCacheData(namedList, "queryResultCache")); collectionCacheData.put(CUMULATIVE_DOCUMENT_CACHE_NAME, getCumulativeCacheData(namedList, "documentCache")); collectionCacheData.put(CUMULATIVE_FIELD_VALUE_CACHE_NAME, getCumulativeCacheData(namedList, "fieldValueCache")); - + cacheData.put(collectionName, collectionCacheData); } catch (Exception e) { throw new StatisticConnectionException(e); @@ -107,44 +111,89 @@ public Map> getData() throws StatisticConnectionE } return cacheData; } - + @SuppressWarnings("unchecked") private CacheData getCacheData(NamedList namedList, String cacheName) { - NamedList cache = getCacheNamedList(namedList, cacheName); - if(cache == null) { - return null; - } - NamedList stats = (NamedList)cache.get("stats"); - CacheData cd = new CacheData((Long)stats.get("lookups"), (Long)stats.get("hits"), (Float)stats.get("hitratio"), (Long)stats.get("inserts"), (Long)stats.get("evictions"), Long.valueOf(stats.get("size").toString()), (Long)stats.get("warmupTime")); + NamedList cache = getCacheNamedList(namedList, cacheName); + if(cache == null) { + return null; + } + NamedList stats = getNameListFromCache(cache,"stats"); + + CacheData cd = new CacheData((toLong(stats.get("lookups"))), + toLong(stats.get("hits")), + toFloat(stats.get("hitratio")), + toLong(stats.get("inserts")), + toLong(stats.get("evictions")), + toLong(stats.get("size")), + toLong(stats.get("warmupTime"))); return cd; } + public Long toLong(Object o) { + if (null == o) { + return 0L; + }else { + if (o instanceof Long) { + return (Long) o; + } + return Long.parseLong(o.toString()); + } + } + public Float toFloat(Object o) { + if (null == o) { + return 0f; + }else { + if (o instanceof Float) { + return (Float) o; + } + return Float.parseFloat(o.toString()); + } + } + + /** + * @author zhaotao + * @time 2021年8月25日 + * @param name + * @return + */ + private NamedList getNameListFromCache(NamedList cache,String name) { + LinkedHashMap stats = (LinkedHashMap) cache.get(name); + return new NamedList<>(stats); + } + @SuppressWarnings("unchecked") - private NamedList getCacheNamedList(NamedList namedList, - String cacheName) { - NamedList cache = ((NamedList)((NamedList)((NamedList)namedList.get("solr-mbeans")).get("CACHE")).get(cacheName)); - logger.trace("Got cache for " + cacheName); - return cache; - } - + private NamedList getCacheNamedList(NamedList namedList, + String cacheName) { + Object o = namedList.get("solr-mbeans"); + if (null != o) { + o = ((NamedList) o).get("CACHE"); + if (null != o) { + return (NamedList) ((NamedList) o).get(cacheName); + } + } + logger.trace("Got cache for " + cacheName); + return new NamedList<>(); + } + @SuppressWarnings("unchecked") private CacheData getCumulativeCacheData(NamedList namedList, String cacheName) { - NamedList cache = getCacheNamedList(namedList, cacheName); + NamedList cache = getCacheNamedList(namedList, cacheName); - if(cache == null) { - return null; - } + if(cache == null) { + return null; + } - NamedList stats = (NamedList)cache.get("stats"); - CacheData data = new CacheData((Long)stats.get("cumulative_lookups"), (Long)stats.get("cumulative_hits"), (Float)stats.get("cumulative_hitratio"), (Long)stats.get("cumulative_inserts"), (Long)stats.get("cumulative_evictions")); + NamedList stats = this.getCacheNamedList(cache,"stats"); + CacheData data = new CacheData(toLong(stats.get("cumulative_lookups")), toLong(stats.get("cumulative_hits")), toFloat(stats.get("cumulative_hitratio")), toLong(stats.get("cumulative_inserts")), toLong(stats.get("cumulative_evictions"))); return data; } - + private class MBeanRequest extends SolrRequest { - + private static final long serialVersionUID = 1L; private ModifiableSolrParams params; - + public MBeanRequest(String category, String key) { super(METHOD.GET, "/admin/mbeans"); params = new ModifiableSolrParams(); @@ -152,7 +201,7 @@ public MBeanRequest(String category, String key) { params.set("stats", "true"); params.set("key", key); } - + public MBeanRequest(String category) { super(METHOD.GET, "/admin/mbeans"); params = new ModifiableSolrParams(); @@ -160,25 +209,29 @@ public MBeanRequest(String category) { params.set("stats", "true"); } - @Override - public SolrResponse process(SolrServer server) throws SolrServerException, + /*public SolrResponse process(SolrClient server) throws SolrServerException, IOException { long startTime = System.currentTimeMillis(); SolrPingResponse res = new SolrPingResponse(); res.setResponse( server.request( this ) ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; - } - + }*/ + @Override public SolrParams getParams() { return params; } - + @Override public Collection getContentStreams() throws IOException { return null; } + + @Override + protected SolrResponse createResponse(SolrClient client) { + return null; + } } } diff --git a/solrmeter/src/test/java/com/plugtree/solrmeter/QueryServiceSolrJImplTestCase.java b/solrmeter/src/test/java/com/plugtree/solrmeter/QueryServiceSolrJImplTestCase.java index 42f120b..e1dbc5e 100644 --- a/solrmeter/src/test/java/com/plugtree/solrmeter/QueryServiceSolrJImplTestCase.java +++ b/solrmeter/src/test/java/com/plugtree/solrmeter/QueryServiceSolrJImplTestCase.java @@ -99,7 +99,7 @@ public void testCreateQuery() throws QueryException { SolrQuery query = service.createQuery("some query", "name:tomas", "/dismax", false, "name, surname", null, null, 10, 0, ""); assertEquals("some query", query.get("q")); assertEquals(new String[]{"name:tomas"}, query.getFilterQueries()); - assertEquals("/dismax", query.getQueryType()); + assertEquals("/dismax", query.getRequestHandler()); assertEquals(new String[]{"name", "surname"}, query.getFacetFields()); service.createQuery(null, "name:tomas", "/dismax", false, "name, surname", null, null, 10, 0, ""); diff --git a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/OptimizeExecutorSpy.java b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/OptimizeExecutorSpy.java index 9a0ea17..c54142a 100644 --- a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/OptimizeExecutorSpy.java +++ b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/OptimizeExecutorSpy.java @@ -18,7 +18,7 @@ import java.net.MalformedURLException; import java.util.LinkedList; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import com.plugtree.solrmeter.model.OptimizeStatistic; import com.plugtree.solrmeter.model.executor.OnDemandOptimizeExecutor; @@ -30,10 +30,10 @@ public OptimizeExecutorSpy() throws MalformedURLException { optimizeObservers = new LinkedList(); } - public SolrServer getServer() { + public SolrClient getServer() { return server; } - public void setServer(SolrServer server) { + public void setServer(SolrClient server) { this.server = server; } diff --git a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/SolrServerMock.java b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/SolrServerMock.java index 0d97537..eb52937 100644 --- a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/SolrServerMock.java +++ b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/SolrServerMock.java @@ -22,14 +22,14 @@ import java.util.Map; import org.apache.log4j.Logger; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.response.UpdateResponse; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.util.NamedList; -public class SolrServerMock extends SolrServer { +public class SolrServerMock extends SolrClient { private static final long serialVersionUID = 7266180569831920295L; @@ -63,12 +63,7 @@ public UpdateResponse add(SolrInputDocument doc) return response; } - @Override - public NamedList request(SolrRequest arg0) - throws SolrServerException, IOException { - return requestsResponses.get(arg0.getPath()); - } - + @Override public UpdateResponse optimize() throws SolrServerException, IOException { numberOfOptimize++; @@ -76,6 +71,12 @@ public UpdateResponse optimize() throws SolrServerException, IOException { return response; } + @Override + public NamedList request(SolrRequest arg0, String s) { + return requestsResponses.get(arg0.getPath()); + } + + public List getAddedDocuments() { return addedDocuments; } @@ -100,4 +101,8 @@ public void setResponseToRequest(String request, NamedList response) { requestsResponses.put(request, response); } + @Override + public void close() throws IOException { + + } } diff --git a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorMock.java b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorMock.java index e03bd13..99c12a2 100644 --- a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorMock.java +++ b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorMock.java @@ -15,7 +15,7 @@ */ package com.plugtree.solrmeter.mock; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.response.UpdateResponse; import org.apache.solr.common.SolrInputDocument; @@ -26,7 +26,7 @@ public class UpdateExecutorMock extends UpdateExecutorRandomImpl { private SolrServerMock server; - public synchronized SolrServer getSolrServer() { + public synchronized SolrClient getSolrServer() { if(server == null) { server = new SolrServerMock(); } diff --git a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorSpy.java b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorSpy.java index 1b0ea9a..f15a0f8 100644 --- a/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorSpy.java +++ b/solrmeter/src/test/java/com/plugtree/solrmeter/mock/UpdateExecutorSpy.java @@ -15,7 +15,7 @@ */ package com.plugtree.solrmeter.mock; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import com.plugtree.solrmeter.model.executor.UpdateExecutorRandomImpl; @@ -28,7 +28,7 @@ public UpdateExecutorSpy() { serverMock = new SolrServerMock(); } - public synchronized SolrServer getSolrServer() { + public synchronized SolrClient getSolrServer() { return serverMock; } } diff --git a/solrmeter/src/test/java/com/plugtree/solrmeter/statistic/RequestHandlerConnectionTestCase.java b/solrmeter/src/test/java/com/plugtree/solrmeter/statistic/RequestHandlerConnectionTestCase.java index 31cec58..04d4703 100644 --- a/solrmeter/src/test/java/com/plugtree/solrmeter/statistic/RequestHandlerConnectionTestCase.java +++ b/solrmeter/src/test/java/com/plugtree/solrmeter/statistic/RequestHandlerConnectionTestCase.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.Map; -import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.common.util.NamedList; import com.plugtree.solrmeter.BaseTestCase; @@ -17,8 +17,8 @@ public class RequestHandlerConnectionTestCase extends BaseTestCase { private static String dummyCollection = "SINGLE_COLLECTION"; public void testConnectionData() throws MalformedURLException, StatisticConnectionException { - SolrServer solrServer = this.createMockSolrServer(); - Map serverMap = new HashMap<>(); + SolrClient solrServer = this.createMockSolrServer(); + Map serverMap = new HashMap<>(); serverMap.put(dummyCollection, solrServer); RequestHandlerConnection connection = new RequestHandlerConnection(serverMap); Map data = connection.getData().get(dummyCollection); @@ -32,8 +32,8 @@ public void testConnectionData() throws MalformedURLException, StatisticConnecti } public void testAllCachesPresent() throws MalformedURLException, StatisticConnectionException { - SolrServer solrServer = this.createMockSolrServer(); - Map serverMap = new HashMap<>(); + SolrClient solrServer = this.createMockSolrServer(); + Map serverMap = new HashMap<>(); serverMap.put(dummyCollection, solrServer); RequestHandlerConnection connection = new RequestHandlerConnection(serverMap); Map data = connection.getData().get(dummyCollection); @@ -57,8 +57,8 @@ public void testAllCachesPresent() throws MalformedURLException, StatisticConnec * 0 */ public void testCumulativeData() throws MalformedURLException, StatisticConnectionException { - SolrServer solrServer = this.createMockSolrServer(); - Map serverMap = new HashMap<>(); + SolrClient solrServer = this.createMockSolrServer(); + Map serverMap = new HashMap<>(); serverMap.put(dummyCollection, solrServer); RequestHandlerConnection connection = new RequestHandlerConnection(serverMap); Map data = connection.getData().get(dummyCollection); @@ -73,11 +73,11 @@ public void testCumulativeData() throws MalformedURLException, StatisticConnecti assertEquals((long)-1, filterQueryData.getWarmupTime()); } - private SolrServer createMockSolrServer() throws MalformedURLException { + private SolrClient createMockSolrServer() throws MalformedURLException { return this.createMockSolrServer("queryResultCache", "fieldCache", "documentCache", "fieldValueCache", "filterCache"); } - private SolrServer createMockSolrServer(String... caches) throws MalformedURLException { + private SolrClient createMockSolrServer(String... caches) throws MalformedURLException { SolrServerMock mock = new SolrServerMock(); mock.setResponseToRequest("/admin/mbeans", this.createMBeansNamedList(caches)); return mock; @@ -164,8 +164,8 @@ private NamedList createStatsNamedList() { } public void testMissingCaches() throws MalformedURLException, StatisticConnectionException { - SolrServer solrServer = this.createMockSolrServer("filterCache"); - Map serverMap = new HashMap<>(); + SolrClient solrServer = this.createMockSolrServer("filterCache"); + Map serverMap = new HashMap<>(); serverMap.put(dummyCollection, solrServer); RequestHandlerConnection connection = new RequestHandlerConnection(serverMap); Map data = connection.getData().get(dummyCollection);