Search in sources :

Example 1 with DiscoveryLiteDescriptorBuilder

use of org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder in project sling by apache.

the class OakDiscoveryServiceTest method testBindBeforeActivate.

@Test
public void testBindBeforeActivate() throws Exception {
    OakVirtualInstanceBuilder builder = (OakVirtualInstanceBuilder) new OakVirtualInstanceBuilder().setDebugName("test").newRepository("/foo/bar", true);
    String slingId = UUID.randomUUID().toString();
    ;
    DiscoveryLiteDescriptorBuilder discoBuilder = new DiscoveryLiteDescriptorBuilder();
    discoBuilder.id("id").me(1).activeIds(1);
    // make sure the discovery-lite descriptor is marked as not final
    // such that the view is not already set before we want it to be
    discoBuilder.setFinal(false);
    DescriptorHelper.setDiscoveryLiteDescriptor(builder.getResourceResolverFactory(), discoBuilder);
    IdMapService idMapService = IdMapService.testConstructor(new SimpleCommonsConfig(1000, -1), new DummySlingSettingsService(slingId), builder.getResourceResolverFactory());
    assertTrue(idMapService.waitForInit(2000));
    OakDiscoveryService discoveryService = (OakDiscoveryService) builder.getDiscoverService();
    assertNotNull(discoveryService);
    DummyListener listener = new DummyListener();
    for (int i = 0; i < 100; i++) {
        discoveryService.bindTopologyEventListener(listener);
        discoveryService.unbindTopologyEventListener(listener);
    }
    discoveryService.bindTopologyEventListener(listener);
    assertEquals(0, listener.countEvents());
    discoveryService.activate(null);
    assertEquals(0, listener.countEvents());
    // some more confusion...
    discoveryService.unbindTopologyEventListener(listener);
    discoveryService.bindTopologyEventListener(listener);
    // only set the final flag now - this makes sure that handlePotentialTopologyChange
    // will actually detect a valid new, different view and send out an event -
    // exactly as we want to
    discoBuilder.setFinal(true);
    DescriptorHelper.setDiscoveryLiteDescriptor(builder.getResourceResolverFactory(), discoBuilder);
    discoveryService.checkForTopologyChange();
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    discoveryService.unbindTopologyEventListener(listener);
    assertEquals(1, listener.countEvents());
    discoveryService.bindTopologyEventListener(listener);
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    // should now have gotten an INIT too
    assertEquals(2, listener.countEvents());
}
Also used : OakVirtualInstanceBuilder(org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder) IdMapService(org.apache.sling.discovery.commons.providers.spi.base.IdMapService) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService) DiscoveryLiteDescriptorBuilder(org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder) DummyListener(org.apache.sling.discovery.commons.providers.base.DummyListener) Test(org.junit.Test)

Example 2 with DiscoveryLiteDescriptorBuilder

use of org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder in project sling by apache.

the class SimulatedLease method updateDescriptor.

public void updateDescriptor(OakTestConfig config) throws Exception {
    DiscoveryLiteDescriptorBuilder builder = collection.getDescriptorFor(this, config);
    DescriptorHelper.setDiscoveryLiteDescriptor(factory, builder);
}
Also used : DiscoveryLiteDescriptorBuilder(org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder)

Example 3 with DiscoveryLiteDescriptorBuilder

use of org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder in project sling by apache.

the class SimulatedLease method updateLeaseAndDescriptor.

public void updateLeaseAndDescriptor(OakTestConfig config) throws Exception {
    DiscoveryLiteDescriptorBuilder builder = collection.updateAndGetDescriptorFor(this, config);
    DescriptorHelper.setDiscoveryLiteDescriptor(factory, builder);
}
Also used : DiscoveryLiteDescriptorBuilder(org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder)

Example 4 with DiscoveryLiteDescriptorBuilder

use of org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder in project sling by apache.

the class SimulatedLeaseCollection method doUpdateAndGet.

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(isFinal);
    discoBuilder.seq(seqNum);
    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;
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) DiscoveryLiteDescriptorBuilder(org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder) LinkedList(java.util.LinkedList)

Aggregations

DiscoveryLiteDescriptorBuilder (org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder)4 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 DummyListener (org.apache.sling.discovery.commons.providers.base.DummyListener)1 DummySlingSettingsService (org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)1 IdMapService (org.apache.sling.discovery.commons.providers.spi.base.IdMapService)1 OakVirtualInstanceBuilder (org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder)1 Test (org.junit.Test)1