Skip to content

Commit

Permalink
Close #191: Failover tests - client reconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou authored and anthonydahanne committed Dec 22, 2016
1 parent 1eb8ff1 commit 3012835
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,24 +355,32 @@ synchronized void setEntityManagementRegistry(long consumerId, String serverName
}

synchronized void setClientManagementRegistry(long consumerId, ClientDescriptor clientDescriptor, ManagementRegistry newRegistry) {
getClient(consumerId, clientDescriptor).ifPresent(client -> {
Optional<Client> optional = getClient(consumerId, clientDescriptor);
if (optional.isPresent()) {
Client client = optional.get();
String notif = client.getManagementRegistry().map(current -> current.equals(newRegistry) ? "" : "CLIENT_REGISTRY_UPDATED").orElse("CLIENT_REGISTRY_AVAILABLE");
if (!notif.isEmpty()) {
client.setManagementRegistry(newRegistry);
firingService.fireNotification(new ContextualNotification(client.getContext(), notif));
}
});
} else {
LOGGER.warn("[0] setClientManagementRegistry(): Client descriptor " + clientDescriptor + " did not fetch entity " + consumerId);
}
}

synchronized void setClientTags(long consumerId, ClientDescriptor clientDescriptor, String[] tags) {
getClient(consumerId, clientDescriptor).ifPresent(client -> {
Optional<Client> optional = getClient(consumerId, clientDescriptor);
if (optional.isPresent()) {
Client client = optional.get();
Set<String> currtags = new HashSet<>(client.getTags());
Set<String> newTags = new HashSet<>(Arrays.asList(tags));
if (!currtags.equals(newTags)) {
client.setTags(tags);
firingService.fireNotification(new ContextualNotification(client.getContext(), "CLIENT_TAGS_UPDATED"));
}
});
} else {
LOGGER.warn("[0] setClientTags(): Client descriptor " + clientDescriptor + " did not fetch entity " + consumerId);
}
}

synchronized Optional<Context> getEntityContext(String serverName, long consumerId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ public void setUp() throws Exception {
}

@Test
//TODO: uncomment this - see https://github.com/Terracotta-OSS/terracotta-core/issues/412
@Ignore("See https://github.com/Terracotta-OSS/terracotta-core/issues/412")
public void all_registries_reexposed_after_failover() throws Exception {
int clientReconnected = 0;
do {
clientReconnected += tmsAgentService.readMessages()
.stream()
.filter(message -> message.getType().equals("NOTIFICATION"))
.flatMap(message -> message.unwrap(ContextualNotification.class).stream())
.filter(contextualNotification -> contextualNotification.getType().equals("CLIENT_RECONNECTED"))
.count();
} while (clientReconnected < 2);

Cluster cluster = tmsAgentService.readTopology();

// removes all random values
Expand Down
Loading

0 comments on commit 3012835

Please sign in to comment.