Search in sources :

Example 1 with DummySlingSettingsService

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

the class AnnouncementRegistryImplTest method setup.

@Before
public void setup() throws Exception {
    resourceResolverFactory = MockFactory.mockResourceResolverFactory();
    config = new SimpleConnectorConfig() {

        public long getConnectorPingTimeout() {
            // 10s for tests that also run on apache jenkins
            return 10;
        }

        ;
    };
    slingId = UUID.randomUUID().toString();
    Session l = RepositoryProvider.instance().getRepository().loginAdministrative(null);
    try {
        l.removeItem("/var");
        l.save();
        l.logout();
    } catch (Exception e) {
        l.refresh(false);
        l.logout();
    }
    registry = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(slingId), config);
}
Also used : SimpleConnectorConfig(org.apache.sling.discovery.base.its.setup.mock.SimpleConnectorConfig) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService) Session(javax.jcr.Session) Before(org.junit.Before)

Example 2 with DummySlingSettingsService

use of org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService 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 3 with DummySlingSettingsService

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

the class VotingHandlerTest method heartbeat.

private void heartbeat(String slingId) throws Exception {
    HeartbeatHandler hh = HeartbeatHandler.testConstructor(new DummySlingSettingsService(slingId), factory, null, null, config, null, votingHandler1);
    OSGiMock.activate(hh);
    HeartbeatHelper.issueClusterLocalHeartbeat(hh);
}
Also used : HeartbeatHandler(org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)

Example 4 with DummySlingSettingsService

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

the class VotingHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    slingId1 = UUID.randomUUID().toString();
    slingId2 = UUID.randomUUID().toString();
    slingId3 = UUID.randomUUID().toString();
    slingId4 = UUID.randomUUID().toString();
    slingId5 = UUID.randomUUID().toString();
    factory = new DummyResourceResolverFactory();
    resetRepo();
    config = new TestConfig("/var/discovery/impltesting/");
    config.setHeartbeatInterval(999);
    config.setHeartbeatTimeout(60);
    votingHandler1 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId1), factory, config);
    votingHandler2 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId2), factory, config);
    votingHandler3 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId3), factory, config);
    votingHandler4 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId4), factory, config);
    votingHandler5 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId5), factory, config);
    resourceResolver = factory.getServiceResourceResolver(null);
    ModifiableThreadPoolConfig tpConfig = new ModifiableThreadPoolConfig();
    tpConfig.setMinPoolSize(80);
    tpConfig.setMaxPoolSize(80);
    threadPool = new DefaultThreadPool("testing", tpConfig);
}
Also used : DummyResourceResolverFactory(org.apache.sling.discovery.base.its.setup.mock.DummyResourceResolverFactory) TestConfig(org.apache.sling.discovery.impl.setup.TestConfig) DefaultThreadPool(org.apache.sling.commons.threads.impl.DefaultThreadPool) ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService) Before(org.junit.Before)

Example 5 with DummySlingSettingsService

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

the class ConnectorRegistryImplTest method testRegisterUnregister.

@Test
public void testRegisterUnregister() throws Exception {
    BaseConfig config = new SimpleConnectorConfig() {

        @Override
        public long getConnectorPingTimeout() {
            return 20000;
        }
    };
    AnnouncementRegistryImpl announcementRegistry = AnnouncementRegistryImpl.testConstructorAndActivate(MockFactory.mockResourceResolverFactory(), new DummySlingSettingsService(UUID.randomUUID().toString()), config);
    ConnectorRegistry c = ConnectorRegistryImpl.testConstructor(announcementRegistry, config);
    final URL url = new URL("http://localhost:1234/connector");
    final ClusterViewService cvs = i.getClusterViewService();
    try {
        c.registerOutgoingConnector(null, url);
        fail("should have complained");
    } catch (IllegalArgumentException e) {
    // ok
    }
    try {
        c.registerOutgoingConnector(cvs, null);
        fail("should have complained");
    } catch (IllegalArgumentException e) {
    // ok
    }
    TopologyConnectorClientInformation client = c.registerOutgoingConnector(cvs, url);
    try {
        // should not be able to register same url twice
        client = c.registerOutgoingConnector(cvs, url);
    // ok - no longer complains - SLING-3446
    } catch (IllegalStateException e) {
        // SLING-3446
        fail("should no longer be thrown");
    }
    try {
        c.unregisterOutgoingConnector(null);
        fail("should have complained");
    } catch (IllegalArgumentException e) {
    // ok
    }
    c.unregisterOutgoingConnector(client.getId());
}
Also used : SimpleConnectorConfig(org.apache.sling.discovery.base.its.setup.mock.SimpleConnectorConfig) AnnouncementRegistryImpl(org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistryImpl) BaseConfig(org.apache.sling.discovery.base.connectors.BaseConfig) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService) ClusterViewService(org.apache.sling.discovery.base.commons.ClusterViewService) URL(java.net.URL) Test(org.junit.Test)

Aggregations

DummySlingSettingsService (org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)6 SimpleConnectorConfig (org.apache.sling.discovery.base.its.setup.mock.SimpleConnectorConfig)2 Before (org.junit.Before)2 Test (org.junit.Test)2 URL (java.net.URL)1 Session (javax.jcr.Session)1 ModifiableThreadPoolConfig (org.apache.sling.commons.threads.ModifiableThreadPoolConfig)1 DefaultThreadPool (org.apache.sling.commons.threads.impl.DefaultThreadPool)1 ClusterView (org.apache.sling.discovery.ClusterView)1 ClusterViewService (org.apache.sling.discovery.base.commons.ClusterViewService)1 BaseConfig (org.apache.sling.discovery.base.connectors.BaseConfig)1 AnnouncementRegistryImpl (org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistryImpl)1 DummyResourceResolverFactory (org.apache.sling.discovery.base.its.setup.mock.DummyResourceResolverFactory)1 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)1 DummyListener (org.apache.sling.discovery.commons.providers.base.DummyListener)1 DiscoveryLiteDescriptorBuilder (org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteDescriptorBuilder)1 IdMapService (org.apache.sling.discovery.commons.providers.spi.base.IdMapService)1 HeartbeatHandler (org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler)1 TestConfig (org.apache.sling.discovery.impl.setup.TestConfig)1 OakVirtualInstanceBuilder (org.apache.sling.discovery.oak.its.setup.OakVirtualInstanceBuilder)1