Search in sources :

Example 1 with HeartbeatHandler

use of org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler in project sling by apache.

the class DiscoveryServiceImplTest method testLocalClusterSyncTokenIdChange.

@Test
public void testLocalClusterSyncTokenIdChange() throws Exception {
    logger.info("testLocalClusterSyncTokenIdChange: start");
    logger.info("testLocalClusterSyncTokenIdChange: creating instance1...");
    FullJR2VirtualInstanceBuilder builder1 = (FullJR2VirtualInstanceBuilder) new FullJR2VirtualInstanceBuilder().setDebugName("instance1").newRepository("/var/testLocalClusterSyncTokenIdChange/", true).setConnectorPingInterval(999).setConnectorPingTimeout(999).setMinEventDelay(0);
    VirtualInstance instance1 = builder1.build();
    logger.info("testLocalClusterSyncTokenIdChange: creating instance2...");
    FullJR2VirtualInstanceBuilder builder2 = (FullJR2VirtualInstanceBuilder) new FullJR2VirtualInstanceBuilder().setDebugName("instance2").useRepositoryOf(instance1).setConnectorPingInterval(999).setConnectorPingTimeout(999).setMinEventDelay(0);
    VirtualInstance instance2 = builder2.build();
    logger.info("testLocalClusterSyncTokenIdChange: registering listener...");
    DummyListener listener = new DummyListener();
    DiscoveryServiceImpl discoveryService = (DiscoveryServiceImpl) instance1.getDiscoveryService();
    discoveryService.bindTopologyEventListener(listener);
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(0, listener.countEvents());
    logger.info("testLocalClusterSyncTokenIdChange: doing some heartbeating...");
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(1000);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(2000);
    logger.info("testLocalClusterSyncTokenIdChange: expecting to have received the INIT...");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    ResourceResolverFactory factory = instance1.getResourceResolverFactory();
    ResourceResolver resolver = factory.getServiceResourceResolver(null);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(1000);
    logger.info("testLocalClusterSyncTokenIdChange: after another heartbeat nothing more should have been triggered...");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(1, listener.countEvents());
    // simulate a change in the establishedView's viewId - which can be
    // achieved by triggering a revoting - which should result with the
    // same view cos the instances have not changed
    HeartbeatHandler heartbeatHandler = (HeartbeatHandler) instance1.getViewChecker();
    logger.info("testLocalClusterSyncTokenIdChange: forcing a new voting to start...");
    heartbeatHandler.startNewVoting();
    logger.info("testLocalClusterSyncTokenIdChange: doing some heartbeats to finish the voting...");
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(1000);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    Thread.sleep(3000);
    logger.info("testLocalClusterSyncTokenIdChange: now we should have gotten a CHANGING/CHANGED pair additionally...");
    assertEquals(0, discoveryService.getViewStateManager().waitForAsyncEvents(2000));
    assertEquals(3, listener.countEvents());
}
Also used : FullJR2VirtualInstanceBuilder(org.apache.sling.discovery.impl.setup.FullJR2VirtualInstanceBuilder) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) HeartbeatHandler(org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) DummyListener(org.apache.sling.discovery.commons.providers.base.DummyListener) Test(org.junit.Test) AbstractDiscoveryServiceTest(org.apache.sling.discovery.base.its.AbstractDiscoveryServiceTest)

Example 2 with HeartbeatHandler

use of org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler 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)

Aggregations

HeartbeatHandler (org.apache.sling.discovery.impl.common.heartbeat.HeartbeatHandler)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)1 AbstractDiscoveryServiceTest (org.apache.sling.discovery.base.its.AbstractDiscoveryServiceTest)1 VirtualInstance (org.apache.sling.discovery.base.its.setup.VirtualInstance)1 DummyListener (org.apache.sling.discovery.commons.providers.base.DummyListener)1 DummySlingSettingsService (org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)1 FullJR2VirtualInstanceBuilder (org.apache.sling.discovery.impl.setup.FullJR2VirtualInstanceBuilder)1 Test (org.junit.Test)1