• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nats.java / #2101

12 Aug 2025 11:26AM UTC coverage: 95.457% (+0.02%) from 95.433%
#2101

push

github

web-flow
Merge pull request #1387 from nats-io/info-nullability

Ensuring nullability contracts

92 of 92 new or added lines in 10 files covered. (100.0%)

108 existing lines in 12 files now uncovered.

11913 of 12480 relevant lines covered (95.46%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/main/java/io/nats/client/impl/NatsStreamContext.java
1
// Copyright 2020-2023 The NATS Authors
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at:
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13

14
package io.nats.client.impl;
15

16
import io.nats.client.*;
17
import io.nats.client.api.*;
18
import org.jspecify.annotations.NonNull;
19
import org.jspecify.annotations.Nullable;
20

21
import java.io.IOException;
22
import java.util.List;
23

24
/**
25
 * Implementation of Stream Context
26
 */
27
class NatsStreamContext implements StreamContext {
28
    final String streamName;
29
    final NatsJetStream js;
30
    final NatsJetStreamManagement jsm;
31

32
    // for when this is constructed from the NatsJetStream itself
33
    NatsStreamContext(@NonNull String streamName, @Nullable NatsJetStream js, @NonNull NatsConnection connection, @Nullable JetStreamOptions jsOptions) throws IOException, JetStreamApiException {
1✔
34
        this.streamName = streamName;
1✔
35
        this.js = js == null ? new NatsJetStream(connection, jsOptions) : js;
1✔
36
        jsm = new NatsJetStreamManagement(connection, jsOptions);
1✔
37
        jsm.getStreamInfo(streamName); // this is just verifying that the stream exists
1✔
38
    }
1✔
39

40
    /**
41
     * {@inheritDoc}
42
     */
43
    @Override
44
    @NonNull
45
    public String getStreamName() {
46
        return streamName;
1✔
47
    }
48

49
    /**
50
     * {@inheritDoc}
51
     */
52
    @Override
53
    @NonNull
54
    public StreamInfo getStreamInfo() throws IOException, JetStreamApiException {
55
        return jsm.getStreamInfo(streamName, null);
1✔
56
    }
57

58
    /**
59
     * {@inheritDoc}
60
     */
61
    @Override
62
    @NonNull
63
    public StreamInfo getStreamInfo(@Nullable StreamInfoOptions options) throws IOException, JetStreamApiException {
64
        return jsm.getStreamInfo(streamName, options);
1✔
65
    }
66

67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    @NonNull
72
    public PurgeResponse purge() throws IOException, JetStreamApiException {
UNCOV
73
        return jsm.purgeStream(streamName);
×
74
    }
75

76
    /**
77
     * {@inheritDoc}
78
     */
79
    @Override
80
    @NonNull
81
    public PurgeResponse purge(@NonNull PurgeOptions options) throws IOException, JetStreamApiException {
82
        return jsm.purgeStream(streamName, options);
1✔
83
    }
84

85
    /**
86
     * {@inheritDoc}
87
     */
88
    @Override
89
    @NonNull
90
    public ConsumerContext getConsumerContext(@NonNull String consumerName) throws IOException, JetStreamApiException {
91
        return new NatsConsumerContext(this, jsm.getConsumerInfo(streamName, consumerName), null);
1✔
92
    }
93

94
    /**
95
     * {@inheritDoc}
96
     */
97
    @Override
98
    @NonNull
99
    public ConsumerContext createOrUpdateConsumer(@NonNull ConsumerConfiguration config) throws IOException, JetStreamApiException {
100
        return new NatsConsumerContext(this, jsm.addOrUpdateConsumer(streamName, config), null);
1✔
101
    }
102

103
    /**
104
     * {@inheritDoc}
105
     */
106
    @Override
107
    @NonNull
108
    public OrderedConsumerContext createOrderedConsumer(@NonNull OrderedConsumerConfiguration config) throws IOException, JetStreamApiException {
109
        return new NatsOrderedConsumerContext(this, config);
1✔
110
    }
111

112
    /**
113
     * {@inheritDoc}
114
     */
115
    @Override
116
    public boolean deleteConsumer(@NonNull String consumerName) throws IOException, JetStreamApiException {
117
        return jsm.deleteConsumer(streamName, consumerName);
1✔
118
    }
119

120
    /**
121
     * {@inheritDoc}
122
     */
123
    @Override
124
    @NonNull
125
    public ConsumerInfo getConsumerInfo(@NonNull String consumerName) throws IOException, JetStreamApiException {
126
        return jsm.getConsumerInfo(streamName, consumerName);
1✔
127
    }
128

129
    /**
130
     * {@inheritDoc}
131
     */
132
    @Override
133
    @NonNull
134
    public List<String> getConsumerNames() throws IOException, JetStreamApiException {
135
        return jsm.getConsumerNames(streamName);
1✔
136
    }
137

138
    /**
139
     * {@inheritDoc}
140
     */
141
    @Override
142
    @NonNull
143
    public List<ConsumerInfo> getConsumers() throws IOException, JetStreamApiException {
144
        return jsm.getConsumers(streamName);
1✔
145
    }
146

147
    /**
148
     * {@inheritDoc}
149
     */
150
    @Override
151
    @NonNull
152
    public MessageInfo getMessage(long seq) throws IOException, JetStreamApiException {
153
        return jsm.getMessage(streamName, seq);
1✔
154
    }
155

156
    /**
157
     * {@inheritDoc}
158
     */
159
    @Override
160
    @NonNull
161
    public MessageInfo getLastMessage(@NonNull String subject) throws IOException, JetStreamApiException {
162
        return jsm.getLastMessage(streamName, subject);
1✔
163
    }
164

165
    /**
166
     * {@inheritDoc}
167
     */
168
    @Override
169
    @NonNull
170
    public MessageInfo getFirstMessage(@NonNull String subject) throws IOException, JetStreamApiException {
171
        return jsm.getFirstMessage(streamName, subject);
1✔
172
    }
173

174
    /**
175
     * {@inheritDoc}
176
     */
177
    @Override
178
    @NonNull
179
    public MessageInfo getNextMessage(long seq, @NonNull String subject) throws IOException, JetStreamApiException {
180
        return jsm.getNextMessage(streamName, seq, subject);
1✔
181
    }
182

183
    /**
184
     * {@inheritDoc}
185
     */
186
    @Override
187
    public boolean deleteMessage(long seq) throws IOException, JetStreamApiException {
188
        return jsm.deleteMessage(streamName, seq);
1✔
189
    }
190

191
    /**
192
     * {@inheritDoc}
193
     */
194
    @Override
195
    public boolean deleteMessage(long seq, boolean erase) throws IOException, JetStreamApiException {
196
        return jsm.deleteMessage(streamName, seq, erase);
1✔
197
    }
198
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc