use of akka.actor.Address in project controller by opendaylight.
the class GossiperTest method testReceiveGossipWhenNotAddressedToSelfShouldIgnore.
@SuppressWarnings("unchecked")
@Test
public void testReceiveGossipWhenNotAddressedToSelfShouldIgnore() {
doNothing().when(mockGossiper).updateRemoteBuckets(anyMap());
Address notSelf = new Address("tcp", "not-self");
mockGossiper.receiveGossip(new GossipEnvelope(notSelf, notSelf, mock(Map.class)));
verify(mockGossiper, times(0)).updateRemoteBuckets(anyMap());
}
use of akka.actor.Address in project controller by opendaylight.
the class GossiperTest method testReceiveGossipTick_WhenRemoteMemberExistsShouldSendStatus.
@Test
public void testReceiveGossipTick_WhenRemoteMemberExistsShouldSendStatus() {
mockGossiper.setClusterMembers(new Address("tcp", "member"));
doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(ActorSelection.class));
mockGossiper.receiveGossipTick();
verify(mockGossiper, times(1)).getLocalStatusAndSendTo(any(ActorSelection.class));
}
use of akka.actor.Address in project controller by opendaylight.
the class Gossiper method receiveGossipTick.
/**
* Sends Gossip status to other members in the cluster.
* <br>
* 1. If there are no member, ignore the tick. <br>
* 2. If there's only 1 member, send gossip status (bucket versions) to it. <br>
* 3. If there are more than one member, randomly pick one and send gossip status (bucket versions) to it.
*/
@VisibleForTesting
void receiveGossipTick() {
final Address address;
switch(clusterMembers.size()) {
case 0:
// no members to send gossip status to
return;
case 1:
address = clusterMembers.get(0);
break;
default:
final int randomIndex = ThreadLocalRandom.current().nextInt(0, clusterMembers.size());
address = clusterMembers.get(randomIndex);
break;
}
LOG.trace("Gossiping to [{}]", address);
getLocalStatusAndSendTo(Verify.verifyNotNull(peers.get(address)));
}
use of akka.actor.Address in project controller by opendaylight.
the class Gossiper method setClusterMembers.
// /
// /Getter Setters
// /
@VisibleForTesting
void setClusterMembers(final Address... members) {
clusterMembers.clear();
peers.clear();
for (Address addr : members) {
addPeer(addr);
}
}
use of akka.actor.Address in project controller by opendaylight.
the class Gossiper method processRemoteStatus.
private void processRemoteStatus(final ActorRef remote, final GossipStatus status, final Map<Address, Long> localVersions) {
final Map<Address, Long> remoteVersions = status.versions();
// diff between remote list and local
final Set<Address> localIsOlder = new HashSet<>(remoteVersions.keySet());
localIsOlder.removeAll(localVersions.keySet());
// diff between local list and remote
final Set<Address> localIsNewer = new HashSet<>(localVersions.keySet());
localIsNewer.removeAll(remoteVersions.keySet());
for (Entry<Address, Long> entry : remoteVersions.entrySet()) {
Address address = entry.getKey();
Long remoteVersion = entry.getValue();
Long localVersion = localVersions.get(address);
if (localVersion == null || remoteVersion == null) {
// this condition is taken care of by above diffs
continue;
}
if (localVersion < remoteVersion) {
localIsOlder.add(address);
} else if (localVersion > remoteVersion) {
localIsNewer.add(address);
}
}
if (!localIsOlder.isEmpty()) {
remote.tell(new GossipStatus(selfAddress, localVersions), getSelf());
}
if (!localIsNewer.isEmpty()) {
// send newer buckets to remote
bucketStore.getBucketsByMembers(localIsNewer, buckets -> {
LOG.trace("Buckets to send from {}: {}", selfAddress, buckets);
remote.tell(new GossipEnvelope(selfAddress, remote.path().address(), buckets), getSelf());
});
}
}
Aggregations