Search in sources :

Example 1 with ObjectHashSet

use of org.agrona.collections.ObjectHashSet in project simple-binary-encoding by real-logic.

the class Message method parseFieldsAndGroups.

private List<Field> parseFieldsAndGroups(final Node node) throws XPathExpressionException {
    final XPath xPath = XPathFactory.newInstance().newXPath();
    final NodeList list = (NodeList) xPath.compile(FIELD_OR_GROUP_OR_DATA_EXPR).evaluate(node, NODESET);
    boolean groupEncountered = false, dataEncountered = false;
    final ObjectHashSet<String> distinctNames = new ObjectHashSet<>();
    final List<Field> fieldList = new ArrayList<>();
    for (int i = 0, size = list.getLength(); i < size; i++) {
        final Field field;
        final String nodeName = list.item(i).getNodeName();
        switch(nodeName) {
            case "group":
                if (dataEncountered) {
                    handleError(node, "group node specified after data node");
                }
                field = parseGroupField(list, i);
                groupEncountered = true;
                break;
            case "data":
                field = parseDataField(list, i);
                dataEncountered = true;
                break;
            case "field":
                if (groupEncountered || dataEncountered) {
                    handleError(node, "field node specified after group or data node specified");
                }
                field = parseField(list, i);
                break;
            default:
                throw new IllegalStateException("Unknown node name: " + nodeName);
        }
        if (!distinctNames.add(field.name())) {
            handleError(node, "duplicate name found: " + field.name());
        }
        fieldList.add(field);
    }
    return fieldList;
}
Also used : XPath(javax.xml.xpath.XPath) ObjectHashSet(org.agrona.collections.ObjectHashSet) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList)

Example 2 with ObjectHashSet

use of org.agrona.collections.ObjectHashSet in project aeron by real-logic.

the class ReplicateRecordingTest method shouldReplicateStoppedRecording.

@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecording() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long srcRecordingId;
    final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
    try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
        final CountersReader counters = srcAeron.countersReader();
        final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
        srcRecordingId = RecordingPos.getRecordingId(counters, counterId);
        offer(publication, messageCount, messagePrefix);
        awaitPosition(counters, counterId, publication.position());
    }
    srcAeronArchive.stopRecording(subscriptionId);
    final MutableLong dstRecordingId = new MutableLong();
    final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
    final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
    dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
    assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
    assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
    final ObjectHashSet<RecordingSignal> transitionEventsSet = new ObjectHashSet<>();
    transitionEventsSet.add(awaitSignal(signalRef, adapter));
    transitionEventsSet.add(awaitSignal(signalRef, adapter));
    assertTrue(transitionEventsSet.contains(RecordingSignal.STOP));
    assertTrue(transitionEventsSet.contains(RecordingSignal.SYNC));
}
Also used : MutableLong(org.agrona.collections.MutableLong) ObjectHashSet(org.agrona.collections.ObjectHashSet) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MutableReference(org.agrona.collections.MutableReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 3 with ObjectHashSet

use of org.agrona.collections.ObjectHashSet in project Aeron by real-logic.

the class ReplicateRecordingTest method shouldReplicateStoppedRecording.

@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecording() {
    final String messagePrefix = "Message-Prefix-";
    final int messageCount = 10;
    final long srcRecordingId;
    final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
    try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
        final CountersReader counters = srcAeron.countersReader();
        final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
        srcRecordingId = RecordingPos.getRecordingId(counters, counterId);
        offer(publication, messageCount, messagePrefix);
        awaitPosition(counters, counterId, publication.position());
    }
    srcAeronArchive.stopRecording(subscriptionId);
    final MutableLong dstRecordingId = new MutableLong();
    final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
    final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
    dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
    assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
    assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
    final ObjectHashSet<RecordingSignal> transitionEventsSet = new ObjectHashSet<>();
    transitionEventsSet.add(awaitSignal(signalRef, adapter));
    transitionEventsSet.add(awaitSignal(signalRef, adapter));
    assertTrue(transitionEventsSet.contains(RecordingSignal.STOP));
    assertTrue(transitionEventsSet.contains(RecordingSignal.SYNC));
}
Also used : MutableLong(org.agrona.collections.MutableLong) ObjectHashSet(org.agrona.collections.ObjectHashSet) RecordingSignal(io.aeron.archive.codecs.RecordingSignal) MutableReference(org.agrona.collections.MutableReference) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountersReader(org.agrona.concurrent.status.CountersReader) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

ObjectHashSet (org.agrona.collections.ObjectHashSet)3 RecordingSignal (io.aeron.archive.codecs.RecordingSignal)2 InterruptAfter (io.aeron.test.InterruptAfter)2 MutableLong (org.agrona.collections.MutableLong)2 MutableReference (org.agrona.collections.MutableReference)2 CountersReader (org.agrona.concurrent.status.CountersReader)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ArrayList (java.util.ArrayList)1 XPath (javax.xml.xpath.XPath)1 NodeList (org.w3c.dom.NodeList)1