Search in sources :

Example 6 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SymphonyLeaderEventFilterIT method testMultipleStreamingConsumers.

@Test
public void testMultipleStreamingConsumers() throws InterruptedException {
    List<SimpleEventConsumer> consumers = IntStream.range(0, 4).mapToObj(i -> new Participant("p" + i)).map(p -> new SimpleEventConsumer(p)).collect(Collectors.toList());
    List<SymphonyStreamHandler> wrapped = consumers.stream().map(c -> {
        lmh = new SymphonyRoomSharedLog(clusterName, streamId, messagesApi, "UNIT", 6000);
        SymphonyStreamHandler out = new SymphonyStreamHandler(singleApi, c, ec, false);
        out.setFilter(new SymphonyLeaderEventFilter(c.p, lmh));
        out.start();
        return out;
    }).collect(Collectors.toList());
    // send some messsages through
    for (int j = 0; j < 8; j++) {
        createLeaderEvent(j % 4);
        for (int k = 0; k < 3; k++) {
            createMessageEvent(k);
        }
    }
    boolean done = false;
    while (!done) {
        Thread.sleep(2000);
        done = consumers.stream().map(c -> c.collection.size() == 6).reduce(true, (a, b) -> a && b);
    }
    wrapped.stream().forEach(c -> c.stop());
}
Also used : IntStream(java.util.stream.IntStream) SymphonyRoomSharedLog(org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog) LogMessageType(org.finos.symphony.toolkit.stream.log.LogMessageType) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) LogMessage(org.finos.symphony.toolkit.stream.log.LogMessage) TestApplication(org.finos.symphony.toolkit.stream.fixture.TestApplication) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Participant(org.finos.symphony.toolkit.stream.Participant) ApiInstance(org.finos.symphony.toolkit.spring.api.factories.ApiInstance) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SymphonyStreamHandler(org.finos.symphony.toolkit.stream.handler.SymphonyStreamHandler) Test(org.junit.jupiter.api.Test) MessagesApi(com.symphony.api.agent.MessagesApi) List(java.util.List) V4Event(com.symphony.api.model.V4Event) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ExceptionConsumer(org.finos.symphony.toolkit.stream.handler.ExceptionConsumer) StreamEventConsumer(org.finos.symphony.toolkit.stream.StreamEventConsumer) SymphonyLeaderEventFilter(org.finos.symphony.toolkit.stream.handler.SymphonyLeaderEventFilter) SymphonyStreamHandler(org.finos.symphony.toolkit.stream.handler.SymphonyStreamHandler) SymphonyLeaderEventFilter(org.finos.symphony.toolkit.stream.handler.SymphonyLeaderEventFilter) Participant(org.finos.symphony.toolkit.stream.Participant) SymphonyRoomSharedLog(org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SymphonySharedLogIT method testParticipantWrite.

@Test
public void testParticipantWrite() {
    SymphonyRoomSharedLog ssl = new SymphonyRoomSharedLog(clusterName, streamId, messagesApi, "test", SymphonyRoomSharedLog.ONE_HOUR);
    Participant p1 = new Participant("testing-participant-" + new Random(122).nextLong());
    Participant p2 = new Participant("testing-participant-" + new Random(122).nextLong());
    ssl.writeParticipantMessage(p1);
    ssl.writeParticipantMessage(p2);
    List<Participant> returned = ssl.getRecentParticipants();
    Assertions.assertTrue(returned.contains(p1));
    Assertions.assertTrue(returned.contains(p2));
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) Random(java.util.Random) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SymphonySharedLogIT method testLeaderWrite.

@Test
public void testLeaderWrite() {
    SymphonyRoomSharedLog ssl = new SymphonyRoomSharedLog(clusterName, streamId, messagesApi, "test", SymphonyRoomSharedLog.ONE_HOUR);
    Participant p1 = new Participant("testing-participant-" + new Random(122).nextLong());
    Participant p2 = new Participant("testing-participant-" + new Random(122).nextLong());
    ssl.writeLeaderMessage(p1);
    ssl.writeLeaderMessage(p2);
    for (int i = 0; i < 30; i++) {
        // sometimes takes a few tries to get the thing back
        Optional<Participant> returned = ssl.getLastRecordedLeader(p1);
        if (returned.isPresent()) {
            Assertions.assertEquals(p2, returned.get());
            return;
        }
    }
    Assertions.fail("Didn't find leader");
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) Random(java.util.Random) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SymphonyLeaderEventFilterIT method createLeaderEvent.

private void createLeaderEvent(int i) {
    LogMessage lm = new LogMessage("test", new Participant("p" + i), LogMessageType.LEADER);
    String messageMl = lmh.createMessageML(lm);
    String json = lmh.serializeJson(lm);
    messagesApi.v4StreamSidMessageCreatePost(null, streamId, messageMl, json, null, null, null, null);
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) LogMessage(org.finos.symphony.toolkit.stream.log.LogMessage)

Example 10 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SymphonySharedLogIT method testLocalLog.

@Test
public void testLocalLog() {
    LocalConsoleOnlyLog ssl = new LocalConsoleOnlyLog();
    Participant p1 = new Participant("testing-participant-" + new Random(122).nextLong());
    Participant p2 = new Participant("testing-participant-" + new Random(122).nextLong());
    ssl.writeParticipantMessage(p1);
    ssl.writeLeaderMessage(p2);
    List<Participant> returned = ssl.getRecentParticipants();
    Assertions.assertTrue(returned.isEmpty());
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) Random(java.util.Random) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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