Search in sources :

Example 1 with PropertyProviderImpl

use of org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl in project sling by apache.

the class AbstractClusterTest method testPropertyProviders.

@Test
public void testPropertyProviders() throws Throwable {
    logger.info("testPropertyProviders: start");
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    assertNull(instance3);
    instance3 = newBuilder().setDebugName("thirdInstance").useRepositoryOf(instance1).build();
    instance3.heartbeatsAndCheckView();
    logger.info("testPropertyProviders: 1st 2s sleep");
    Thread.sleep(2000);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    instance3.heartbeatsAndCheckView();
    logger.info("testPropertyProviders: 2nd 2s sleep");
    Thread.sleep(2000);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    instance3.heartbeatsAndCheckView();
    logger.info("testPropertyProviders: 3rd 2s sleep");
    Thread.sleep(2000);
    property1Value = UUID.randomUUID().toString();
    property1Name = UUID.randomUUID().toString();
    PropertyProviderImpl pp1 = new PropertyProviderImpl();
    pp1.setProperty(property1Name, property1Value);
    instance1.bindPropertyProvider(pp1, property1Name);
    property2Value = UUID.randomUUID().toString();
    property2Name = UUID.randomUUID().toString();
    PropertyProviderImpl pp2 = new PropertyProviderImpl();
    pp2.setProperty(property2Name, property2Value);
    instance2.bindPropertyProvider(pp2, property2Name);
    assertPropertyValues();
    property1Value = UUID.randomUUID().toString();
    pp1.setProperty(property1Name, property1Value);
    instance1.heartbeatsAndCheckView();
    instance2.heartbeatsAndCheckView();
    assertPropertyValues();
    assertNull(instance1.getClusterViewService().getLocalClusterView().getInstances().get(0).getProperty(UUID.randomUUID().toString()));
    assertNull(instance2.getClusterViewService().getLocalClusterView().getInstances().get(0).getProperty(UUID.randomUUID().toString()));
    logger.info("testPropertyProviders: end");
}
Also used : PropertyProviderImpl(org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl) Test(org.junit.Test)

Example 2 with PropertyProviderImpl

use of org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl in project sling by apache.

the class AbstractSingleInstanceTest method doTestProperty.

private void doTestProperty(final String propertyName, final String propertyValue, final String expectedPropertyValue) throws Throwable {
    PropertyProviderImpl pp = new PropertyProviderImpl();
    pp.setProperty(propertyName, propertyValue);
    instance.bindPropertyProvider(pp, propertyName);
    assertEquals(expectedPropertyValue, instance.getClusterViewService().getLocalClusterView().getInstances().get(0).getProperty(propertyName));
}
Also used : PropertyProviderImpl(org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl)

Example 3 with PropertyProviderImpl

use of org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl in project sling by apache.

the class AbstractSingleInstanceTest method testTopologyEventListeners.

@Test
public void testTopologyEventListeners() throws Throwable {
    logger.info("testTopologyEventListeners: start");
    instance.heartbeatsAndCheckView();
    logger.info("testTopologyEventListeners: 1st sleep 2s");
    Thread.sleep(2000);
    instance.heartbeatsAndCheckView();
    logger.info("testTopologyEventListeners: 2nd sleep 2s");
    Thread.sleep(2000);
    AssertingTopologyEventListener assertingTopologyEventListener = new AssertingTopologyEventListener();
    assertingTopologyEventListener.addExpected(Type.TOPOLOGY_INIT);
    logger.info("testTopologyEventListeners: binding the event listener");
    instance.bindTopologyEventListener(assertingTopologyEventListener);
    // SLING-4755: async event sending requires some minimal wait time nowadays
    Thread.sleep(1000);
    assertEquals(0, assertingTopologyEventListener.getRemainingExpectedCount());
    final String propertyName = UUID.randomUUID().toString();
    propertyValue = UUID.randomUUID().toString();
    PropertyProviderImpl pp = new PropertyProviderImpl();
    pp.setProperty(propertyName, propertyValue);
    assertingTopologyEventListener.addExpected(Type.PROPERTIES_CHANGED);
    assertEquals(1, assertingTopologyEventListener.getRemainingExpectedCount());
    assertEquals(0, pp.getGetCnt());
    instance.bindPropertyProvider(pp, propertyName);
    logger.info("testTopologyEventListeners: 3rd sleep 1.5s");
    Thread.sleep(1500);
    logger.info("testTopologyEventListeners: dumping due to failure: ");
    assertingTopologyEventListener.dump();
    assertEquals(0, assertingTopologyEventListener.getRemainingExpectedCount());
    // we can only assume that the getProperty was called at least once - it
    // could be called multiple times though..
    assertTrue(pp.getGetCnt() > 0);
    assertingTopologyEventListener.addExpected(Type.PROPERTIES_CHANGED);
    assertEquals(1, assertingTopologyEventListener.getRemainingExpectedCount());
    pp.setGetCnt(0);
    propertyValue = UUID.randomUUID().toString();
    pp.setProperty(propertyName, propertyValue);
    assertEquals(0, pp.getGetCnt());
    instance.heartbeatsAndCheckView();
    logger.info("testTopologyEventListeners: 4th sleep 2s");
    Thread.sleep(2000);
    assertEquals(0, assertingTopologyEventListener.getRemainingExpectedCount());
    assertEquals(2, pp.getGetCnt());
    // a heartbeat repeat should not result in another call though
    instance.heartbeatsAndCheckView();
    logger.info("testTopologyEventListeners: 5th sleep 2s");
    Thread.sleep(2000);
    assertEquals(0, assertingTopologyEventListener.getRemainingExpectedCount());
    assertEquals(3, pp.getGetCnt());
    logger.info("testTopologyEventListeners: done");
}
Also used : AssertingTopologyEventListener(org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener) PropertyProviderImpl(org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl) Test(org.junit.Test)

Example 4 with PropertyProviderImpl

use of org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl in project sling by apache.

the class AbstractSingleInstanceTest method testPropertyProviders.

@Test
public void testPropertyProviders() throws Throwable {
    logger.info("testPropertyProviders: start");
    final String propertyName = UUID.randomUUID().toString();
    propertyValue = UUID.randomUUID().toString();
    PropertyProviderImpl pp = new PropertyProviderImpl();
    pp.setProperty(propertyName, propertyValue);
    instance.bindPropertyProvider(pp, propertyName);
    instance.heartbeatsAndCheckView();
    // wait 4000ms for the vote to happen
    Thread.sleep(4000);
    assertEquals(propertyValue, instance.getClusterViewService().getLocalClusterView().getInstances().get(0).getProperty(propertyName));
    propertyValue = UUID.randomUUID().toString();
    pp.setProperty(propertyName, propertyValue);
    instance.heartbeatsAndCheckView();
    assertEquals(propertyValue, instance.getClusterViewService().getLocalClusterView().getInstances().get(0).getProperty(propertyName));
    assertNull(instance.getClusterViewService().getLocalClusterView().getInstances().get(0).getProperty(UUID.randomUUID().toString()));
    logger.info("testPropertyProviders: end");
}
Also used : PropertyProviderImpl(org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl) Test(org.junit.Test)

Aggregations

PropertyProviderImpl (org.apache.sling.discovery.base.its.setup.mock.PropertyProviderImpl)4 Test (org.junit.Test)3 AssertingTopologyEventListener (org.apache.sling.discovery.base.its.setup.mock.AssertingTopologyEventListener)1