use of org.apache.sling.discovery.DiscoveryService in project sling by apache.
the class TestViewStateManager method testChangedPropertiesChanged.
@Test
public void testChangedPropertiesChanged() throws Exception {
final DummyListener listener = new DummyListener();
mgr.installMinEventDelayHandler(new DiscoveryService() {
@Override
public TopologyView getTopology() {
throw new IllegalStateException("not yet impl");
}
}, new DummyScheduler(), 1);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
mgr.bind(listener);
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view1 = new DummyTopologyView().addInstance();
InstanceDescription instance1 = view1.getInstances().iterator().next();
ClusterView cluster1 = instance1.getClusterView();
mgr.handleNewView(view1);
assertEvents(listener, EventHelper.newInitEvent(view1));
DefaultClusterView cluster2 = new DefaultClusterView(new String(cluster1.getId()));
final BaseTopologyView view2 = new DummyTopologyView(view1.getLocalClusterSyncTokenId()).addInstance(instance1.getSlingId(), cluster2, instance1.isLeader(), instance1.isLocal());
DefaultInstanceDescription instance2 = (DefaultInstanceDescription) view2.getLocalInstance();
instance2.setProperty("foo", "bar");
mgr.handleNewView(view2);
assertEvents(listener, EventHelper.newPropertiesChangedEvent(view1, view2));
}
use of org.apache.sling.discovery.DiscoveryService in project sling by apache.
the class NoClusterDiscoveryServiceTest method testListenerAfter.
@Test
public void testListenerAfter() throws Exception {
final DiscoveryService service = this.createService(true);
final List<TopologyEvent> events = new ArrayList<TopologyEvent>();
final TopologyEventListener listener = new TopologyEventListener() {
@Override
public void handleTopologyEvent(final TopologyEvent event) {
events.add(event);
}
};
invoke(service, "bindTopologyEventListener", new Class[] { TopologyEventListener.class }, new Object[] { listener });
assertEquals(1, events.size());
assertEquals(TopologyEvent.Type.TOPOLOGY_INIT, events.get(0).getType());
assertNotNull(events.get(0).getNewView());
assertNull(events.get(0).getOldView());
}
use of org.apache.sling.discovery.DiscoveryService in project sling by apache.
the class NoClusterDiscoveryServiceTest method createService.
private DiscoveryService createService(final boolean activate) {
final DiscoveryService service = new NoClusterDiscoveryService();
setField(service, "settingsService", new SlingSettingsService() {
@Override
public String getSlingId() {
return "my-sling-id";
}
@Override
public String getSlingHomePath() {
return null;
}
@Override
public URL getSlingHome() {
return null;
}
@Override
public Set<String> getRunModes() {
return null;
}
@Override
public String getAbsolutePathWithinSlingHome(String relativePath) {
return null;
}
});
if (activate) {
invoke(service, "activate");
}
return service;
}
use of org.apache.sling.discovery.DiscoveryService in project sling by apache.
the class NoClusterDiscoveryServiceTest method testListenerBefore.
@Test
public void testListenerBefore() throws Exception {
final DiscoveryService service = this.createService(false);
final List<TopologyEvent> events = new ArrayList<TopologyEvent>();
final TopologyEventListener listener = new TopologyEventListener() {
@Override
public void handleTopologyEvent(final TopologyEvent event) {
events.add(event);
}
};
invoke(service, "bindTopologyEventListener", new Class[] { TopologyEventListener.class }, new Object[] { listener });
assertEquals(0, events.size());
invoke(service, "activate");
assertEquals(1, events.size());
assertEquals(TopologyEvent.Type.TOPOLOGY_INIT, events.get(0).getType());
assertNotNull(events.get(0).getNewView());
assertNull(events.get(0).getOldView());
}
use of org.apache.sling.discovery.DiscoveryService in project sling by apache.
the class NoClusterDiscoveryServiceTest method testPropertyChanges.
@Test
public void testPropertyChanges() throws Exception {
final DiscoveryService service = this.createService(true);
final List<TopologyEvent> events = new ArrayList<TopologyEvent>();
final TopologyEventListener listener = new TopologyEventListener() {
@Override
public void handleTopologyEvent(final TopologyEvent event) {
events.add(event);
}
};
invoke(service, "bindTopologyEventListener", new Class[] { TopologyEventListener.class }, new Object[] { listener });
events.clear();
final PropertyProvider provider = new PropertyProvider() {
@Override
public String getProperty(final String name) {
if ("a".equals(name)) {
return "1";
}
if ("b".equals(name)) {
return "2";
}
if ("c".equals(name)) {
return "3";
}
return null;
}
};
final Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyProvider.PROPERTY_PROPERTIES, new String[] { "a", "b", "c" });
properties.put(Constants.SERVICE_ID, 1L);
invoke(service, "bindPropertyProvider", new Class[] { PropertyProvider.class, Map.class }, new Object[] { provider, properties });
assertEquals(1, events.size());
assertEquals(TopologyEvent.Type.PROPERTIES_CHANGED, events.get(0).getType());
assertNotNull(events.get(0).getNewView());
assertTrue(events.get(0).getNewView().isCurrent());
assertNotNull(events.get(0).getOldView());
assertFalse(events.get(0).getOldView().isCurrent());
// test properties
assertEquals("1", events.get(0).getNewView().getLocalInstance().getProperty("a"));
assertEquals("2", events.get(0).getNewView().getLocalInstance().getProperty("b"));
assertEquals("3", events.get(0).getNewView().getLocalInstance().getProperty("c"));
assertNull(events.get(0).getOldView().getLocalInstance().getProperty("a"));
assertNull(events.get(0).getOldView().getLocalInstance().getProperty("b"));
assertNull(events.get(0).getOldView().getLocalInstance().getProperty("c"));
events.clear();
invoke(service, "unbindPropertyProvider", new Class[] { PropertyProvider.class, Map.class }, new Object[] { provider, properties });
assertEquals(1, events.size());
assertEquals(TopologyEvent.Type.PROPERTIES_CHANGED, events.get(0).getType());
assertNotNull(events.get(0).getNewView());
assertTrue(events.get(0).getNewView().isCurrent());
assertNotNull(events.get(0).getOldView());
assertFalse(events.get(0).getOldView().isCurrent());
assertEquals("1", events.get(0).getOldView().getLocalInstance().getProperty("a"));
assertEquals("2", events.get(0).getOldView().getLocalInstance().getProperty("b"));
assertEquals("3", events.get(0).getOldView().getLocalInstance().getProperty("c"));
assertNull(events.get(0).getNewView().getLocalInstance().getProperty("a"));
assertNull(events.get(0).getNewView().getLocalInstance().getProperty("b"));
assertNull(events.get(0).getNewView().getLocalInstance().getProperty("c"));
}
Aggregations