Search in sources :

Example 1 with Participant

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;
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) Multicaster(org.finos.symphony.toolkit.stream.cluster.Multicaster) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with Participant

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);
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with Participant

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());
}
Also used : MessagesApi(com.symphony.api.agent.MessagesApi) List(java.util.List) V4Event(com.symphony.api.model.V4Event) Optional(java.util.Optional) Participant(org.finos.symphony.toolkit.stream.Participant) Collectors(java.util.stream.Collectors) MessageSearchQuery(com.symphony.api.model.MessageSearchQuery) MessageSearchQuery(com.symphony.api.model.MessageSearchQuery)

Example 4 with Participant

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;
}
Also used : TestClusterMember(org.finos.symphony.toolkit.stream.fixture.TestClusterMember) DummyLeaderServiceImpl(org.finos.symphony.toolkit.stream.fixture.DummyLeaderServiceImpl) Random(java.util.Random) Participant(org.finos.symphony.toolkit.stream.Participant) TestNetwork(org.finos.symphony.toolkit.stream.fixture.TestNetwork) Connectivity(org.finos.symphony.toolkit.stream.fixture.Connectivity)

Example 5 with Participant

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Participant(org.finos.symphony.toolkit.stream.Participant) HashSet(java.util.HashSet)

Aggregations

Participant (org.finos.symphony.toolkit.stream.Participant)13 Random (java.util.Random)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 MessagesApi (com.symphony.api.agent.MessagesApi)2 V4Event (com.symphony.api.model.V4Event)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 LogMessage (org.finos.symphony.toolkit.stream.log.LogMessage)2 SymphonyRoomSharedLog (org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 MessageSearchQuery (com.symphony.api.model.MessageSearchQuery)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 ApiInstance (org.finos.symphony.toolkit.spring.api.factories.ApiInstance)1 StreamEventConsumer (org.finos.symphony.toolkit.stream.StreamEventConsumer)1