You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:26:42 UTC
[sling-org-apache-sling-discovery-base] 03/07: SLING-5231 : remove
getAdministrativeResourceResolver from discovery components : merged
patches from Carsten
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.discovery.base-1.1.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-base.git
commit e88cbacff5f620ef3cff635458224bcf4b620946
Author: Stefan Egli <st...@apache.org>
AuthorDate: Tue Nov 15 12:38:35 2016 +0000
SLING-5231 : remove getAdministrativeResourceResolver from discovery components : merged patches from Carsten
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/base@1769802 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
.../announcement/AnnouncementRegistryImpl.java | 67 ++++----
.../discovery/base/its/AbstractClusterTest.java | 181 +++++++++++----------
.../base/its/AbstractSingleInstanceTest.java | 22 +--
.../base/its/AbstractTopologyEventTest.java | 45 +++--
.../discovery/base/its/setup/VirtualInstance.java | 17 +-
.../base/its/setup/VirtualInstanceHelper.java | 12 +-
.../setup/mock/DummyResourceResolverFactory.java | 24 ++-
.../base/its/setup/mock/DummyViewChecker.java | 3 +-
.../its/setup/mock/MockedResourceResolver.java | 42 ++++-
10 files changed, 238 insertions(+), 177 deletions(-)
diff --git a/pom.xml b/pom.xml
index d6bf00f..657aa5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -184,7 +184,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.4.0</version>
+ <version>2.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/src/main/java/org/apache/sling/discovery/base/connectors/announcement/AnnouncementRegistryImpl.java b/src/main/java/org/apache/sling/discovery/base/connectors/announcement/AnnouncementRegistryImpl.java
index c983da7..c13d4ab 100644
--- a/src/main/java/org/apache/sling/discovery/base/connectors/announcement/AnnouncementRegistryImpl.java
+++ b/src/main/java/org/apache/sling/discovery/base/connectors/announcement/AnnouncementRegistryImpl.java
@@ -62,17 +62,17 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
private SlingSettingsService settingsService;
private String slingId;
-
+
@Reference
private BaseConfig config;
-
+
public static AnnouncementRegistryImpl testConstructorAndActivate(ResourceResolverFactory resourceResolverFactory,
SlingSettingsService slingSettingsService, BaseConfig config) {
AnnouncementRegistryImpl registry = testConstructor(resourceResolverFactory, slingSettingsService, config);
registry.activate();
return registry;
}
-
+
public static AnnouncementRegistryImpl testConstructor(ResourceResolverFactory resourceResolverFactory,
SlingSettingsService slingSettingsService, BaseConfig config) {
AnnouncementRegistryImpl registry = new AnnouncementRegistryImpl();
@@ -81,22 +81,23 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
registry.config = config;
return registry;
}
-
+
@Activate
protected void activate() {
slingId = settingsService.getSlingId();
}
-
- private final Map<String,CachedAnnouncement> ownAnnouncementsCache =
+
+ private final Map<String,CachedAnnouncement> ownAnnouncementsCache =
new HashMap<String,CachedAnnouncement>();
+ @Override
public synchronized void unregisterAnnouncement(final String ownerId) {
if (ownerId==null || ownerId.length()==0) {
throw new IllegalArgumentException("ownerId must not be null or empty");
}
// remove from the cache - even if there's an error afterwards
ownAnnouncementsCache.remove(ownerId);
-
+
if (resourceResolverFactory == null) {
logger.error("unregisterAnnouncement: resourceResolverFactory is null");
return;
@@ -104,7 +105,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
+ .getServiceResourceResolver(null);
final String path = config.getClusterInstancesPath()
+ "/"
@@ -134,10 +135,12 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
}
}
+ @Override
public synchronized Collection<Announcement> listLocalAnnouncements() {
return fillWithCachedAnnouncements(new LinkedList<Announcement>());
}
-
+
+ @Override
public synchronized Collection<CachedAnnouncement> listLocalIncomingAnnouncements() {
Collection<CachedAnnouncement> result = new LinkedList<CachedAnnouncement>(ownAnnouncementsCache.values());
for (Iterator<CachedAnnouncement> it = result.iterator(); it.hasNext();) {
@@ -153,7 +156,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
}
return result;
}
-
+
private final InstanceDescription getLocalInstanceDescription(final ClusterView localClusterView) {
for (Iterator<InstanceDescription> it = localClusterView.getInstances().iterator(); it
.hasNext();) {
@@ -165,6 +168,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
return null;
}
+ @Override
public synchronized Collection<Announcement> listAnnouncementsInSameCluster(final ClusterView localClusterView) {
logger.debug("listAnnouncementsInSameCluster: start. localClusterView: {}", localClusterView);
if (localClusterView==null) {
@@ -175,7 +179,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
final InstanceDescription localInstance = getLocalInstanceDescription(localClusterView);
try {
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
+ .getServiceResourceResolver(null);
Resource clusterInstancesResource = ResourceHelper
.getOrCreateResource(
@@ -194,7 +198,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
fillWithCachedAnnouncements(incomingAnnouncements);
continue;
}
-
+
//TODO: add ClusterView.contains(instanceSlingId) for convenience to next api change
if (!contains(localClusterView, instanceId)) {
logger.debug("listAnnouncementsInSameCluster: instance is not in my view, ignoring: {}", instanceId);
@@ -221,7 +225,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
String.class));
logger.debug("listAnnouncementsInSameCluster: found announcement: {}", topologyAnnouncement);
incomingAnnouncements.add(topologyAnnouncement);
- // SLING-3389: no longer check for expired announcements -
+ // SLING-3389: no longer check for expired announcements -
// instead make use of the fact that this instance
// has a clusterView and that every live instance
// is responsible of cleaning up expired announcements
@@ -253,7 +257,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
}
return incomingAnnouncements;
}
-
+
private final Collection<Announcement> fillWithCachedAnnouncements(
final Collection<Announcement> incomingAnnouncements) {
for (Iterator<Entry<String, CachedAnnouncement>> it = ownAnnouncementsCache.entrySet().iterator(); it
@@ -280,6 +284,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
return false;
}
+ @Override
public synchronized boolean hasActiveAnnouncement(final String ownerId) {
if (ownerId==null || ownerId.length()==0) {
throw new IllegalArgumentException("ownerId must not be null or empty: "+ownerId);
@@ -288,10 +293,11 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
if (cachedAnnouncement==null) {
return false;
}
-
+
return !cachedAnnouncement.hasExpired();
}
+ @Override
public synchronized long registerAnnouncement(final Announcement topologyAnnouncement) {
if (topologyAnnouncement==null) {
throw new IllegalArgumentException("topologyAnnouncement must not be null");
@@ -304,8 +310,8 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
logger.error("registerAnnouncement: resourceResolverFactory is null");
return -1;
}
-
- final CachedAnnouncement cachedAnnouncement =
+
+ final CachedAnnouncement cachedAnnouncement =
ownAnnouncementsCache.get(topologyAnnouncement.getOwnerId());
if (cachedAnnouncement!=null) {
if (logger.isDebugEnabled()) {
@@ -320,7 +326,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
return cachedAnnouncement.registerPing(topologyAnnouncement, config);
}
logger.debug("registerAnnouncement: incoming announcement differs from existing one!");
-
+
} catch(JSONException e) {
logger.error("registerAnnouncement: got JSONException while converting incoming announcement to JSON: "+e, e);
}
@@ -364,7 +370,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
+ .getServiceResourceResolver(null);
final Resource announcementsResource = ResourceHelper
.getOrCreateResource(
@@ -376,7 +382,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
topologyAnnouncement.persistTo(announcementsResource);
resourceResolver.commit();
- ownAnnouncementsCache.put(topologyAnnouncement.getOwnerId(),
+ ownAnnouncementsCache.put(topologyAnnouncement.getOwnerId(),
new CachedAnnouncement(topologyAnnouncement, config));
} catch (LoginException e) {
logger.error(
@@ -401,12 +407,13 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
return 0;
}
- public synchronized void addAllExcept(final Announcement target, final ClusterView clusterView,
+ @Override
+ public synchronized void addAllExcept(final Announcement target, final ClusterView clusterView,
final AnnouncementFilter filter) {
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
+ .getServiceResourceResolver(null);
final Resource clusterInstancesResource = ResourceHelper
.getOrCreateResource(
@@ -471,14 +478,15 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
}
}
+ @Override
public synchronized void checkExpiredAnnouncements() {
- for (Iterator<Entry<String, CachedAnnouncement>> it =
+ for (Iterator<Entry<String, CachedAnnouncement>> it =
ownAnnouncementsCache.entrySet().iterator(); it.hasNext();) {
final Entry<String, CachedAnnouncement> entry = it.next();
if (entry.getValue().hasExpired()) {
// then we have an expiry
it.remove();
-
+
final String instanceId = entry.getKey();
logger.info("checkExpiredAnnouncements: topology connector of "+instanceId+
" (to me="+slingId+
@@ -496,7 +504,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
boolean requiresCommit = false;
try {
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
+ .getServiceResourceResolver(null);
final Resource announcementsResource = ResourceHelper
.getOrCreateResource(
resourceResolver,
@@ -510,7 +518,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
final String ownerId = res.getName();
// ownerId is the slingId of the owner of the announcement (ie of the peer of the connector).
// let's check if the we have that owner's announcement in the cache
-
+
if (ownAnnouncementsCache.containsKey(ownerId)) {
// fine then, we'll leave this announcement untouched
continue;
@@ -518,7 +526,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
// otherwise this announcement is likely from an earlier incarnation
// of this instance - hence stale - hence we must remove it now
// (SLING-4139)
- ResourceHelper.deleteResource(resourceResolver,
+ ResourceHelper.deleteResource(resourceResolver,
res.getPath());
requiresCommit = true;
}
@@ -548,8 +556,8 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
- ResourceHelper.deleteResource(resourceResolver,
+ .getServiceResourceResolver(null);
+ ResourceHelper.deleteResource(resourceResolver,
config.getClusterInstancesPath()
+ "/"
+ slingId
@@ -575,6 +583,7 @@ public class AnnouncementRegistryImpl implements AnnouncementRegistry {
}
}
+ @Override
public synchronized Collection<InstanceDescription> listInstances(final ClusterView localClusterView) {
logger.debug("listInstances: start. localClusterView: {}", localClusterView);
final Collection<InstanceDescription> instances = new LinkedList<InstanceDescription>();
diff --git a/src/test/java/org/apache/sling/discovery/base/its/AbstractClusterTest.java b/src/test/java/org/apache/sling/discovery/base/its/AbstractClusterTest.java
index 80ff0c0..53d0a7d 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/AbstractClusterTest.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/AbstractClusterTest.java
@@ -36,6 +36,7 @@ import java.util.concurrent.Semaphore;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.RootLogger;
import org.apache.sling.commons.testing.junit.categories.Slow;
import org.apache.sling.discovery.ClusterView;
import org.apache.sling.discovery.InstanceDescription;
@@ -62,17 +63,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractClusterTest {
-
+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
+
private class SimpleClusterView {
-
+
private VirtualInstance[] instances;
SimpleClusterView(VirtualInstance... instances) {
this.instances = instances;
}
-
+
@Override
public String toString() {
String instanceSlingIds = "";
@@ -100,10 +101,10 @@ public abstract class AbstractClusterTest {
private Level logLevel;
protected abstract VirtualInstanceBuilder newBuilder();
-
+
@Before
public void setup() throws Exception {
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
discoveryLogger.setLevel(Level.TRACE);
logger.debug("here we are");
@@ -140,10 +141,10 @@ public abstract class AbstractClusterTest {
instance3 = null;
instance4 = null;
instance5 = null;
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
discoveryLogger.setLevel(logLevel);
}
-
+
/** test leader behaviour with ascending slingIds, SLING-3253 **/
@Test
public void testLeaderAsc() throws Throwable {
@@ -206,11 +207,11 @@ public abstract class AbstractClusterTest {
}
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
-
+
// now they must be in the same cluster, so in a cluster of size 1
assertEquals(2, instance1.getClusterViewService().getLocalClusterView().getInstances().size());
assertEquals(2, instance2.getClusterViewService().getLocalClusterView().getInstances().size());
-
+
// the first instance should be the leader - since it was started first
assertTrue(instance1.getLocalInstanceDescription().isLeader());
assertFalse(instance2.getLocalInstanceDescription().isLeader());
@@ -231,11 +232,11 @@ public abstract class AbstractClusterTest {
public void testStaleAnnouncementsVisibleToClusterPeers4139() throws Throwable {
logger.info("testStaleAnnouncementsVisibleToClusterPeers4139: start");
final String instance1SlingId = prepare4139();
-
+
// remove topology connector from instance3 to instance1
// -> corresponds to stop pinging
// (nothing to assert additionally here)
-
+
// start instance 1
instance1Restarted = newBuilder().setDebugName("firstInstance")
.useRepositoryOf(instance2)
@@ -247,13 +248,13 @@ public abstract class AbstractClusterTest {
runHeartbeatOnceWith(instance1Restarted, instance2, instance3);
Thread.sleep(500);
runHeartbeatOnceWith(instance1Restarted, instance2, instance3);
-
+
// facts: connector 3->1 does not exist actively anymore,
- // instance 1+2 should build a cluster,
+ // instance 1+2 should build a cluster,
// instance 3 should be isolated
logger.info("instance1Restarted.dump: "+instance1Restarted.slingId);
instance1Restarted.dumpRepo();
-
+
logger.info("instance2.dump: "+instance2.slingId);
instance2.dumpRepo();
@@ -266,10 +267,10 @@ public abstract class AbstractClusterTest {
instance1Restarted.stop();
logger.info("testStaleAnnouncementsVisibleToClusterPeers4139: end");
}
-
+
/**
* Tests a situation where a connector was done to instance1, which eventually
- * crashed, then the connector is done to instance2. Meanwhile instance1
+ * crashed, then the connector is done to instance2. Meanwhile instance1
* got restarted and this test assures that the instance3 is not reported
* twice in the topology. Did not happen before 4139, but should never afterwards neither
*/
@@ -277,13 +278,13 @@ public abstract class AbstractClusterTest {
public void testDuplicateInstanceIn2Clusters4139() throws Throwable {
logger.info("testDuplicateInstanceIn2Clusters4139: start");
final String instance1SlingId = prepare4139();
-
+
// remove topology connector from instance3 to instance1
// -> corresponds to stop pinging
// (nothing to assert additionally here)
// instead, now start a connector from instance3 to instance2
pingConnector(instance3, instance2);
-
+
// start instance 1
instance1Restarted = newBuilder().setDebugName("firstInstance")
.useRepositoryOf(instance2)
@@ -300,7 +301,7 @@ public abstract class AbstractClusterTest {
logger.info("instance3.slingId: "+instance3.slingId);
instance1Restarted.dumpRepo();
assertSameTopology(new SimpleClusterView(instance1Restarted, instance2), new SimpleClusterView(instance3));
-
+
Thread.sleep(500);
runHeartbeatOnceWith(instance1Restarted, instance2, instance3);
pingConnector(instance3, instance2);
@@ -316,16 +317,16 @@ public abstract class AbstractClusterTest {
logger.info("testDuplicateInstanceIn2Clusters4139: end");
}
-
+
/* ok, this test should do the following:
* cluster A with instance 1 and instance 2
* cluster B with instance 3 and instance 4
* cluster C with instance 5
-
+
* initially, instance3 is pinging instance1, and instance 5 is pinging instance1 as well (MAC hub)
* that should result in instance3 and 5 to inherit the rest from instance1
- * then simulate load balancer switching from instance1 to instance2 - hence pings go to instance2
- *
+ * then simulate load balancer switching from instance1 to instance2 - hence pings go to instance2
+ *
*/
@Category(Slow.class) //TODO: this takes env 45sec
@Test
@@ -333,10 +334,10 @@ public abstract class AbstractClusterTest {
final int MIN_EVENT_DELAY = 1;
tearDown(); // reset any setup that was done - we start with a different setup than the default one
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
discoveryLogger.setLevel(Level.DEBUG);
-
+
instance1 = newBuilder().setDebugName("instance1")
.newRepository("/var/discovery/clusterA/", true)
.setConnectorPingTimeout(10 /* sec */)
@@ -375,7 +376,7 @@ public abstract class AbstractClusterTest {
assertSameTopology(new SimpleClusterView(instance1, instance2));
assertSameTopology(new SimpleClusterView(instance3, instance4));
assertSameTopology(new SimpleClusterView(instance5));
-
+
// create a topology connector from instance3 to instance1
// -> corresponds to starting to ping
runHeartbeatOnceWith(instance1, instance2, instance3, instance4, instance5);
@@ -386,7 +387,7 @@ public abstract class AbstractClusterTest {
pingConnector(instance3, instance1);
pingConnector(instance5, instance1);
Thread.sleep(500);
-
+
// make asserts on the topology
logger.info("testConnectorSwitching4139: instance1.slingId="+instance1.slingId);
logger.info("testConnectorSwitching4139: instance2.slingId="+instance2.slingId);
@@ -394,11 +395,11 @@ public abstract class AbstractClusterTest {
logger.info("testConnectorSwitching4139: instance4.slingId="+instance4.slingId);
logger.info("testConnectorSwitching4139: instance5.slingId="+instance5.slingId);
instance1.dumpRepo();
-
- assertSameTopology(new SimpleClusterView(instance1, instance2),
- new SimpleClusterView(instance3, instance4),
+
+ assertSameTopology(new SimpleClusterView(instance1, instance2),
+ new SimpleClusterView(instance3, instance4),
new SimpleClusterView(instance5));
-
+
// simulate a crash of instance1, resulting in load-balancer to switch the pings
boolean success = false;
for(int i=0; i<25; i++) {
@@ -419,7 +420,7 @@ public abstract class AbstractClusterTest {
}
logger.info("testConnectorSwitching4139: looping cos ping1="+ping1+", ping2="+ping2);
Thread.sleep(1000); // 25x1000ms = 25sec max - (vs 10sec timeout)
-
+
}
assertTrue(success);
// one final heartbeat
@@ -429,8 +430,8 @@ public abstract class AbstractClusterTest {
instance2.dumpRepo();
- assertSameTopology(new SimpleClusterView(instance2),
- new SimpleClusterView(instance3, instance4),
+ assertSameTopology(new SimpleClusterView(instance2),
+ new SimpleClusterView(instance3, instance4),
new SimpleClusterView(instance5));
// restart instance1, crash instance4
@@ -455,7 +456,7 @@ public abstract class AbstractClusterTest {
// an establishedView as failing upon detecting a view change
// when the view changes, we're sending TOPOLOGY_CHANGING to listeners
// so getTopology() should also return isCurrent==false - which
- // means that doing a ping will also fail, cos that wants to
+ // means that doing a ping will also fail, cos that wants to
// get a current topology to send as an announcement.
// which is a long way of saying: we cannot do an assert here
// since instance3 *can* have an undefined cluster view..
@@ -500,8 +501,8 @@ public abstract class AbstractClusterTest {
instance1Restarted.dumpRepo();
assertTrue(success);
- assertSameTopology(new SimpleClusterView(instance1Restarted, instance2),
- new SimpleClusterView(instance3),
+ assertSameTopology(new SimpleClusterView(instance1Restarted, instance2),
+ new SimpleClusterView(instance3),
new SimpleClusterView(instance5));
instance1Restarted.stop();
@@ -514,10 +515,10 @@ public abstract class AbstractClusterTest {
final int MIN_EVENT_DELAY = 1;
tearDown(); // reset any setup that was done - we start with a different setup than the default one
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
discoveryLogger.setLevel(Level.DEBUG);
-
+
instance1 = newBuilder().setDebugName("instance1")
.newRepository("/var/discovery/clusterA/", true)
.setConnectorPingTimeout(15 /* sec */)
@@ -547,25 +548,25 @@ public abstract class AbstractClusterTest {
assertSameTopology(new SimpleClusterView(instance1, instance2));
assertSameTopology(new SimpleClusterView(instance3));
assertSameTopology(new SimpleClusterView(instance5));
-
+
// create a topology connector from instance3 to instance1
// -> corresponds to starting to ping
pingConnector(instance3, instance1);
pingConnector(instance5, instance1);
pingConnector(instance3, instance1);
pingConnector(instance5, instance1);
-
+
// make asserts on the topology
logger.info("testDuplicateInstance3726: instance1.slingId="+instance1.slingId);
logger.info("testDuplicateInstance3726: instance2.slingId="+instance2.slingId);
logger.info("testDuplicateInstance3726: instance3.slingId="+instance3.slingId);
logger.info("testDuplicateInstance3726: instance5.slingId="+instance5.slingId);
instance1.dumpRepo();
-
- assertSameTopology(new SimpleClusterView(instance1, instance2),
- new SimpleClusterView(instance3/*, instance4*/),
+
+ assertSameTopology(new SimpleClusterView(instance1, instance2),
+ new SimpleClusterView(instance3/*, instance4*/),
new SimpleClusterView(instance5));
-
+
// simulate a crash of instance1, resulting in load-balancer to switch the pings
instance1.stopViewChecker();
boolean success = false;
@@ -587,7 +588,7 @@ public abstract class AbstractClusterTest {
}
logger.info("testDuplicateInstance3726: looping");
Thread.sleep(1000); // 25x1000ms = 25sec max - (vs 15sec timeout)
-
+
}
assertTrue(success);
// one final heartbeat
@@ -597,8 +598,8 @@ public abstract class AbstractClusterTest {
instance2.dumpRepo();
- assertSameTopology(new SimpleClusterView(instance2),
- new SimpleClusterView(instance3),
+ assertSameTopology(new SimpleClusterView(instance2),
+ new SimpleClusterView(instance3),
new SimpleClusterView(instance5));
// restart instance1, start instance4
@@ -614,7 +615,7 @@ public abstract class AbstractClusterTest {
for(int i=0; i<3; i++) {
runHeartbeatOnceWith(instance1Restarted, instance2, instance3, instance4, instance5);
Thread.sleep(250);
- // since instance4 just started - hooked to instance3
+ // since instance4 just started - hooked to instance3
// it is possible that it doesn't just have a topology
// yet - so we cannot do:
//assertTrue(pingConnector(instance3, instance2));
@@ -635,8 +636,8 @@ public abstract class AbstractClusterTest {
logger.info("testDuplicateInstance3726: instance5.slingId="+instance5.slingId);
assertTrue(success);
- assertSameTopology(new SimpleClusterView(instance1Restarted, instance2),
- new SimpleClusterView(instance3, instance4),
+ assertSameTopology(new SimpleClusterView(instance1Restarted, instance2),
+ new SimpleClusterView(instance3, instance4),
new SimpleClusterView(instance5));
instance1Restarted.stop();
logger.info("testDuplicateInstance3726: end");
@@ -646,7 +647,7 @@ public abstract class AbstractClusterTest {
if (clusters==null) {
return;
}
- for(int i=0; i<clusters.length; i++) { // go through all clusters
+ for(int i=0; i<clusters.length; i++) { // go through all clusters
final SimpleClusterView aCluster = clusters[i];
assertSameClusterIds(aCluster.instances);
for(int j=0; j<aCluster.instances.length; j++) { // and all instances therein
@@ -676,7 +677,7 @@ public abstract class AbstractClusterTest {
/**
* Tests a situation where a connector was done to instance1, which eventually
- * crashed, then the connector is done to instance4 (which is in a separate, 3rd cluster).
+ * crashed, then the connector is done to instance4 (which is in a separate, 3rd cluster).
* Meanwhile instance1 got restarted and this test assures that the instance3 is not reported
* twice in the topology. This used to happen prior to SLING-4139
*/
@@ -684,11 +685,11 @@ public abstract class AbstractClusterTest {
public void testStaleInstanceIn3Clusters4139() throws Throwable {
logger.info("testStaleInstanceIn3Clusters4139: start");
final String instance1SlingId = prepare4139();
-
+
// remove topology connector from instance3 to instance1
// -> corresponds to stop pinging
// (nothing to assert additionally here)
-
+
// start instance4 in a separate cluster
instance4 = newBuilder().setDebugName("remoteInstance4")
.newRepository("/var/discovery/implremote4/", false)
@@ -700,12 +701,12 @@ public abstract class AbstractClusterTest {
} catch(UndefinedClusterViewException e) {
// ok
}
-
+
// instead, now start a connector from instance3 to instance2
instance4.heartbeatsAndCheckView();
instance4.heartbeatsAndCheckView();
pingConnector(instance3, instance4);
-
+
// start instance 1
instance1Restarted = newBuilder().setDebugName("firstInstance")
.useRepositoryOf(instance2)
@@ -726,7 +727,7 @@ public abstract class AbstractClusterTest {
new SimpleClusterView(instance3),
new SimpleClusterView(instance4));
assertSameTopology(new SimpleClusterView(instance1Restarted, instance2));
-
+
Thread.sleep(100);
runHeartbeatOnceWith(instance1Restarted, instance2, instance3, instance4);
pingConnector(instance3, instance4);
@@ -746,7 +747,7 @@ public abstract class AbstractClusterTest {
Thread.sleep(100);
runHeartbeatOnceWith(instance1Restarted, instance2, instance3, instance4);
pingConnector(instance3, instance4);
-
+
// now the situation should be as follows:
logger.info("iteration 2");
logger.info("instance1Restarted.slingId: "+instance1Restarted.slingId);
@@ -762,7 +763,7 @@ public abstract class AbstractClusterTest {
logger.info("testStaleInstanceIn3Clusters4139: end");
}
-
+
/**
* Preparation steps for SLING-4139 tests:
* Creates two clusters: A: with instance1 and 2, B with instance 3
@@ -788,7 +789,7 @@ public abstract class AbstractClusterTest {
Thread.sleep(100);
runHeartbeatOnceWith(instance1, instance2);
assertSameClusterIds(instance1, instance2);
-
+
// now launch the remote instance
instance3 = newBuilder().setDebugName("remoteInstance")
.newRepository("/var/discovery/implremote/", false)
@@ -807,7 +808,7 @@ public abstract class AbstractClusterTest {
assertEquals(0, instance2.getAnnouncementRegistry().listLocalIncomingAnnouncements().size());
assertEquals(0, instance3.getAnnouncementRegistry().listLocalAnnouncements().size());
assertEquals(0, instance3.getAnnouncementRegistry().listLocalIncomingAnnouncements().size());
-
+
// create a topology connector from instance3 to instance1
// -> corresponds to starting to ping
instance3.heartbeatsAndCheckView();
@@ -817,7 +818,7 @@ public abstract class AbstractClusterTest {
// make asserts on the topology
instance1.dumpRepo();
assertSameTopology(new SimpleClusterView(instance1, instance2), new SimpleClusterView(instance3));
-
+
// kill instance 1
logger.info("instance1.slingId="+instance1.slingId);
logger.info("instance2.slingId="+instance2.slingId);
@@ -842,7 +843,7 @@ public abstract class AbstractClusterTest {
instance3.getConfig().setViewCheckTimeout(Integer.MAX_VALUE /* no timeout */); // set instance3's heartbeatTimeout back to Integer.MAX_VALUE /* no timeout */
return instance1SlingId;
}
-
+
private void assertNotSameClusterIds(VirtualInstance... instances) throws UndefinedClusterViewException {
if (instances==null) {
fail("must not pass empty set of instances here");
@@ -998,12 +999,12 @@ public abstract class AbstractClusterTest {
// statusDetails = null;
}
- private Announcement ping(VirtualInstance to, final Announcement incomingTopologyAnnouncement)
+ private Announcement ping(VirtualInstance to, final Announcement incomingTopologyAnnouncement)
throws UndefinedClusterViewException {
final String slingId = to.slingId;
final ClusterViewService clusterViewService = to.getClusterViewService();
final AnnouncementRegistry announcementRegistry = to.getAnnouncementRegistry();
-
+
incomingTopologyAnnouncement.removeInherited(slingId);
final Announcement replyAnnouncement = new Announcement(
@@ -1034,6 +1035,7 @@ public abstract class AbstractClusterTest {
announcementRegistry.addAllExcept(replyAnnouncement, clusterView,
new AnnouncementFilter() {
+ @Override
public boolean accept(final String receivingSlingId, Announcement announcement) {
if (announcement.getPrimaryKey().equals(
incomingTopologyAnnouncement
@@ -1055,11 +1057,12 @@ public abstract class AbstractClusterTest {
final ClusterView clusterView = from.getClusterViewService().getLocalClusterView();
topologyAnnouncement.setLocalCluster(clusterView);
from.getAnnouncementRegistry().addAllExcept(topologyAnnouncement, clusterView, new AnnouncementFilter() {
-
+
+ @Override
public boolean accept(final String receivingSlingId, final Announcement announcement) {
// filter out announcements that are of old cluster instances
// which I dont really have in my cluster view at the moment
- final Iterator<InstanceDescription> it =
+ final Iterator<InstanceDescription> it =
clusterView.getInstances().iterator();
while(it.hasNext()) {
final InstanceDescription instance = it.next();
@@ -1119,18 +1122,18 @@ public abstract class AbstractClusterTest {
Thread.sleep(500);
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
-
+
String newClusterId1 = instance1.getClusterViewService()
.getLocalClusterView().getId();
String newClusterId2 = instance2.getClusterViewService()
.getLocalClusterView().getId();
// both cluster ids must be the same
assertEquals(newClusterId1, newClusterId1);
-
+
instance1.dumpRepo();
assertEquals(2, instance1.getClusterViewService().getLocalClusterView().getInstances().size());
assertEquals(2, instance2.getClusterViewService().getLocalClusterView().getInstances().size());
-
+
// let instance2 'die' by now longer doing heartbeats
// SLING-4302 : then set the heartbeatTimeouts back to 1 sec to have them properly time out with the sleeps applied below
instance2.getConfig().setViewCheckTimeout(1);
@@ -1168,7 +1171,7 @@ public abstract class AbstractClusterTest {
assertEquals(newClusterId1, actualClusterId);
logger.info("testStableClusterId: end");
}
-
+
@Test
public void testClusterView() throws Exception {
logger.info("testClusterView: start");
@@ -1399,26 +1402,27 @@ public abstract class AbstractClusterTest {
throw new IllegalStateException("instance not found: instance="
+ instance + ", slingId=" + slingId);
}
-
+
class LongRunningListener implements TopologyEventListener {
-
+
String failMsg = null;
-
+
boolean initReceived = false;
int noninitReceived;
private Semaphore changedSemaphore = new Semaphore(0);
-
+
public void assertNoFail() {
if (failMsg!=null) {
fail(failMsg);
}
}
-
+
public Semaphore getChangedSemaphore() {
return changedSemaphore;
}
-
+
+ @Override
public void handleTopologyEvent(TopologyEvent event) {
if (failMsg!=null) {
failMsg += "/ Already failed, got another event; "+event;
@@ -1442,7 +1446,7 @@ public abstract class AbstractClusterTest {
noninitReceived++;
}
}
-
+
/**
* Test plan:
* * have a discoveryservice with two listeners registered
@@ -1457,7 +1461,7 @@ public abstract class AbstractClusterTest {
* and that the first listener is still busy, make
* sure that once the first listener finishes, that
* the second listener still gets the event
- * @throws Throwable
+ * @throws Throwable
*/
@Category(Slow.class) //TODO: this takes env 15sec
@Test
@@ -1475,7 +1479,7 @@ public abstract class AbstractClusterTest {
instance1.heartbeatsAndCheckView();
logger.info("testLongRunningListener : instance 2 should now be considered dead");
// instance1.dumpRepo();
-
+
LongRunningListener longRunningListener1 = new LongRunningListener();
AssertingTopologyEventListener fastListener2 = new AssertingTopologyEventListener();
fastListener2.addExpected(Type.TOPOLOGY_INIT);
@@ -1489,7 +1493,7 @@ public abstract class AbstractClusterTest {
Thread.sleep(2500); // SLING-4755: async event sending requires some minimal wait time nowadays
assertEquals(0, fastListener2.getRemainingExpectedCount());
assertTrue(longRunningListener1.initReceived);
-
+
// after INIT, now do an actual change where listener1 will do a long-running handling
fastListener2.addExpected(Type.TOPOLOGY_CHANGING);
fastListener2.addExpected(Type.TOPOLOGY_CHANGED);
@@ -1504,7 +1508,7 @@ public abstract class AbstractClusterTest {
instance1.heartbeatsAndCheckView();
instance2.heartbeatsAndCheckView();
Thread.sleep(500);
-
+
instance1.dumpRepo();
longRunningListener1.assertNoFail();
// nothing unexpected should arrive at listener2:
@@ -1521,12 +1525,13 @@ public abstract class AbstractClusterTest {
assertEquals(1, fastListener2.getRemainingExpectedCount());
assertEquals(1, longRunningListener1.noninitReceived);
assertTrue(longRunningListener1.getChangedSemaphore().hasQueuedThreads());
-
+
// now let's simulate SLING-4755: deactivation while longRunningListener1 does long processing
// - which is simulated by waiting on changedSemaphore.
final List<Exception> asyncException = new LinkedList<Exception>();
Thread th = new Thread(new Runnable() {
+ @Override
public void run() {
try {
instance1.stop();
@@ -1536,7 +1541,7 @@ public abstract class AbstractClusterTest {
}
}
}
-
+
});
th.start();
logger.info("Waiting max 4 sec...");
@@ -1557,7 +1562,7 @@ public abstract class AbstractClusterTest {
fail("async exceptions: "+asyncException.size()+", first: "+asyncException.get(0));
}
}
-
+
// now the test consists of
// a) the fact that we reached this place without unlocking the changedSemaphore
// b) when we now unlock the changedSemaphore the remaining events should flush through
@@ -1569,5 +1574,5 @@ public abstract class AbstractClusterTest {
assertFalse(longRunningListener1.getChangedSemaphore().hasQueuedThreads());
}
-
+
}
diff --git a/src/test/java/org/apache/sling/discovery/base/its/AbstractSingleInstanceTest.java b/src/test/java/org/apache/sling/discovery/base/its/AbstractSingleInstanceTest.java
index 7d4229b..e0157f7 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/AbstractSingleInstanceTest.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/AbstractSingleInstanceTest.java
@@ -30,7 +30,7 @@ import java.util.Map;
import java.util.UUID;
import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.RootLogger;
import org.apache.sling.discovery.ClusterView;
import org.apache.sling.discovery.InstanceDescription;
import org.apache.sling.discovery.TopologyEvent;
@@ -55,12 +55,12 @@ public abstract class AbstractSingleInstanceTest {
String propertyValue;
private Level logLevel;
-
+
protected abstract VirtualInstanceBuilder newBuilder();
@Before
public void setup() throws Exception {
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
discoveryLogger.setLevel(Level.DEBUG);
logger.info("setup: creating new standalone instance");
@@ -74,7 +74,7 @@ public abstract class AbstractSingleInstanceTest {
@After
public void tearDown() throws Exception {
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
discoveryLogger.setLevel(logLevel);
logger.info("tearDown: stopping standalone instance");
if (instance!=null) {
@@ -99,7 +99,7 @@ public abstract class AbstractSingleInstanceTest {
instance.heartbeatsAndCheckView();
// wait 4000ms for the vote to happen
Thread.sleep(4000);
-
+
assertNotNull(instance.getClusterViewService().getLocalClusterView());
ClusterView cv = instance.getClusterViewService().getLocalClusterView();
logger.info("cluster view: id=" + cv.getId());
@@ -155,14 +155,14 @@ public abstract class AbstractSingleInstanceTest {
.getProperty(UUID.randomUUID().toString()));
logger.info("testPropertyProviders: end");
}
-
+
@Test
public void testInvalidProperties() throws Throwable {
logger.info("testInvalidProperties: start");
-
+
instance.heartbeatsAndCheckView();
instance.heartbeatsAndCheckView();
-
+
final String propertyValue = UUID.randomUUID().toString();
Thread.sleep(2000);
doTestProperty(UUID.randomUUID().toString(), propertyValue, propertyValue);
@@ -187,7 +187,7 @@ public abstract class AbstractSingleInstanceTest {
instance.getClusterViewService().getLocalClusterView()
.getInstances().get(0).getProperty(propertyName));
}
-
+
@Test
public void testTopologyEventListeners() throws Throwable {
logger.info("testTopologyEventListeners: start");
@@ -270,7 +270,7 @@ public abstract class AbstractSingleInstanceTest {
} catch(UndefinedClusterViewException e) {
// ok
}
-
+
ada.addExpected(Type.TOPOLOGY_INIT);
instance.heartbeatsAndCheckView();
Thread.sleep(1000);
@@ -292,5 +292,5 @@ public abstract class AbstractSingleInstanceTest {
instance.assertEstablishedView();
logger.info("testBootstrap: end");
}
-
+
}
diff --git a/src/test/java/org/apache/sling/discovery/base/its/AbstractTopologyEventTest.java b/src/test/java/org/apache/sling/discovery/base/its/AbstractTopologyEventTest.java
index 82094b8..04eab4d 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/AbstractTopologyEventTest.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/AbstractTopologyEventTest.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.RootLogger;
import org.apache.sling.discovery.TopologyEvent;
import org.apache.sling.discovery.TopologyEvent.Type;
import org.apache.sling.discovery.TopologyView;
@@ -33,7 +33,6 @@ import org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder;
import org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,14 +49,14 @@ public abstract class AbstractTopologyEventTest {
private VirtualInstance instance2;
private Level logLevel;
-
+
@Before
public void setup() throws Exception {
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
logLevel = discoveryLogger.getLevel();
discoveryLogger.setLevel(Level.DEBUG);
}
-
+
@After
public void tearDown() throws Throwable {
if (instance1!=null) {
@@ -70,16 +69,16 @@ public abstract class AbstractTopologyEventTest {
instance2.stop();
instance2 = null;
}
- final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+ final org.apache.log4j.Logger discoveryLogger = RootLogger.getLogger("org.apache.sling.discovery");
discoveryLogger.setLevel(logLevel);
}
-
+
public abstract VirtualInstanceBuilder newBuilder();
-
+
/**
* Tests the fact that the INIT event is delayed until voting has succeeded
* (which is the default with SLIGN-5030 and SLING-4959
- * @throws Throwable
+ * @throws Throwable
*/
@Test
public void testDelayedInitEvent() throws Throwable {
@@ -92,7 +91,7 @@ public abstract class AbstractTopologyEventTest {
l1.addExpected(Type.TOPOLOGY_INIT);
instance1.bindTopologyEventListener(l1);
logger.info("testDelayedInitEvent: instance1 created, no events expected yet. slingId="+instance1.slingId);
-
+
instance1.heartbeatsAndCheckView();
Thread.sleep(1200);
instance1.heartbeatsAndCheckView();
@@ -104,7 +103,7 @@ public abstract class AbstractTopologyEventTest {
assertEquals(1, l1.getEvents().size()); // one event
assertEquals(0, l1.getRemainingExpectedCount()); // the expected one
assertEquals(0, l1.getUnexpectedCount());
-
+
logger.info("testDelayedInitEvent: creating instance2");
instance2 = newBuilder().setDebugName("secondInstanceB")
.useRepositoryOf(instance1)
@@ -118,10 +117,10 @@ public abstract class AbstractTopologyEventTest {
l1Two.addExpected(Type.TOPOLOGY_INIT);
logger.info("testDelayedInitEvent: listener instance1.l1Two added - it expects an INIT now");
instance1.bindTopologyEventListener(l1Two);
-
+
Thread.sleep(500); // SLING-4755: async event sending requires some minimal wait time nowadays
- // just because instance2 is started doesn't kick off any events yet
+ // just because instance2 is started doesn't kick off any events yet
// since instance2 didn't send heartbeats yet
assertEquals(1, l1.getEvents().size()); // one event
assertEquals(0, l1.getRemainingExpectedCount()); // the expected one
@@ -131,8 +130,8 @@ public abstract class AbstractTopologyEventTest {
assertEquals(1, l1Two.getEvents().size());
assertEquals(0, l1Two.getRemainingExpectedCount()); // the expected one
assertEquals(0, l1Two.getUnexpectedCount());
-
-
+
+
// the second & third heartbeat though triggers the voting etc
logger.info("testDelayedInitEvent: two more heartbeats should trigger events");
l1.addExpected(Type.TOPOLOGY_CHANGING);
@@ -174,7 +173,7 @@ public abstract class AbstractTopologyEventTest {
assertEquals(3, l1Two.getEvents().size());
logger.info("testDelayedInitEvent: end");
}
-
+
@Test
public void testGetDuringDelay() throws Throwable {
instance1 = newBuilder().setDebugName("firstInstanceA")
@@ -184,12 +183,12 @@ public abstract class AbstractTopologyEventTest {
AssertingTopologyEventListener l1 = new AssertingTopologyEventListener("instance1.l1");
l1.addExpected(TopologyEvent.Type.TOPOLOGY_INIT);
instance1.bindTopologyEventListener(l1);
-
+
TopologyView earlyTopo = instance1.getDiscoveryService().getTopology();
assertNotNull(earlyTopo);
assertFalse(earlyTopo.isCurrent());
assertEquals(1, earlyTopo.getInstances().size());
-
+
for(int i=0; i<4; i++) {
instance1.heartbeatsAndCheckView();
Thread.sleep(125);
@@ -199,14 +198,14 @@ public abstract class AbstractTopologyEventTest {
assertEquals(instance1.getSlingId(), secondTopo.getInstances().iterator().next().getSlingId());
assertTrue(secondTopo.isCurrent());
instance1.dumpRepo();
-
+
assertEarlyAndFirstClusterViewIdMatches(earlyTopo, secondTopo);
Thread.sleep(500);
// should have gotten the INIT, hence 0 remaining expected events
assertEquals(0, l1.getRemainingExpectedCount());
assertEquals(0, l1.getUnexpectedCount());
-
+
l1.addExpected(TopologyEvent.Type.TOPOLOGY_CHANGING);
instance2 = newBuilder().setDebugName("secondInstanceB")
.useRepositoryOf(instance1)
@@ -221,7 +220,7 @@ public abstract class AbstractTopologyEventTest {
instance1.heartbeatsAndCheckView();
Thread.sleep(750);
}
-
+
assertEquals(0, l1.getUnexpectedCount());
TopologyView topo2 = instance2.getDiscoveryService().getTopology();
assertTrue(topo2.isCurrent());
@@ -229,7 +228,7 @@ public abstract class AbstractTopologyEventTest {
TopologyView topo1 = instance1.getDiscoveryService().getTopology();
assertTrue(topo1.isCurrent());
assertEquals(2, topo1.getInstances().size());
-
+
l1.addExpected(TopologyEvent.Type.TOPOLOGY_CHANGED);
Thread.sleep(5000);
assertEquals(0, l1.getRemainingExpectedCount());
@@ -243,5 +242,5 @@ public abstract class AbstractTopologyEventTest {
}
public abstract void assertEarlyAndFirstClusterViewIdMatches(TopologyView earlyTopo, TopologyView secondTopo);
-
+
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java b/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
index 0309d91..7bd9b16 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
@@ -118,12 +118,13 @@ public class VirtualInstance {
stopping_ = true;
this.notifyAll();
}
-
+
public boolean hasStopped() {
return stopped_;
}
- public void run() {
+ @Override
+ public void run() {
try{
doRun();
} finally {
@@ -131,7 +132,7 @@ public class VirtualInstance {
logger.info("Instance ["+slingId+"] stopped.");
}
}
-
+
public void doRun() {
while(true) {
synchronized(this) {
@@ -157,7 +158,7 @@ public class VirtualInstance {
}
}
-
+
public VirtualInstance(VirtualInstanceBuilder builder) throws Exception {
this.builder = builder;
this.slingId = builder.getSlingId();
@@ -187,7 +188,7 @@ public class VirtualInstance {
osgiMock.addServices(builder.getAdditionalServices(this));
resourceResolver = resourceResolverFactory
- .getAdministrativeResourceResolver(null);
+ .getServiceResourceResolver(null);
if (builder.isResetRepo()) {
//SLING-4587 : do resetRepo before creating the observationListener
@@ -199,11 +200,11 @@ public class VirtualInstance {
osgiMock.activateAll();
}
-
+
public void setDelay(String operationDescriptor, long delayMillis) {
delay.setDelay(operationDescriptor, delayMillis);
}
-
+
@Override
public String toString() {
return "a [Test]Instance[slingId="+slingId+", debugName="+debugName+"]";
@@ -357,7 +358,7 @@ public class VirtualInstance {
public void dumpRepo() throws Exception {
VirtualInstanceHelper.dumpRepo(resourceResolverFactory);
}
-
+
public ResourceResolverFactory getResourceResolverFactory() {
return resourceResolverFactory;
}
diff --git a/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstanceHelper.java b/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstanceHelper.java
index ffbaff4..5388428 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstanceHelper.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstanceHelper.java
@@ -36,15 +36,15 @@ public class VirtualInstanceHelper {
public static void dumpRepo(ResourceResolverFactory resourceResolverFactory) throws Exception {
Session session = resourceResolverFactory
- .getAdministrativeResourceResolver(null).adaptTo(Session.class);
+ .getServiceResourceResolver(null).adaptTo(Session.class);
logger.info("dumpRepo: ====== START =====");
logger.info("dumpRepo: repo = " + session.getRepository());
-
+
dump(session.getRootNode());
-
+
// session.logout();
logger.info("dumpRepo: ====== END =====");
-
+
session.logout();
}
@@ -54,7 +54,7 @@ public class VirtualInstanceHelper {
// ignore that one
return;
}
-
+
PropertyIterator pi = node.getProperties();
StringBuilder sb = new StringBuilder();
while (pi.hasNext()) {
@@ -72,7 +72,7 @@ public class VirtualInstanceHelper {
sb.append("<unknown type=" + p.getType() + "/>");
}
}
-
+
StringBuffer depth = new StringBuffer();
for(int i=0; i<node.getDepth(); i++) {
depth.append(" ");
diff --git a/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyResourceResolverFactory.java b/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyResourceResolverFactory.java
index ab1f2a1..49e1ced 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyResourceResolverFactory.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyResourceResolverFactory.java
@@ -38,26 +38,40 @@ public class DummyResourceResolverFactory implements ResourceResolverFactory {
private ArtificialDelay delay;
public DummyResourceResolverFactory() {
-
+
}
-
+
public void setSlingRepository(SlingRepository repository) {
this.repository = repository;
}
-
+
public void setArtificialDelay(ArtificialDelay delay) {
this.delay = delay;
}
-
+
@Override
public ResourceResolver getResourceResolver(Map<String, Object> authenticationInfo) throws LoginException {
throw new IllegalStateException("not yet implemented");
}
+
+ @Override
+ public ResourceResolver getServiceResourceResolver(Map<String, Object> arg0) throws LoginException {
+ try {
+ MockedResourceResolver mockedResourceResolver =
+ new MockedResourceResolver(repository, delay);
+ repository = (SlingRepository) mockedResourceResolver.getRepository();
+ return mockedResourceResolver;
+ } catch (RepositoryException e) {
+ throw new LoginException(e);
+ }
+ }
+
@Override
+ @Deprecated
public ResourceResolver getAdministrativeResourceResolver(Map<String, Object> authenticationInfo) throws LoginException {
try {
- MockedResourceResolver mockedResourceResolver =
+ MockedResourceResolver mockedResourceResolver =
new MockedResourceResolver(repository, delay);
repository = (SlingRepository) mockedResourceResolver.getRepository();
return mockedResourceResolver;
diff --git a/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyViewChecker.java b/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyViewChecker.java
index e83556c..f6bb69a 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyViewChecker.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/setup/mock/DummyViewChecker.java
@@ -18,7 +18,6 @@
*/
package org.apache.sling.discovery.base.its.setup.mock;
-import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.scheduler.Scheduler;
import org.apache.sling.discovery.base.commons.BaseViewChecker;
@@ -28,7 +27,7 @@ import org.apache.sling.discovery.base.connectors.ping.ConnectorRegistry;
import org.apache.sling.settings.SlingSettingsService;
public class DummyViewChecker extends BaseViewChecker {
-
+
protected SlingSettingsService slingSettingsService;
protected ResourceResolverFactory resourceResolverFactory;
diff --git a/src/test/java/org/apache/sling/discovery/base/its/setup/mock/MockedResourceResolver.java b/src/test/java/org/apache/sling/discovery/base/its/setup/mock/MockedResourceResolver.java
index e4a49a1..a25d017 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/setup/mock/MockedResourceResolver.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/setup/mock/MockedResourceResolver.java
@@ -44,13 +44,10 @@ import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.testing.jcr.RepositoryProvider;
import org.apache.sling.commons.testing.jcr.RepositoryUtil;
import org.apache.sling.jcr.api.SlingRepository;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MockedResourceResolver implements ResourceResolver {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
private final SlingRepository repository;
private Session session;
@@ -66,7 +63,7 @@ public class MockedResourceResolver implements ResourceResolver {
public MockedResourceResolver(SlingRepository repositoryOrNull) throws RepositoryException {
this(repositoryOrNull, null);
}
-
+
public MockedResourceResolver(SlingRepository repositoryOrNull, ArtificialDelay delay) throws RepositoryException {
this.delay = delay;
if (repositoryOrNull==null) {
@@ -108,6 +105,7 @@ public class MockedResourceResolver implements ResourceResolver {
}
+ @Override
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (type.equals(Session.class)) {
@@ -122,27 +120,33 @@ public class MockedResourceResolver implements ResourceResolver {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Resource resolve(HttpServletRequest request, String absPath) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Resource resolve(String absPath) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
@Deprecated
public Resource resolve(HttpServletRequest request) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public String map(String resourcePath) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public String map(HttpServletRequest request, String resourcePath) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Resource getResource(String path) {
Session session;
try {
@@ -156,6 +160,7 @@ public class MockedResourceResolver implements ResourceResolver {
return new MockedResource(this, path, "nt:unstructured");
}
+ @Override
public Resource getResource(Resource base, String path) {
if (base.getPath().equals("/")) {
return getResource("/" + path);
@@ -164,20 +169,24 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public String[] getSearchPath() {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Iterator<Resource> listChildren(Resource parent) {
try {
Node node = parent.adaptTo(Node.class);
final NodeIterator nodes = node.getNodes();
return new Iterator<Resource>() {
+ @Override
public void remove() {
throw new UnsupportedOperationException();
}
+ @Override
public Resource next() {
Node next = nodes.nextNode();
try {
@@ -189,6 +198,7 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public boolean hasNext() {
return nodes.hasNext();
}
@@ -198,28 +208,34 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public Iterable<Resource> getChildren(Resource parent) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Iterator<Resource> findResources(String query, String language) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Iterator<Map<String, Object>> queryResources(String query,
String language) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public ResourceResolver clone(Map<String, Object> authenticationInfo)
throws LoginException {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public boolean isLive() {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public void close() {
Iterator<MockedResource> it = resources.iterator();
while (it.hasNext()) {
@@ -238,18 +254,22 @@ public class MockedResourceResolver implements ResourceResolver {
resources.add(mockedResource);
}
+ @Override
public String getUserID() {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Iterator<String> getAttributeNames() {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public Object getAttribute(String name) {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public void delete(Resource resource) throws PersistenceException {
if (resources.contains(resource)) {
resources.remove(resource);
@@ -264,6 +284,7 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public Resource create(Resource parent, String name,
Map<String, Object> properties) throws PersistenceException {
final Node parentNode = parent.adaptTo(Node.class);
@@ -305,6 +326,7 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public void revert() {
try {
this.session.refresh(false);
@@ -313,6 +335,7 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public void commit() throws PersistenceException {
if (delay!=null) {
delay.delay("pre.commit");
@@ -324,28 +347,39 @@ public class MockedResourceResolver implements ResourceResolver {
}
}
+ @Override
public boolean hasChanges() {
throw new UnsupportedOperationException("Not implemented");
}
+ @Override
public String getParentResourceType(Resource resource) {
// TODO Auto-generated method stub
return null;
}
+ @Override
public String getParentResourceType(String resourceType) {
// TODO Auto-generated method stub
return null;
}
+ @Override
public boolean isResourceType(Resource resource, String resourceType) {
// TODO Auto-generated method stub
return false;
}
+ @Override
public void refresh() {
// TODO Auto-generated method stub
}
+ @Override
+ public boolean hasChildren(Resource arg0) {
+ // TODO Auto-generated method stub
+ return this.getChildren(arg0).iterator().hasNext();
+ }
+
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.