You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2015/10/21 17:50:37 UTC

svn commit: r1709867 [3/3] - in /sling/trunk/bundles/extensions/discovery/oak: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/discovery/ src/main/java/org/apa...

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakClusterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakClusterTest.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakClusterTest.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakClusterTest.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.discovery.oak.its;
+
+import org.apache.sling.discovery.base.its.AbstractClusterTest;
+import org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder;
+import org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder;
+
+public class OakClusterTest extends AbstractClusterTest {
+
+    @Override
+    protected VirtualInstanceBuilder newBuilder() {
+        return new OakVirtualInstanceBuilder();
+    }
+
+}

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakClusterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakSingleInstanceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakSingleInstanceTest.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakSingleInstanceTest.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakSingleInstanceTest.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.discovery.oak.its;
+
+import org.apache.sling.discovery.base.its.AbstractSingleInstanceTest;
+import org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder;
+import org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder;
+
+public class OakSingleInstanceTest extends AbstractSingleInstanceTest {
+
+    @Override
+    protected VirtualInstanceBuilder newBuilder() {
+        return new OakVirtualInstanceBuilder();
+    }
+
+}

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakSingleInstanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakTopologyEventTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakTopologyEventTest.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakTopologyEventTest.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakTopologyEventTest.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,43 @@
+/*
+ * 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.sling.discovery.oak.its;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.discovery.TopologyView;
+import org.apache.sling.discovery.base.its.AbstractTopologyEventTest;
+import org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder;
+import org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder;
+
+public class OakTopologyEventTest extends AbstractTopologyEventTest {
+
+    @Override
+    public VirtualInstanceBuilder newBuilder() {
+        return new OakVirtualInstanceBuilder();
+    }
+
+    @Override
+    public void assertEarlyAndFirstClusterViewIdMatches(TopologyView earlyTopo, TopologyView secondTopo) {
+        // for the oak discovery-lite variant there's nothing we can assert here
+        // except perhaps that they shouldn't be null..
+        assertNotNull(earlyTopo);
+        assertNotNull(secondTopo);
+    }
+    
+}

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/OakTopologyEventTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakTestConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakTestConfig.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakTestConfig.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakTestConfig.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,80 @@
+/*
+ * 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.sling.discovery.oak.its.setup;
+
+import org.apache.sling.discovery.base.its.setup.ModifiableTestBaseConfig;
+import org.apache.sling.discovery.oak.Config;
+
+public class OakTestConfig extends Config implements ModifiableTestBaseConfig {
+
+    public OakTestConfig() {
+        // empty
+    }
+    
+    public void setDiscoveryResourcePath(String discoveryResourcePath) {
+        this.discoveryResourcePath = discoveryResourcePath;
+    }
+
+    public void setMinEventDelay(int minEventDelay) {
+        this.minEventDelay = minEventDelay;
+    }
+
+    public void addTopologyConnectorWhitelistEntry(String whitelistEntry) {
+        if (topologyConnectorWhitelist==null) {
+            topologyConnectorWhitelist = new String[] {whitelistEntry};
+        } else {
+            String[] list = topologyConnectorWhitelist;
+            topologyConnectorWhitelist = new String[list.length+1];
+            System.arraycopy(list, 0, topologyConnectorWhitelist, 0, list.length);
+            topologyConnectorWhitelist[topologyConnectorWhitelist.length-1] = whitelistEntry;
+        }
+    }
+
+    @Override
+    public int getBackoffStableFactor() {
+        return 1;
+    }
+
+    @Override
+    public int getBackoffStandbyFactor() {
+        return 1;
+    }
+
+    public void setConnectorInterval(long connectorInterval) {
+        this.connectorPingInterval = connectorInterval;
+    }
+
+    public void setConnectorTimeout(long connectorTimeout) {
+        this.connectorPingTimeout = connectorTimeout;
+    }
+    
+    @Override
+    public void setViewCheckTimeout(int viewCheckTimeout) {
+        setConnectorTimeout(viewCheckTimeout);
+    }
+
+    @Override
+    public void setViewCheckInterval(int viewCheckInterval) {
+        setConnectorInterval(viewCheckInterval);
+    }
+    
+    public long getViewCheckerTimeout() {
+        return connectorPingTimeout;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakTestConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakVirtualInstanceBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakVirtualInstanceBuilder.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakVirtualInstanceBuilder.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakVirtualInstanceBuilder.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,259 @@
+/*
+ * 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.sling.discovery.oak.its.setup;
+
+import static org.junit.Assert.fail;
+
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.discovery.base.commons.BaseDiscoveryService;
+import org.apache.sling.discovery.base.commons.ClusterViewService;
+import org.apache.sling.discovery.base.commons.ViewChecker;
+import org.apache.sling.discovery.base.its.setup.ModifiableTestBaseConfig;
+import org.apache.sling.discovery.base.its.setup.VirtualInstance;
+import org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder;
+import org.apache.sling.discovery.base.its.setup.mock.MockFactory;
+import org.apache.sling.discovery.commons.providers.spi.base.IdMapService;
+import org.apache.sling.discovery.commons.providers.spi.base.OakSyncTokenConsistencyService;
+import org.apache.sling.discovery.commons.providers.spi.base.RepositoryTestHelper;
+import org.apache.sling.discovery.oak.OakDiscoveryService;
+import org.apache.sling.discovery.oak.cluster.OakClusterViewService;
+import org.apache.sling.discovery.oak.pinger.OakViewChecker;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junitx.util.PrivateAccessor;
+
+public class OakVirtualInstanceBuilder extends VirtualInstanceBuilder {
+
+    NodeStore nodeStore;
+    private String path;
+    private OakTestConfig config;
+    private IdMapService idMapService;
+    private OakViewChecker oakViewChecker;
+    private SimulatedLeaseCollection leaseCollection;
+    private OakSyncTokenConsistencyService consistencyService;
+    
+    @Override
+    public VirtualInstanceBuilder createNewRepository() throws Exception {
+        nodeStore = new MemoryNodeStore();
+        SlingRepository repository = RepositoryTestHelper.newOakRepository(nodeStore);
+        factory = MockFactory.mockResourceResolverFactory(repository);
+        leaseCollection = new SimulatedLeaseCollection();
+        return this;
+    }
+    
+    @Override
+    public VirtualInstanceBuilder useRepositoryOf(VirtualInstanceBuilder other) throws Exception {
+        if (!(other instanceof OakVirtualInstanceBuilder)) {
+            throw new IllegalArgumentException("other must be of type OakVirtualInstanceBuilder but is: "+other);
+        }
+        OakVirtualInstanceBuilder otherOakbuilder = (OakVirtualInstanceBuilder)other;
+        nodeStore = otherOakbuilder.nodeStore;
+        SlingRepository repository = RepositoryTestHelper.newOakRepository(nodeStore);
+        factory = MockFactory.mockResourceResolverFactory(repository);
+        leaseCollection = otherOakbuilder.leaseCollection;
+        hookedToBuilder = other;
+        ownRepository = false;
+        return this;
+    }
+
+    @Override
+    public VirtualInstanceBuilder setPath(String path) {
+        this.path = path;
+        return this;
+    }
+
+    @Override
+    public Object[] getAdditionalServices(VirtualInstance instance) throws Exception {
+        return null;
+    }
+    
+    public IdMapService getIdMapService() {
+        if (idMapService==null) {
+            idMapService = createIdMapService();
+        }
+        return idMapService;
+    }
+
+    private IdMapService createIdMapService() {
+        return IdMapService.testConstructor(getConfig(), getSlingSettingsService(), getResourceResolverFactory());
+    }
+
+    @Override
+    protected ClusterViewService createClusterViewService() {
+        return OakClusterViewService.testConstructor(getSlingSettingsService(), getResourceResolverFactory(), getIdMapService(), getConfig());
+    }
+    
+    OakTestConfig getConfig() {
+        if (config==null) {
+            config = createConfig();
+        }
+        return config;
+    }
+    
+    @Override
+    public ModifiableTestBaseConfig getConnectorConfig() {
+        return getConfig();
+    }
+    
+    private OakTestConfig createConfig() {
+        OakTestConfig c = new OakTestConfig();
+        c.setDiscoveryResourcePath(path);
+        return c;
+    }
+    
+    @Override
+    protected ViewChecker createViewChecker() throws Exception {
+        getOakViewChecker();
+        return new ViewChecker() {
+            
+            private final Logger logger = LoggerFactory.getLogger(getClass());
+
+            private SimulatedLease lease = new SimulatedLease(getResourceResolverFactory(), leaseCollection, getSlingId());
+            
+            protected void activate(ComponentContext c) throws Throwable {
+                OakViewChecker pinger = getOakViewChecker();
+                PrivateAccessor.invoke(pinger, "activate", new Class[] {ComponentContext.class}, new Object[] {c});
+            }
+            
+            @Override
+            public void checkView() {
+                try {
+                    lease.updateDescriptor(getConfig());
+                } catch (Exception e) {
+                    logger.error("run: could not update lease: "+e);
+                }
+            }
+            
+            public void run() {
+                heartbeatAndCheckView();
+            }
+            
+            @Override
+            public void heartbeatAndCheckView() {
+//                next step is try to simulate the logic
+//                where no heartbeat means no descriptor yet
+//                one heartbeat means i'm visible for others
+//                as soon as I see others the descriptor is updated
+                try {
+                    lease.updateLeaseAndDescriptor(getConfig());
+                } catch (Exception e) {
+                    logger.error("run: could not update lease: "+e, e);
+                }
+                try{
+                    getOakViewChecker().run();
+                } catch(Exception e) {
+                    logger.error("run: could not ping: "+e, e);
+                }
+                if (!getIdMapService().isInitialized()) {
+                    if (!getIdMapService().waitForInit(1500)) {
+                        fail("init didnt work");
+                    }
+                }
+            }
+        };
+    }
+
+    private OakViewChecker getOakViewChecker() throws Exception {
+        if (oakViewChecker==null) {
+            oakViewChecker = createOakViewChecker() ;
+        }
+        return oakViewChecker;
+    }
+
+    private OakViewChecker createOakViewChecker() throws Exception {
+        return OakViewChecker.testConstructor(getSlingSettingsService(), getResourceResolverFactory(), getConnectorRegistry(), getAnnouncementRegistry(), getScheduler(), getConfig());
+    }
+
+    private OakSyncTokenConsistencyService getConsistencyService() throws Exception {
+        if (consistencyService == null) {
+            consistencyService = createConsistencyService();
+        }
+        return consistencyService;
+    }
+    
+    private OakSyncTokenConsistencyService createConsistencyService() {
+        return OakSyncTokenConsistencyService.testConstructorAndActivate(getConfig(), getIdMapService(), getSlingSettingsService(), getResourceResolverFactory());
+    }
+
+    @Override
+    protected BaseDiscoveryService createDiscoveryService() throws Exception {
+        return OakDiscoveryService.testConstructor(
+                getSlingSettingsService(), 
+                getAnnouncementRegistry(), 
+                getConnectorRegistry(), 
+                getClusterViewService(), 
+                getConfig(), 
+                getOakViewChecker(), 
+                getScheduler(), 
+                getIdMapService(), 
+                getConsistencyService(), 
+                getResourceResolverFactory());
+    }
+
+    @Override
+    public VirtualInstance build() throws Exception {
+        if (path==null) {
+            if (ownRepository) {
+                setPath("/var/discovery/impl/");
+                getConfig().setDiscoveryResourcePath("/var/discovery/impl/");
+            } else {
+                OakVirtualInstanceBuilder other = (OakVirtualInstanceBuilder) hookedToBuilder;
+                this.path = other.path;
+                getConfig().setDiscoveryResourcePath(other.path);
+            }
+        }
+        if (path==null) {
+            throw new IllegalStateException("no path set");
+        }
+        if (!path.startsWith("/")) {
+            throw new IllegalStateException("path must start with /: "+path);
+        }
+        if (!path.endsWith("/")) {
+            throw new IllegalStateException("path must end with /: "+path);
+        }
+        VirtualInstance result = new VirtualInstance(this) {
+
+        };
+        return result;
+    }
+    
+    @Override
+    protected void resetRepo() throws Exception {
+        leaseCollection.reset();
+        ResourceResolver rr = null;
+        Session l = null;
+        try {
+            rr = factory.getAdministrativeResourceResolver(null);
+            l = rr.adaptTo(Session.class);
+            l.removeItem("/var");
+            l.save();
+            l.logout();
+        } catch (Exception e) {
+            l.refresh(false);
+            l.logout();
+        }
+    }
+}

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/OakVirtualInstanceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLease.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLease.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLease.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLease.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,59 @@
+/*
+ * 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.sling.discovery.oak.its.setup;
+
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.discovery.commons.providers.spi.base.DescriptorHelper;
+import org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder;
+
+public class SimulatedLease {
+
+    private final SimulatedLeaseCollection collection;
+    private final ResourceResolverFactory factory;
+    private final String slingId;
+
+    public SimulatedLease(ResourceResolverFactory factory,
+            SimulatedLeaseCollection collection,
+            String slingId) {
+        this.factory = factory;
+        this.collection = collection;
+        collection.hooked(this);
+        this.slingId = slingId;
+    }
+    
+    @Override
+    public String toString() {
+        return "a SimulatedLease[slingId="+slingId+"]";
+    }
+    
+    public String getSlingId() {
+        return slingId;
+    }
+
+    public void updateDescriptor(OakTestConfig config) throws Exception {
+        DiscoveryLiteDescriptorBuilder builder = collection.getDescriptorFor(this, config);
+        DescriptorHelper.setDiscoveryLiteDescriptor(factory, builder);
+    }
+    
+    public void updateLeaseAndDescriptor(OakTestConfig config) throws Exception {
+        DiscoveryLiteDescriptorBuilder builder = collection.updateAndGetDescriptorFor(this, config);
+        DescriptorHelper.setDiscoveryLiteDescriptor(factory, builder);
+    }
+
+}

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLease.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java Wed Oct 21 15:50:37 2015
@@ -0,0 +1,102 @@
+/*
+ * 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.sling.discovery.oak.its.setup;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+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 {
+
+    private final Map<String,Long> leaseUpdates = 
+            new HashMap<String, Long>();
+    
+    private final Map<String,Integer> clusterNodeIds =
+            new HashMap<String, Integer>();
+    
+    private int highestId = 0;
+    
+    private final String viewId = UUID.randomUUID().toString();
+    
+    List<SimulatedLease> leases = new LinkedList<SimulatedLease>();
+    
+    public SimulatedLeaseCollection() {
+        // empty
+    }
+    
+    public synchronized void hooked(SimulatedLease lease) {
+        leases.add(lease);
+    }
+
+    public synchronized DiscoveryLiteDescriptorBuilder getDescriptorFor(SimulatedLease simulatedLease, OakTestConfig config) {
+        return doUpdateAndGet(simulatedLease, config, false);
+    }
+    
+    public synchronized DiscoveryLiteDescriptorBuilder updateAndGetDescriptorFor(SimulatedLease simulatedLease, OakTestConfig config) {
+        return doUpdateAndGet(simulatedLease, config, true);
+    }
+
+    private DiscoveryLiteDescriptorBuilder doUpdateAndGet(SimulatedLease simulatedLease, OakTestConfig config, boolean updateLease) {
+        int clusterNodeId = getClusterNodeId(simulatedLease.getSlingId());
+        if (updateLease) {
+            leaseUpdates.put(simulatedLease.getSlingId(), System.currentTimeMillis());
+        }
+        DiscoveryLiteDescriptorBuilder discoBuilder = 
+                new DiscoveryLiteDescriptorBuilder();
+        discoBuilder.me(clusterNodeId);
+        discoBuilder.id(viewId);
+        discoBuilder.setFinal(true);       
+        List<Integer> actives = new LinkedList<Integer>();
+        List<Integer> inactives = new LinkedList<Integer>();
+        for (Map.Entry<String, Long> entry : leaseUpdates.entrySet()) {
+            int id = getClusterNodeId(entry.getKey());
+            if (isTimedout(entry.getValue(), config)) {
+                inactives.add(id);
+            } else {
+                actives.add(id);
+            }
+        }
+        discoBuilder.activeIds(actives.toArray(new Integer[0]));
+        discoBuilder.inactiveIds(inactives.toArray(new Integer[0]));
+        return discoBuilder;
+    }
+
+    private boolean isTimedout(Long lastHeartbeat, OakTestConfig config) {
+        return System.currentTimeMillis() > lastHeartbeat + (1000 * config.getViewCheckerTimeout());
+    }
+
+    private int getClusterNodeId(String slingId) {
+        Integer id = clusterNodeIds.get(slingId);
+        if (id==null) {
+            id = ++highestId;
+            clusterNodeIds.put(slingId, id);
+        }
+        return id;
+    }
+
+    public void reset() {
+        clusterNodeIds.clear();
+    }
+
+}

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/java/org/apache/sling/discovery/oak/its/setup/SimulatedLeaseCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/bundles/extensions/discovery/oak/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/oak/src/test/resources/log4j.properties?rev=1709867&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/oak/src/test/resources/log4j.properties (added)
+++ sling/trunk/bundles/extensions/discovery/oak/src/test/resources/log4j.properties Wed Oct 21 15:50:37 2015
@@ -0,0 +1,26 @@
+# 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.
+
+log4j.rootLogger=INFO, stdout
+
+log4j.logger.org.apache.jackrabbit.core.TransientRepository=WARN
+#log4j.logger.org.apache.sling.discovery.impl=DEBUG
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+#log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L)\n
+log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m\n

Propchange: sling/trunk/bundles/extensions/discovery/oak/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native