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:28:00 UTC
[sling-org-apache-sling-discovery-oak] 03/10: SLING-5256 : change
in localClusterSyncTokenId should always trigger a TOPOLOGY_CHANGED -
ensured by adjusting ViewStateManager.onlyDiffersInProperties and
DefaultTopologyView.compareTopology accordingly including new tests for
both - plus added OakDiscoveryServiceTest.testDescriptorSeqNumChange to
verify that discovery.oak now properly detects otherwise-equal topologies
when their sequence_number==localClusterSyncTokenId differs (unlikely to
happen under normal load situations though)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.discovery.oak-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-oak.git
commit 917cac3a452db396cbc7227089dfb11f935ecb3a
Author: Stefan Egli <st...@apache.org>
AuthorDate: Wed Nov 4 10:37:59 2015 +0000
SLING-5256 : change in localClusterSyncTokenId should always trigger a TOPOLOGY_CHANGED - ensured by adjusting ViewStateManager.onlyDiffersInProperties and DefaultTopologyView.compareTopology accordingly including new tests for both - plus added OakDiscoveryServiceTest.testDescriptorSeqNumChange to verify that discovery.oak now properly detects otherwise-equal topologies when their sequence_number==localClusterSyncTokenId differs (unlikely to happen under normal load situations though)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/oak@1712527 13f79535-47bb-0310-9956-ffa450edef68
---
.../discovery/oak/OakDiscoveryServiceTest.java | 54 ++++++++++++++++++++++
.../oak/its/setup/SimulatedLeaseCollection.java | 25 +++++++++-
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/src/test/java/org/apache/sling/discovery/oak/OakDiscoveryServiceTest.java b/src/test/java/org/apache/sling/discovery/oak/OakDiscoveryServiceTest.java
index f1b965a..a756dc1 100644
--- a/src/test/java/org/apache/sling/discovery/oak/OakDiscoveryServiceTest.java
+++ b/src/test/java/org/apache/sling/discovery/oak/OakDiscoveryServiceTest.java
@@ -24,13 +24,18 @@ import static org.junit.Assert.assertTrue;
import java.util.UUID;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.discovery.base.its.setup.VirtualInstance;
import org.apache.sling.discovery.commons.providers.base.DummyListener;
import org.apache.sling.discovery.commons.providers.spi.base.DescriptorHelper;
import org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteConfig;
+import org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptor;
import org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder;
import org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService;
import org.apache.sling.discovery.commons.providers.spi.base.IdMapService;
import org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder;
+import org.apache.sling.discovery.oak.its.setup.SimulatedLeaseCollection;
import org.junit.Test;
public class OakDiscoveryServiceTest {
@@ -113,4 +118,53 @@ public class OakDiscoveryServiceTest {
assertEquals(2, listener.countEvents()); // should now have gotten an INIT too
}
+ @Test
+ public void testDescriptorSeqNumChange() throws Exception {
+ OakVirtualInstanceBuilder builder1 =
+ (OakVirtualInstanceBuilder) new OakVirtualInstanceBuilder()
+ .setDebugName("instance1")
+ .newRepository("/foo/barry/foo/", true)
+ .setConnectorPingInterval(999)
+ .setConnectorPingTimeout(999);
+ VirtualInstance instance1 = builder1.build();
+ OakVirtualInstanceBuilder builder2 =
+ (OakVirtualInstanceBuilder) new OakVirtualInstanceBuilder()
+ .setDebugName("instance2")
+ .useRepositoryOf(instance1)
+ .setConnectorPingInterval(999)
+ .setConnectorPingTimeout(999);
+ VirtualInstance instance2 = builder2.build();
+
+ DummyListener listener = new DummyListener();
+ OakDiscoveryService discoveryService = (OakDiscoveryService) instance1.getDiscoveryService();
+ discoveryService.bindTopologyEventListener(listener);
+
+ assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
+ assertEquals(0, listener.countEvents());
+
+ instance1.heartbeatsAndCheckView();
+ instance2.heartbeatsAndCheckView();
+ instance1.heartbeatsAndCheckView();
+ instance2.heartbeatsAndCheckView();
+
+ assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
+ assertEquals(1, listener.countEvents());
+
+ ResourceResolverFactory factory = instance1.getResourceResolverFactory();
+ ResourceResolver resolver = factory.getAdministrativeResourceResolver(null);
+
+ instance1.heartbeatsAndCheckView();
+ assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
+ assertEquals(1, listener.countEvents());
+
+ // increment the seqNum by 2 - simulating a coming and going instance
+ // while we were sleeping
+ SimulatedLeaseCollection c = builder1.getSimulatedLeaseCollection();
+ c.incSeqNum(2);
+
+ instance1.heartbeatsAndCheckView();
+ assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
+ assertEquals(3, listener.countEvents());
+ }
+
}
diff --git a/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java b/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java
index 02abf26..5e21926 100644
--- a/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java
+++ b/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java
@@ -25,7 +25,6 @@ import java.util.Map;
import java.util.UUID;
import org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder;
-import org.apache.sling.discovery.oak.Config;
public class SimulatedLeaseCollection {
@@ -42,11 +41,32 @@ public class SimulatedLeaseCollection {
List<SimulatedLease> leases = new LinkedList<SimulatedLease>();
private volatile boolean isFinal = true;
+
+ private int seqNum = 0;
public SimulatedLeaseCollection() {
// empty
}
+ public int getSeqNum() {
+ return seqNum;
+ }
+
+ public void setSeqNum(int seqNum) {
+ this.seqNum = seqNum;
+ }
+
+ public void incSeqNum() {
+ seqNum++;
+ }
+
+ public void incSeqNum(int amount) {
+ if (amount<=0) {
+ throw new IllegalArgumentException("amount must be >0, is: "+amount);
+ }
+ seqNum+=amount;
+ }
+
public synchronized void hooked(SimulatedLease lease) {
leases.add(lease);
}
@@ -68,7 +88,8 @@ public class SimulatedLeaseCollection {
new DiscoveryLiteDescriptorBuilder();
discoBuilder.me(clusterNodeId);
discoBuilder.id(viewId);
- discoBuilder.setFinal(isFinal);
+ discoBuilder.setFinal(isFinal);
+ discoBuilder.seq(seqNum);
List<Integer> actives = new LinkedList<Integer>();
List<Integer> inactives = new LinkedList<Integer>();
for (Map.Entry<String, Long> entry : leaseUpdates.entrySet()) {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.