use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class SharedStreamWebConfig method multicaster.
@Bean
@ConditionalOnMissingBean
public Multicaster multicaster() {
Participant me = selfParticipant();
Multicaster out = new HttpMulticaster(me, (int) streamProperties.getTimeoutMs() / 2);
return out;
}
use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class CantTalkToSymphonyTest method testClusterLeadershipChanges.
@ParameterizedTest
@MethodSource("setupConfigurations")
public void testClusterLeadershipChanges(Configuration c) throws InterruptedException {
System.out.println("--------------------------------------");
System.out.println("TEST: " + c.size + " " + c.time + "ms");
System.out.println("--------------------------------------");
Setup s = setupNetwork(c);
s.startup();
waitForLeaderCount(s);
if (c.size > 1) {
// stop leader talking to symphjony
Participant oldLeader = getLeaders(s).stream().findFirst().orElseThrow(() -> new IllegalStateException("Should be a leader"));
System.out.println("--------------------------------------");
s.canTalkToSymphony.remove(oldLeader);
waitForLeaderCount(s);
getLeaders(s).stream().filter(l -> !l.equals(oldLeader)).findFirst().orElseThrow(() -> new IllegalStateException("Should be a new leader"));
// when we heal the network, we should go back to a single leader
System.out.println("--------------------------------------");
s.c.connect(oldLeader);
waitForLeaderCount(s);
getLeaders(s).stream().findFirst().orElseThrow(() -> new IllegalStateException("Should be a leader"));
}
s.shutdown();
int changes = ((DummyLeaderServiceImpl) s.ls).leaderHistory.size();
Assertions.assertTrue(changes < 10, () -> "Expected <10 changes, got " + changes);
}
use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class SymphonyRoomSharedLog method performQuery.
protected List<Participant> performQuery(LogMessageType messageType, int count) {
long since = System.currentTimeMillis() - participationIntervalMillis - ONE_HOUR;
MessageSearchQuery msq = new MessageSearchQuery().hashtag(getHashTagId()).streamId(getStreamId()).fromDate(since).streamType("ROOM");
return messagesApi.v1MessageSearchPost(msq, null, null, 0, count, null, null).stream().map(m -> readMessage(m)).filter(o -> o.isPresent()).map(o -> o.get()).filter(cm -> cm.messageType == messageType).map(cm -> cm.getParticipant()).distinct().collect(Collectors.toList());
}
use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class AbstractClusterTest method setupNetwork.
public Setup setupNetwork(Configuration c) {
Setup setup = new Setup();
setup.c = new Connectivity();
setup.n = new TestNetwork(setup.c, c.time / 10);
Random r = new Random();
setup.allParticipants = IntStream.range(0, c.size).mapToObj(i -> new Participant("P" + i)).collect(Collectors.toSet());
setup.ls = new DummyLeaderServiceImpl(setup.allParticipants);
setup.members = setup.allParticipants.stream().map(p -> createClusterMember(p, c, setup, r)).collect(Collectors.toList());
// setup.members.forEach(m -> setup.allParticipants.forEach(p -> m.accept(p)));
setup.c.set(Collections.singleton(setup.allParticipants));
setup.size = c.size;
setup.maxTimeout = c.time;
setup.canTalkToSymphony = new HashSet<Participant>(setup.allParticipants);
setup.members.forEach(m -> setup.n.register(m.getSelfDetails(), (TestClusterMember) m));
return setup;
}
use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class SplitBrainClusterTest method splitTheBrain.
/**
* Leader should always end up in the smallest (b) group
*/
private void splitTheBrain(Setup s, Participant leader) throws InterruptedException {
Set<Participant> a = new HashSet<Participant>();
Set<Participant> b = new HashSet<Participant>();
b.add(leader);
for (Participant participant : s.allParticipants) {
if (participant == leader) {
// already done
} else if (a.size() > b.size()) {
b.add(participant);
} else {
a.add(participant);
}
}
Set<Set<Participant>> out = new HashSet<Set<Participant>>();
out.add(a);
out.add(b);
s.canTalkToSymphony.removeAll(b);
System.out.println("Splitting: " + out);
s.c.set(out);
Thread.sleep(500);
}
Aggregations