Search in sources :

Example 1 with Status

use of io.nats.client.support.Status in project nats.java by nats-io.

the class PushStatusMessageManager method manage.

boolean manage(Message msg) {
    if (msg.isStatusMessage()) {
        // this checks fc, hb and unknown
        // only process fc and hb if those flags are set
        // otherwise they are simply known statuses
        Status status = msg.getStatus();
        if (status.isFlowControl()) {
            if (fc) {
                _processFlowControl(msg.getReplyTo(), ErrorListener.FlowControlSource.FLOW_CONTROL);
            }
            return true;
        }
        if (status.isHeartbeat()) {
            if (fc) {
                // status flowControlSubject is set in the beforeQueueProcessor
                _processFlowControl(extractFcSubject(msg), ErrorListener.FlowControlSource.HEARTBEAT);
            }
            return true;
        }
        // this status is unknown to us, always use the error handler.
        // If it's a sync call, also throw an exception
        conn.getOptions().getErrorListener().unhandledStatus(conn, sub, status);
        if (syncMode) {
            throw new JetStreamStatusException(sub, status);
        }
        return true;
    }
    // JS Message
    lastStreamSeq = msg.metaData().streamSequence();
    lastConsumerSeq = msg.metaData().consumerSequence();
    return false;
}
Also used : Status(io.nats.client.support.Status) JetStreamStatusException(io.nats.client.JetStreamStatusException)

Example 2 with Status

use of io.nats.client.support.Status in project nats.java by nats-io.

the class ErrorListenerTests method testCoverage.

@Test
public void testCoverage() {
    // this exercises default interface implementation
    _cover(new ErrorListener() {
    });
    // exercises the default implementation
    _cover(new ErrorListenerLoggerImpl());
    // exercises a little more than the defaults
    AtomicBoolean errorOccurredFlag = new AtomicBoolean();
    AtomicBoolean exceptionOccurredFlag = new AtomicBoolean();
    AtomicBoolean slowConsumerDetectedFlag = new AtomicBoolean();
    AtomicBoolean messageDiscardedFlag = new AtomicBoolean();
    AtomicBoolean heartbeatAlarmFlag = new AtomicBoolean();
    AtomicBoolean unhandledStatusFlag = new AtomicBoolean();
    AtomicBoolean flowControlProcessedFlag = new AtomicBoolean();
    _cover(new ErrorListener() {

        @Override
        public void errorOccurred(Connection conn, String error) {
            errorOccurredFlag.set(true);
        }

        @Override
        public void exceptionOccurred(Connection conn, Exception exp) {
            exceptionOccurredFlag.set(true);
        }

        @Override
        public void slowConsumerDetected(Connection conn, Consumer consumer) {
            slowConsumerDetectedFlag.set(true);
        }

        @Override
        public void messageDiscarded(Connection conn, Message msg) {
            messageDiscardedFlag.set(true);
        }

        @Override
        public void heartbeatAlarm(Connection conn, JetStreamSubscription sub, long lastStreamSequence, long lastConsumerSequence) {
            heartbeatAlarmFlag.set(true);
        }

        @Override
        public void unhandledStatus(Connection conn, JetStreamSubscription sub, Status status) {
            unhandledStatusFlag.set(true);
        }

        @Override
        public void flowControlProcessed(Connection conn, JetStreamSubscription sub, String subject, FlowControlSource source) {
            flowControlProcessedFlag.set(true);
        }
    });
    assertTrue(errorOccurredFlag.get());
    assertTrue(exceptionOccurredFlag.get());
    assertTrue(slowConsumerDetectedFlag.get());
    assertTrue(messageDiscardedFlag.get());
    assertTrue(heartbeatAlarmFlag.get());
    assertTrue(unhandledStatusFlag.get());
    assertTrue(flowControlProcessedFlag.get());
}
Also used : Status(io.nats.client.support.Status) TestBase.standardConnection(io.nats.client.utils.TestBase.standardConnection) TestBase.standardCloseConnection(io.nats.client.utils.TestBase.standardCloseConnection) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test)

Example 3 with Status

use of io.nats.client.support.Status in project nats.java by nats-io.

the class HeadersTests method assertValidStatus.

private IncomingHeadersProcessor assertValidStatus(IncomingHeadersProcessor ihp, int code, String msg) {
    Status status = ihp.getStatus();
    assertNotNull(status);
    assertEquals(code, status.getCode());
    if (msg != null) {
        assertEquals(msg, status.getMessage());
    }
    NatsMessage.InternalMessageFactory imf = new NatsMessage.InternalMessageFactory("sid", "sub", "rt", 0, false);
    imf.setHeaders(ihp);
    assertTrue(imf.getMessage().isStatusMessage());
    return ihp;
}
Also used : Status(io.nats.client.support.Status)

Example 4 with Status

use of io.nats.client.support.Status in project nats.java by nats-io.

the class HeadersTests method verifyStatusBooleans.

@Test
public void verifyStatusBooleans() {
    Status status = new Status(Status.FLOW_OR_HEARTBEAT_STATUS_CODE, Status.FLOW_CONTROL_TEXT);
    assertTrue(status.isFlowControl());
    assertFalse(status.isHeartbeat());
    assertFalse(status.isNoResponders());
    status = new Status(Status.FLOW_OR_HEARTBEAT_STATUS_CODE, Status.HEARTBEAT_TEXT);
    assertFalse(status.isFlowControl());
    assertTrue(status.isHeartbeat());
    assertFalse(status.isNoResponders());
    status = new Status(Status.NO_RESPONDERS_CODE, Status.NO_RESPONDERS_TEXT);
    assertFalse(status.isFlowControl());
    assertFalse(status.isHeartbeat());
    assertTrue(status.isNoResponders());
    // path coverage
    status = new Status(Status.NO_RESPONDERS_CODE, "not no responders text");
    assertFalse(status.isNoResponders());
}
Also used : Status(io.nats.client.support.Status) Test(org.junit.jupiter.api.Test)

Aggregations

Status (io.nats.client.support.Status)4 Test (org.junit.jupiter.api.Test)2 JetStreamStatusException (io.nats.client.JetStreamStatusException)1 TestBase.standardCloseConnection (io.nats.client.utils.TestBase.standardCloseConnection)1 TestBase.standardConnection (io.nats.client.utils.TestBase.standardConnection)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1