use of com.linkedin.d2.balancer.LoadBalancerState.LoadBalancerStateListenerCallback in project rest.li by linkedin.
the class SimpleLoadBalancerStateTest method testListenToService.
@Test(groups = { "small", "back-end" })
public void testListenToService() throws InterruptedException {
reset();
assertFalse(_state.isListeningToService("service-1"));
assertNull(_state.getServiceProperties("service-1"));
final CountDownLatch latch = new CountDownLatch(1);
LoadBalancerStateListenerCallback callback = new LoadBalancerStateListenerCallback() {
@Override
public void done(int type, String name) {
latch.countDown();
}
};
_state.listenToService("service-1", callback);
if (!latch.await(5, TimeUnit.SECONDS)) {
fail("didn't get callback when listenToService was called");
}
assertTrue(_state.isListeningToService("service-1"));
assertNotNull(_state.getServiceProperties("service-1"));
assertNull(_state.getServiceProperties("service-1").getProperty());
ServiceProperties property = new ServiceProperties("service-1", "cluster-1", "/test", Arrays.asList("random"));
_serviceRegistry.put("service-1", property);
assertTrue(_state.isListeningToService("service-1"));
assertNotNull(_state.getServiceProperties("service-1"));
assertEquals(_state.getServiceProperties("service-1").getProperty(), property);
}
use of com.linkedin.d2.balancer.LoadBalancerState.LoadBalancerStateListenerCallback in project rest.li by linkedin.
the class SimpleLoadBalancerStateTest method testListenToCluster.
@Test(groups = { "small", "back-end" })
public void testListenToCluster() throws URISyntaxException, InterruptedException {
reset();
List<String> schemes = new ArrayList<>();
schemes.add("http");
assertFalse(_state.isListeningToCluster("cluster-1"));
assertNull(_state.getClusterProperties("cluster-1"));
final CountDownLatch latch = new CountDownLatch(1);
LoadBalancerStateListenerCallback callback = new LoadBalancerStateListenerCallback() {
@Override
public void done(int type, String name) {
latch.countDown();
}
};
_state.listenToCluster("cluster-1", callback);
if (!latch.await(5, TimeUnit.SECONDS)) {
fail("didn't get callback when listenToCluster was called");
}
assertTrue(_state.isListeningToCluster("cluster-1"));
assertNotNull(_state.getClusterProperties("cluster-1"));
assertNull(_state.getClusterProperties("cluster-1").getProperty());
ClusterProperties property = new ClusterProperties("cluster-1", schemes);
_clusterRegistry.put("cluster-1", property);
assertTrue(_state.isListeningToCluster("cluster-1"));
assertNotNull(_state.getClusterProperties("cluster-1"));
assertEquals(_state.getClusterProperties("cluster-1").getProperty(), property);
}
use of com.linkedin.d2.balancer.LoadBalancerState.LoadBalancerStateListenerCallback in project rest.li by linkedin.
the class SimpleLoadBalancer method listenToCluster.
public void listenToCluster(String clusterName, boolean waitForUpdatedValue, LoadBalancerStateListenerCallback callback) {
if (waitForUpdatedValue) {
_state.listenToCluster(clusterName, callback);
} else {
_state.listenToCluster(clusterName, new NullStateListenerCallback());
callback.done(0, null);
}
}
Aggregations