This is an automated email from the ASF dual-hosted git repository.
ab pushed a commit to branch jira/solr-14749-api
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/jira/solr-14749-api by this push:
new 690fc1e SOLR-14749: Reset other changed files to master.
690fc1e is described below
commit 690fc1e3d26c9e26bc68abad098fd08581096483
Author: Andrzej Bialecki <ab@apache.org>
AuthorDate: Thu Oct 8 12:32:43 2020 +0200
SOLR-14749: Reset other changed files to master.
---
.../src/java/org/apache/solr/api/AnnotatedApi.java | 15 +-
.../apache/solr/api/CustomContainerPlugins.java | 61 +----
.../solr/handler/admin/ContainerPluginsApi.java | 10 +-
.../apache/solr/packagemanager/PackageManager.java | 3 +-
.../test/org/apache/solr/cloud/OverseerTest.java | 26 +-
.../solr/cluster/events/AllEventsListener.java | 76 ------
.../cluster/events/ClusterEventProducerTest.java | 273 ---------------------
.../impl/CollectionsRepairEventListenerTest.java | 132 ----------
.../apache/solr/handler/TestContainerPlugin.java | 4 +-
9 files changed, 23 insertions(+), 577 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java b/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
index 1558f1c..fd77413 100644
--- a/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
+++ b/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
@@ -85,18 +85,9 @@ public class AnnotatedApi extends Api implements PermissionNameProvider
, Closea
}
public static List<Api> getApis(Object obj) {
- return getApis(obj.getClass(), obj, true);
+ return getApis(obj.getClass(), obj);
}
-
- /**
- * Get a list of Api-s supported by this class.
- * @param theClass class
- * @param obj object of this class (may be null)
- * @param required if true then an exception is thrown if no Api-s can be retrieved, if
false
- * then absence of Api-s is silently ignored.
- * @return list of discovered Api-s
- */
- public static List<Api> getApis(Class<? extends Object> theClass , Object obj,
boolean required) {
+ public static List<Api> getApis(Class<? extends Object> theClass , Object obj)
{
Class<?> klas = null;
try {
klas = MethodHandles.publicLookup().accessClass(theClass);
@@ -131,7 +122,7 @@ public class AnnotatedApi extends Api implements PermissionNameProvider
, Closea
SpecProvider specProvider = readSpec(endPoint, Collections.singletonList(m));
apis.add(new AnnotatedApi(specProvider, endPoint, Collections.singletonMap("", cmd),
null));
}
- if (required && apis.isEmpty()) {
+ if (apis.isEmpty()) {
throw new RuntimeException("Invalid Class : " + klas.getName() + " No @EndPoints");
}
diff --git a/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java b/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
index ec3e4e3..93de2e3 100644
--- a/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
+++ b/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
@@ -33,9 +33,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.lucene.util.ResourceLoaderAware;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.request.beans.PluginMeta;
-import org.apache.solr.cloud.ClusterSingleton;
-import org.apache.solr.cluster.events.ClusterEvent;
-import org.apache.solr.cluster.events.ClusterEventListener;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.annotation.JsonProperty;
@@ -71,7 +68,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
refresh();
return false;
}
-
public CustomContainerPlugins(CoreContainer coreContainer, ApiBag apiBag) {
this.coreContainer = coreContainer;
this.containerApiBag = apiBag;
@@ -82,10 +78,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
currentPlugins.forEach(ew.getBiConsumer());
}
- public synchronized ApiInfo getPlugin(String name) {
- return currentPlugins.get(name);
- }
-
public synchronized void refresh() {
Map<String, Object> pluginInfos = null;
try {
@@ -115,7 +107,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
if (e.getValue() == Diff.REMOVED) {
ApiInfo apiInfo = currentPlugins.remove(e.getKey());
if (apiInfo == null) continue;
- handleClusterSingleton(null, apiInfo);
for (ApiHolder holder : apiInfo.holders) {
Api old = containerApiBag.unregister(holder.api.getEndPoint().method()[0],
getActualPath(apiInfo, holder.api.getEndPoint().path()[0]));
@@ -145,7 +136,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
containerApiBag.register(holder, getTemplateVars(apiInfo.info));
}
currentPlugins.put(e.getKey(), apiInfo);
- handleClusterSingleton(apiInfo, null);
} else {
//this plugin is being updated
ApiInfo old = currentPlugins.put(e.getKey(), apiInfo);
@@ -153,7 +143,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
//register all new paths
containerApiBag.register(holder, getTemplateVars(apiInfo.info));
}
- handleClusterSingleton(apiInfo, old);
if (old != null) {
//this is an update of the plugin. But, it is possible that
// some paths are remved in the newer version of the plugin
@@ -174,47 +163,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
}
}
- private void handleClusterSingleton(ApiInfo newApiInfo, ApiInfo oldApiInfo) {
- if (newApiInfo != null) {
- // register new api
- Object instance = newApiInfo.getInstance();
- if (instance instanceof ClusterSingleton) {
- ClusterSingleton singleton = (ClusterSingleton) instance;
- coreContainer.getClusterSingletons().getSingletons().put(singleton.getName(), singleton);
- // easy check to see if we should immediately start this singleton
- if (coreContainer.getClusterEventProducer() != null &&
- coreContainer.getClusterEventProducer().isRunning()) {
- try {
- singleton.start();
- } catch (Exception exc) {
- log.warn("Exception starting ClusterSingleton {}: {}", newApiInfo, exc);
- }
- }
- }
- if (instance instanceof ClusterEventListener) {
- // XXX nocommit obtain a list of supported event types from the config
- ClusterEvent.EventType[] types = ClusterEvent.EventType.values();
- try {
- coreContainer.getClusterEventProducer().registerListener((ClusterEventListener)
instance, types);
- } catch (Exception exc) {
- log.warn("Exception adding ClusterEventListener {}: {}", newApiInfo, exc);
- }
- }
- }
- if (oldApiInfo != null) {
- // stop & unregister the old api
- Object instance = oldApiInfo.getInstance();
- if (instance instanceof ClusterSingleton) {
- ClusterSingleton singleton = (ClusterSingleton) instance;
- singleton.stop();
- coreContainer.getClusterSingletons().getSingletons().remove(singleton.getName());
- }
- if (instance instanceof ClusterEventListener) {
- coreContainer.getClusterEventProducer().unregisterListener((ClusterEventListener)
instance);
- }
- }
- }
-
private static String getActualPath(ApiInfo apiInfo, String path) {
path = path.replaceAll("\\$path-prefix", apiInfo.info.pathPrefix);
path = path.replaceAll("\\$plugin-name", apiInfo.info.name);
@@ -274,9 +222,6 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
return null;
}
- public Object getInstance() {
- return instance;
- }
@SuppressWarnings({"unchecked","rawtypes"})
public ApiInfo(PluginMeta info, List<String> errs) {
@@ -323,14 +268,14 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
}
try {
- List<Api> apis = AnnotatedApi.getApis(klas, null, false);
+ List<Api> apis = AnnotatedApi.getApis(klas, null);
for (Object api : apis) {
EndPoint endPoint = ((AnnotatedApi) api).getEndPoint();
if (endPoint.path().length > 1 || endPoint.method().length > 1) {
errs.add("Only one HTTP method and url supported for each API");
}
if (endPoint.method().length != 1 || endPoint.path().length != 1) {
- errs.add("The @EndPoint must have exactly one method and path attributes");
+ errs.add("The @EndPint must have exactly one method and path attributes");
}
List<String> pathSegments = StrUtils.splitSmart(endPoint.path()[0], '/',
true);
PathTrie.replaceTemplates(pathSegments, getTemplateVars(info));
@@ -375,7 +320,7 @@ public class CustomContainerPlugins implements ClusterPropertiesListener,
MapWri
}
}
this.holders = new ArrayList<>();
- for (Api api : AnnotatedApi.getApis(instance.getClass(), instance, false)) {
+ for (Api api : AnnotatedApi.getApis(instance)) {
holders.add(new ApiHolder((AnnotatedApi) api));
}
}
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java b/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java
index ad95423..0c7a487 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java
@@ -51,7 +51,7 @@ import static org.apache.lucene.util.IOUtils.closeWhileHandlingException;
public class ContainerPluginsApi {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public static final String PLUGINS = "plugin";
+ public static final String PLUGIN = "plugin";
private final Supplier<SolrZkClient> zkClientSupplier;
private final CoreContainer coreContainer;
public final Read readAPI = new Read();
@@ -67,7 +67,7 @@ public class ContainerPluginsApi {
path = "/cluster/plugin",
permission = PermissionNameProvider.Name.COLL_READ_PERM)
public void list(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
- rsp.add(PLUGINS, plugins(zkClientSupplier));
+ rsp.add(PLUGIN, plugins(zkClientSupplier));
}
}
@@ -151,7 +151,7 @@ public class ContainerPluginsApi {
SolrZkClient zkClient = zkClientSupplier.get();
try {
Map<String, Object> clusterPropsJson = (Map<String, Object>) Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS,
null, new Stat(), true));
- return (Map<String, Object>) clusterPropsJson.computeIfAbsent(PLUGINS, o ->
new LinkedHashMap<>());
+ return (Map<String, Object>) clusterPropsJson.computeIfAbsent(PLUGIN, o ->
new LinkedHashMap<>());
} catch (KeeperException.NoNodeException e) {
return new LinkedHashMap<>();
} catch (KeeperException | InterruptedException e) {
@@ -165,9 +165,9 @@ public class ContainerPluginsApi {
zkClientSupplier.get().atomicUpdate(ZkStateReader.CLUSTER_PROPS, bytes -> {
Map rawJson = bytes == null ? new LinkedHashMap() :
(Map) Utils.fromJSON(bytes);
- Map pluginsModified = modifier.apply((Map) rawJson.computeIfAbsent(PLUGINS, o ->
new LinkedHashMap<>()));
+ Map pluginsModified = modifier.apply((Map) rawJson.computeIfAbsent(PLUGIN, o ->
new LinkedHashMap<>()));
if (pluginsModified == null) return null;
- rawJson.put(PLUGINS, pluginsModified);
+ rawJson.put(PLUGIN, pluginsModified);
return Utils.toJSON(rawJson);
});
} catch (KeeperException | InterruptedException e) {
diff --git a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
index 044cf8c..424f604 100644
--- a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
+++ b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
@@ -52,7 +52,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.Pair;
import org.apache.solr.common.util.Utils;
import org.apache.solr.filestore.DistribPackageStore;
-import org.apache.solr.handler.admin.ContainerPluginsApi;
import org.apache.solr.packagemanager.SolrPackage.Command;
import org.apache.solr.packagemanager.SolrPackage.Manifest;
import org.apache.solr.packagemanager.SolrPackage.Plugin;
@@ -232,7 +231,7 @@ public class PackageManager implements Closeable {
}
}
@SuppressWarnings({"unchecked"})
- Map<String, Object> clusterPlugins = (Map<String, Object>) result.getOrDefault(ContainerPluginsApi.PLUGINS,
Collections.emptyMap());
+ Map<String, Object> clusterPlugins = (Map<String, Object>) result.getOrDefault("plugin",
Collections.emptyMap());
for (String key : clusterPlugins.keySet()) {
// Map<String, String> pluginMeta = (Map<String, String>) clusterPlugins.get(key);
PluginMeta pluginMeta;
diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
index f6c07c1..b6372a0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
@@ -17,7 +17,13 @@
package org.apache.solr.cloud;
import static org.apache.solr.cloud.AbstractDistribZkTestBase.verifyReplicaStatus;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.anyBoolean;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
@@ -50,7 +56,6 @@ import org.apache.solr.client.solrj.impl.SolrClientCloudManager;
import org.apache.solr.cloud.overseer.NodeMutator;
import org.apache.solr.cloud.overseer.OverseerAction;
import org.apache.solr.cloud.overseer.ZkWriteCommand;
-import org.apache.solr.cluster.events.impl.ClusterEventProducerImpl;
import org.apache.solr.common.AlreadyClosedException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ClusterState;
@@ -112,6 +117,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
private static SolrZkClient zkClient;
+
private volatile boolean testDone = false;
private final List<ZkController> zkControllers = Collections.synchronizedList(new
ArrayList<>());
@@ -121,6 +127,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
private final List<HttpShardHandlerFactory> httpShardHandlerFactorys = Collections.synchronizedList(new
ArrayList<>());
private final List<UpdateShardHandler> updateShardHandlers = Collections.synchronizedList(new
ArrayList<>());
private final List<CloudSolrClient> solrClients = Collections.synchronizedList(new
ArrayList<>());
+
private static final String COLLECTION = SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
public static class MockZKController{
@@ -299,7 +306,6 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Before
public void setUp() throws Exception {
testDone = false;
-
super.setUp();
}
@@ -316,7 +322,6 @@ public class OverseerTest extends SolrTestCaseJ4 {
}
server = null;
-
}
@After
@@ -1423,24 +1428,11 @@ public class OverseerTest extends SolrTestCaseJ4 {
Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(testDone); // Allow retry on
session expiry
when(mockAlwaysUpCoreContainer.getResourceLoader()).thenReturn(new SolrResourceLoader());
- CoreContainer.ClusterSingletons singletons = new CoreContainer.ClusterSingletons();
- // don't wait for all singletons
- singletons.setReady();
- FieldSetter.setField(mockAlwaysUpCoreContainer, CoreContainer.class.getDeclaredField("clusterSingletons"),
singletons);
- ClusterEventProducerImpl clusterEventProducer = new ClusterEventProducerImpl(mockAlwaysUpCoreContainer);
- when(mockAlwaysUpCoreContainer.getClusterEventProducer()).thenReturn(clusterEventProducer);
FieldSetter.setField(zkController, ZkController.class.getDeclaredField("zkClient"), zkClient);
FieldSetter.setField(zkController, ZkController.class.getDeclaredField("cc"), mockAlwaysUpCoreContainer);
when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);
when(zkController.getZkClient()).thenReturn(zkClient);
when(zkController.getZkStateReader()).thenReturn(reader);
- // primitive support for CC.runAsync
- doAnswer(invocable -> {
- Runnable r = invocable.getArgument(0);
- Thread t = new Thread(r);
- t.start();
- return null;
- }).when(mockAlwaysUpCoreContainer).runAsync(any(Runnable.class));
when(zkController.getLeaderProps(anyString(), anyString(), anyInt())).thenCallRealMethod();
when(zkController.getLeaderProps(anyString(), anyString(), anyInt(), anyBoolean())).thenCallRealMethod();
diff --git a/solr/core/src/test/org/apache/solr/cluster/events/AllEventsListener.java b/solr/core/src/test/org/apache/solr/cluster/events/AllEventsListener.java
deleted file mode 100644
index 8da6bea..0000000
--- a/solr/core/src/test/org/apache/solr/cluster/events/AllEventsListener.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.solr.cluster.events;
-
-import org.junit.Assert;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-/**
- *
- */
-public class AllEventsListener implements ClusterEventListener {
- CountDownLatch eventLatch = new CountDownLatch(1);
- ClusterEvent.EventType expectedType;
- Map<ClusterEvent.EventType, List<ClusterEvent>> events = new HashMap<>();
-
- @Override
- public String getName() {
- return "allEventsListener";
- }
-
- @Override
- public void onEvent(ClusterEvent event) {
- events.computeIfAbsent(event.getType(), type -> new ArrayList<>()).add(event);
- if (event.getType() == expectedType) {
- eventLatch.countDown();
- }
- }
-
- public void setExpectedType(ClusterEvent.EventType expectedType) {
- this.expectedType = expectedType;
- eventLatch = new CountDownLatch(1);
- }
-
- public void waitForExpectedEvent(int timeoutSeconds) throws InterruptedException {
- boolean await = eventLatch.await(timeoutSeconds, TimeUnit.SECONDS);
- if (!await) {
- Assert.fail("Timed out waiting for expected event " + expectedType);
- }
- }
-
- @Override
- public void start() throws Exception {
-
- }
-
- @Override
- public boolean isRunning() {
- return false;
- }
-
- @Override
- public void stop() {
-
- }
-}
diff --git a/solr/core/src/test/org/apache/solr/cluster/events/ClusterEventProducerTest.java
b/solr/core/src/test/org/apache/solr/cluster/events/ClusterEventProducerTest.java
deleted file mode 100644
index ea6c5f5..0000000
--- a/solr/core/src/test/org/apache/solr/cluster/events/ClusterEventProducerTest.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.solr.cluster.events;
-
-import org.apache.solr.client.solrj.embedded.JettySolrRunner;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.request.V2Request;
-import org.apache.solr.client.solrj.request.beans.PluginMeta;
-import org.apache.solr.client.solrj.response.V2Response;
-import org.apache.solr.cloud.SolrCloudTestCase;
-import org.apache.solr.common.cloud.ClusterProperties;
-import org.apache.solr.common.util.Utils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.lang.invoke.MethodHandles;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import static java.util.Collections.singletonMap;
-import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
-import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
-
-/**
- *
- */
-public class ClusterEventProducerTest extends SolrCloudTestCase {
-
- private AllEventsListener eventsListener;
-
- @BeforeClass
- public static void setupCluster() throws Exception {
- configureCluster(3)
- .addConfig("conf", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf"))
- .configure();
- }
-
- @Before
- public void setUp() throws Exception {
- System.setProperty("enable.packages", "true");
- super.setUp();
- cluster.deleteAllCollections();
- eventsListener = new AllEventsListener();
- cluster.getOpenOverseer().getCoreContainer().getClusterEventProducer().registerListener(eventsListener);
- }
-
- @After
- public void teardown() {
- System.clearProperty("enable.packages");
- if (eventsListener != null) {
- cluster.getOpenOverseer().getCoreContainer().getClusterEventProducer().unregisterListener(eventsListener);
- }
- }
-
- @Test
- public void testEvents() throws Exception {
-
- // NODES_DOWN
-
- eventsListener.setExpectedType(ClusterEvent.EventType.NODES_DOWN);
-
- // don't kill Overseer
- JettySolrRunner nonOverseerJetty = null;
- for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
- if (cluster.getOpenOverseer().getCoreContainer().getZkController().getNodeName().equals(jetty.getNodeName()))
{
- continue;
- }
- nonOverseerJetty = jetty;
- break;
- }
- String nodeName = nonOverseerJetty.getNodeName();
- cluster.stopJettySolrRunner(nonOverseerJetty);
- cluster.waitForJettyToStop(nonOverseerJetty);
- eventsListener.waitForExpectedEvent(10);
- assertNotNull("should be NODES_DOWN events", eventsListener.events.get(ClusterEvent.EventType.NODES_DOWN));
- List<ClusterEvent> events = eventsListener.events.get(ClusterEvent.EventType.NODES_DOWN);
- assertEquals("should be one NODES_DOWN event", 1, events.size());
- ClusterEvent event = events.get(0);
- assertEquals("should be NODES_DOWN event type", ClusterEvent.EventType.NODES_DOWN, event.getType());
- NodesDownEvent nodesDown = (NodesDownEvent) event;
- assertEquals("should be node " + nodeName, nodeName, nodesDown.getNodeNames().next());
-
- // NODES_UP
- eventsListener.setExpectedType(ClusterEvent.EventType.NODES_UP);
- JettySolrRunner newNode = cluster.startJettySolrRunner();
- cluster.waitForNode(newNode, 60);
- eventsListener.waitForExpectedEvent(10);
- assertNotNull("should be NODES_UP events", eventsListener.events.get(ClusterEvent.EventType.NODES_UP));
- events = eventsListener.events.get(ClusterEvent.EventType.NODES_UP);
- assertEquals("should be one NODES_UP event", 1, events.size());
- event = events.get(0);
- assertEquals("should be NODES_UP event type", ClusterEvent.EventType.NODES_UP, event.getType());
- NodesUpEvent nodesUp = (NodesUpEvent) event;
- assertEquals("should be node " + newNode.getNodeName(), newNode.getNodeName(), nodesUp.getNodeNames().next());
-
- // COLLECTIONS_ADDED
- eventsListener.setExpectedType(ClusterEvent.EventType.COLLECTIONS_ADDED);
- String collection = "testNodesEvent_collection";
- CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collection,
"conf", 1, 1);
- cluster.getSolrClient().request(create);
- cluster.waitForActiveCollection(collection, 1, 1);
- eventsListener.waitForExpectedEvent(10);
- assertNotNull("should be COLLECTIONS_ADDED events", eventsListener.events.get(ClusterEvent.EventType.COLLECTIONS_ADDED));
- events = eventsListener.events.get(ClusterEvent.EventType.COLLECTIONS_ADDED);
- assertEquals("should be one COLLECTIONS_ADDED event", 1, events.size());
- event = events.get(0);
- assertEquals("should be COLLECTIONS_ADDED event type", ClusterEvent.EventType.COLLECTIONS_ADDED,
event.getType());
- CollectionsAddedEvent collectionsAdded = (CollectionsAddedEvent) event;
- assertEquals("should be collection " + collection, collection, collectionsAdded.getCollectionNames().next());
-
- // COLLECTIONS_REMOVED
- eventsListener.setExpectedType(ClusterEvent.EventType.COLLECTIONS_REMOVED);
- CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collection);
- cluster.getSolrClient().request(delete);
- eventsListener.waitForExpectedEvent(10);
- assertNotNull("should be COLLECTIONS_REMOVED events", eventsListener.events.get(ClusterEvent.EventType.COLLECTIONS_REMOVED));
- events = eventsListener.events.get(ClusterEvent.EventType.COLLECTIONS_REMOVED);
- assertEquals("should be one COLLECTIONS_REMOVED event", 1, events.size());
- event = events.get(0);
- assertEquals("should be COLLECTIONS_REMOVED event type", ClusterEvent.EventType.COLLECTIONS_REMOVED,
event.getType());
- CollectionsRemovedEvent collectionsRemoved = (CollectionsRemovedEvent) event;
- assertEquals("should be collection " + collection, collection, collectionsRemoved.getCollectionNames().next());
-
- // CLUSTER_CONFIG_CHANGED
- eventsListener.setExpectedType(ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED);
- ClusterProperties clusterProperties = new ClusterProperties(cluster.getZkClient());
- Map<String, Object> oldProps = new HashMap<>(clusterProperties.getClusterProperties());
- clusterProperties.setClusterProperty("ext.foo", "bar");
- eventsListener.waitForExpectedEvent(10);
- assertNotNull("should be CLUSTER_CONFIG_CHANGED events", eventsListener.events.get(ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED));
- events = eventsListener.events.get(ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED);
- assertEquals("should be one CLUSTER_CONFIG_CHANGED event", 1, events.size());
- event = events.get(0);
- assertEquals("should be CLUSTER_CONFIG_CHANGED event type", ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED,
event.getType());
- ClusterPropertiesChangedEvent propertiesChanged = (ClusterPropertiesChangedEvent) event;
- Map<String, Object> newProps = propertiesChanged.getNewClusterProperties();
- assertEquals("new properties wrong value of the 'ext.foo' property: " + newProps,
- "bar", newProps.get("ext.foo"));
-
- // unset the property
- eventsListener.setExpectedType(ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED);
- clusterProperties.setClusterProperty("ext.foo", null);
- eventsListener.waitForExpectedEvent(10);
- assertNotNull("should be CLUSTER_CONFIG_CHANGED events", eventsListener.events.get(ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED));
- events = eventsListener.events.get(ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED);
- assertEquals("should be two CLUSTER_CONFIG_CHANGED events", 2, events.size());
- event = events.get(1);
- assertEquals("should be CLUSTER_CONFIG_CHANGED event type", ClusterEvent.EventType.CLUSTER_PROPERTIES_CHANGED,
event.getType());
- propertiesChanged = (ClusterPropertiesChangedEvent) event;
- assertEquals("new properties should not have 'ext.foo' property: " + propertiesChanged.getNewClusterProperties(),
- null, propertiesChanged.getNewClusterProperties().get("ext.foo"));
-
- }
-
- private static CountDownLatch dummyEventLatch = new CountDownLatch(1);
- private static ClusterEvent lastEvent = null;
-
- public static class DummyEventListener implements ClusterEventListener {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- boolean running = false;
- @Override
- public void onEvent(ClusterEvent event) {
- if (!running) {
- log.debug("skipped event, not running: {}", event);
- return;
- }
- if (event.getType() == ClusterEvent.EventType.COLLECTIONS_ADDED ||
- event.getType() == ClusterEvent.EventType.COLLECTIONS_REMOVED) {
- log.debug("recorded event {}", Utils.toJSONString(event));
- lastEvent = event;
- dummyEventLatch.countDown();
- } else {
- log.debug("skipped event, wrong type: {}", event.getType());
- }
- }
-
- @Override
- public String getName() {
- return "dummy";
- }
-
- @Override
- public void start() throws Exception {
- log.debug("starting {}", Integer.toHexString(hashCode()));
- running = true;
- }
-
- @Override
- public boolean isRunning() {
- return running;
- }
-
- @Override
- public void stop() {
- log.debug("stopping {}", Integer.toHexString(hashCode()));
- running = false;
- }
- }
-
- @Test
- public void testListenerPlugins() throws Exception {
- PluginMeta plugin = new PluginMeta();
- plugin.name = "testplugin";
- plugin.klass = DummyEventListener.class.getName();
- V2Request req = new V2Request.Builder("/cluster/plugin")
- .forceV2(true)
- .withMethod(POST)
- .withPayload(singletonMap("add", plugin))
- .build();
- V2Response rsp = req.process(cluster.getSolrClient());
- //just check if the plugin is indeed registered
- V2Request readPluginState = new V2Request.Builder("/cluster/plugin")
- .forceV2(true)
- .withMethod(GET)
- .build();
- rsp = readPluginState.process(cluster.getSolrClient());
- assertEquals(DummyEventListener.class.getName(), rsp._getStr("/plugin/testplugin/class",
null));
-
- String collection = "testListenerPlugins_collection";
- CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collection,
"conf", 1, 1);
- cluster.getSolrClient().request(create);
- cluster.waitForActiveCollection(collection, 1, 1);
- boolean await = dummyEventLatch.await(30, TimeUnit.SECONDS);
- if (!await) {
- fail("Timed out waiting for COLLECTIONS_ADDED event, " + collection);
- }
- assertNotNull("lastEvent should be COLLECTIONS_ADDED", lastEvent);
- assertEquals("lastEvent should be COLLECTIONS_ADDED", ClusterEvent.EventType.COLLECTIONS_ADDED,
lastEvent.getType());
- // verify timestamp
- Instant now = Instant.now();
- assertTrue("timestamp of the event is in the future", now.isAfter(lastEvent.getTimestamp()));
- assertEquals(collection, ((CollectionsAddedEvent)lastEvent).getCollectionNames().next());
-
- dummyEventLatch = new CountDownLatch(1);
- lastEvent = null;
-
- CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collection);
- cluster.getSolrClient().request(delete);
- await = dummyEventLatch.await(30, TimeUnit.SECONDS);
- if (!await) {
- fail("Timed out waiting for COLLECTIONS_REMOVED event, " + collection);
- }
- assertNotNull("lastEvent should be COLLECTIONS_REMOVED", lastEvent);
- assertEquals("lastEvent should be COLLECTIONS_REMOVED", ClusterEvent.EventType.COLLECTIONS_REMOVED,
lastEvent.getType());
- // verify timestamp
- now = Instant.now();
- assertTrue("timestamp of the event is in the future", now.isAfter(lastEvent.getTimestamp()));
- assertEquals(collection, ((CollectionsRemovedEvent)lastEvent).getCollectionNames().next());
- }
-}
diff --git a/solr/core/src/test/org/apache/solr/cluster/events/impl/CollectionsRepairEventListenerTest.java
b/solr/core/src/test/org/apache/solr/cluster/events/impl/CollectionsRepairEventListenerTest.java
deleted file mode 100644
index a764051..0000000
--- a/solr/core/src/test/org/apache/solr/cluster/events/impl/CollectionsRepairEventListenerTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.solr.cluster.events.impl;
-
-import org.apache.solr.client.solrj.embedded.JettySolrRunner;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.cloud.SolrCloudTestCase;
-import org.apache.solr.cluster.events.AllEventsListener;
-import org.apache.solr.cluster.events.ClusterEvent;
-import org.apache.solr.cluster.events.ClusterEventListener;
-import org.apache.solr.core.CoreContainer;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-/**
- *
- */
-public class CollectionsRepairEventListenerTest extends SolrCloudTestCase {
-
- public static class CollectionsRepairWrapperListener implements ClusterEventListener {
- final CollectionsRepairEventListener delegate;
-
- CountDownLatch completed = new CountDownLatch(1);
-
- CollectionsRepairWrapperListener(CoreContainer cc) throws Exception {
- delegate = new CollectionsRepairEventListener(cc);
- }
-
- @Override
- public void onEvent(ClusterEvent event) {
- delegate.onEvent(event);
- completed.countDown();
- }
-
- @Override
- public String getName() {
- return "wrapperListener";
- }
-
- @Override
- public void start() throws Exception {
- delegate.start();
- }
-
- @Override
- public boolean isRunning() {
- return delegate.isRunning();
- }
-
- @Override
- public void stop() {
- delegate.stop();
- }
- }
-
- private static AllEventsListener eventsListener = new AllEventsListener();
- private static CollectionsRepairWrapperListener repairListener;
-
- private static int NUM_NODES = 3;
-
- @BeforeClass
- public static void setupCluster() throws Exception {
- configureCluster(NUM_NODES)
- .addConfig("conf", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf"))
- .configure();
- CoreContainer cc = cluster.getOpenOverseer().getCoreContainer();
- cc.getClusterEventProducer()
- .registerListener(eventsListener, ClusterEvent.EventType.values());
- repairListener = new CollectionsRepairWrapperListener(cc);
- cc.getClusterEventProducer()
- .registerListener(repairListener, ClusterEvent.EventType.NODES_DOWN);
- repairListener.start();
- }
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- cluster.deleteAllCollections();
- }
-
- @Test
- public void testCollectionRepair() throws Exception {
- eventsListener.setExpectedType(ClusterEvent.EventType.COLLECTIONS_ADDED);
- String collection = "testCollectionRepair_collection";
- CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collection,
"conf", 1, 3);
- cluster.getSolrClient().request(create);
- cluster.waitForActiveCollection(collection, 1, 3);
- eventsListener.waitForExpectedEvent(10);
- eventsListener.setExpectedType(ClusterEvent.EventType.NODES_DOWN);
-
- // don't kill Overseer
- JettySolrRunner nonOverseerJetty = null;
- for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
- if (cluster.getOpenOverseer().getCoreContainer().getZkController().getNodeName().equals(jetty.getNodeName()))
{
- continue;
- }
- nonOverseerJetty = jetty;
- break;
- }
- String nodeName = nonOverseerJetty.getNodeName();
- cluster.stopJettySolrRunner(nonOverseerJetty);
- cluster.waitForJettyToStop(nonOverseerJetty);
- eventsListener.waitForExpectedEvent(10);
- cluster.waitForActiveCollection(collection, 1, 2);
-
- // wait for completed processing in the repair listener
- boolean await = repairListener.completed.await(60, TimeUnit.SECONDS);
- if (!await) {
- fail("Timeout waiting for the processing to complete");
- }
- cluster.waitForActiveCollection(collection, 1, 3);
- }
-}
diff --git a/solr/core/src/test/org/apache/solr/handler/TestContainerPlugin.java b/solr/core/src/test/org/apache/solr/handler/TestContainerPlugin.java
index bd9bf7c..4c37c17 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestContainerPlugin.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestContainerPlugin.java
@@ -92,8 +92,8 @@ public class TestContainerPlugin extends SolrCloudTestCase {
expectError(req, cluster.getSolrClient(), errPath, "No method with @Command in class");
//test with an invalid class
-// plugin.klass = C1.class.getName();
-// expectError(req, cluster.getSolrClient(), errPath, "No @EndPoints");
+ plugin.klass = C1.class.getName();
+ expectError(req, cluster.getSolrClient(), errPath, "No @EndPoints");
//test with a valid class. This should succeed now
plugin.klass = C3.class.getName();
|