Skip to content

Commit

Permalink
SpringCloudCommandRouter more lenient with no local handlers
Browse files Browse the repository at this point in the history
Instead of throwing an exception when no locally registered node is
found, it should just ignore this and copy members from the Service
Registry. If a "pre-registration" local member is found, it should
be removed, as it will be replaced by a copy from the Service Registry

Resolves issue #1
  • Loading branch information
abuijze committed Nov 28, 2018
1 parent 30da230 commit eefbbac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Expand Up @@ -31,13 +31,7 @@
import org.springframework.context.event.EventListener;

import java.net.URI;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -167,20 +161,20 @@ public void updateMembership(int loadFactor, CommandMessageFilter commandFilter)
@SuppressWarnings("UnusedParameters")
public void resetLocalMembership(InstanceRegisteredEvent event) {
registered = true;
Member startUpPhaseLocalMember =

Optional<Member> startUpPhaseLocalMember =
atomicConsistentHash.get().getMembers().stream()
.filter(Member::local)
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"There should be no scenario where the local member does not exist."
));

if (logger.isDebugEnabled()) {
logger.debug("Resetting local membership for [{}].", startUpPhaseLocalMember);
}
.findFirst();

updateMemberships();
atomicConsistentHash.updateAndGet(consistentHash -> consistentHash.without(startUpPhaseLocalMember));

startUpPhaseLocalMember.ifPresent(m -> {
if (logger.isDebugEnabled()) {
logger.debug("Resetting local membership for [{}].", m);
}
atomicConsistentHash.updateAndGet(consistentHash -> consistentHash.without(m));
});
}

/**
Expand Down
Expand Up @@ -122,6 +122,12 @@ public void testFindDestinationReturnsEmptyOptionalMemberForCommandMessage() {
verify(routingStrategy).getRoutingKey(TEST_COMMAND);
}

// reproduces issue #1 (https://github.com/AxonFramework/extension-springcloud/issues/1)
@Test
public void testPreRegistrationLocalMemberIgnoredWhenNotPresent() {
testSubject.resetLocalMembership(null);

This comment has been minimized.

Copy link
@smcvb

smcvb Nov 28, 2018

Member

Shouldn't you be able to verify none of the services are called in this scenario?

}

@Test
public void testFindDestinationReturnsMemberForCommandMessage() {
SimpleMember<URI> testMember = new SimpleMember<>(
Expand Down

0 comments on commit eefbbac

Please sign in to comment.