use of com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy.DistanceReporter in project java-driver by datastax.
the class LoadBalancingPolicyWrapperTest method should_propagate_distances_from_policies.
@Test
public void should_propagate_distances_from_policies() {
// Given
wrapper.init();
ArgumentCaptor<DistanceReporter> captor1 = ArgumentCaptor.forClass(DistanceReporter.class);
verify(policy1).init(anyMap(), captor1.capture());
DistanceReporter distanceReporter1 = captor1.getValue();
ArgumentCaptor<DistanceReporter> captor2 = ArgumentCaptor.forClass(DistanceReporter.class);
verify(policy2).init(anyMap(), captor2.capture());
DistanceReporter distanceReporter2 = captor1.getValue();
ArgumentCaptor<DistanceReporter> captor3 = ArgumentCaptor.forClass(DistanceReporter.class);
verify(policy3).init(anyMap(), captor3.capture());
DistanceReporter distanceReporter3 = captor3.getValue();
InOrder inOrder = inOrder(eventBus);
// When
distanceReporter1.setDistance(node1, NodeDistance.REMOTE);
// Then
// first event defines the distance
inOrder.verify(eventBus).fire(new DistanceEvent(NodeDistance.REMOTE, node1));
// When
distanceReporter2.setDistance(node1, NodeDistance.REMOTE);
// Then
// event is ignored if the node is already at this distance
inOrder.verify(eventBus, times(0)).fire(any(DistanceEvent.class));
// When
distanceReporter2.setDistance(node1, NodeDistance.LOCAL);
// Then
// event is applied if it sets a smaller distance
inOrder.verify(eventBus).fire(new DistanceEvent(NodeDistance.LOCAL, node1));
// When
distanceReporter3.setDistance(node1, NodeDistance.IGNORED);
// Then
// event is ignored if the node is already at a closer distance
inOrder.verify(eventBus, times(0)).fire(any(DistanceEvent.class));
}
Aggregations