@@ -147,6 +147,66 @@ public void basicGetAndAck() {
147147 metrics .cleanStaleState ();
148148 assertThat (failedToPublishMessages (metrics ), is (2L ));
149149 assertThat (publishedMessages (metrics ), is (2L ));
150+
151+ long anyDeliveryTag = 123L ;
152+ metrics .basicNack (channel , anyDeliveryTag );
153+ }
154+
155+
156+ @ Test public void publishingAcknowledgements () {
157+ long anyDeliveryTag = 123L ;
158+ AbstractMetricsCollector metrics = factory .create ();
159+ Channel channel = mock (Channel .class );
160+ // begins with no messages acknowledged
161+ assertThat (publishAck (metrics ), is (0 ));
162+ // first acknowledgement gets tracked
163+ metrics .basicPublishAck (channel , anyDeliveryTag , false );
164+ assertThat (publishAck (metrics ), is (1 ));
165+ // second acknowledgement gets tracked
166+ metrics .basicPublishAck (channel , anyDeliveryTag , false );
167+ assertThat (publishAck (metrics ), is (2 ));
168+ // multiple deliveries aren't tracked
169+ metrics .basicPublishAck (channel , anyDeliveryTag , true );
170+ assertThat (publishAck (metrics ), is (2 ));
171+ // cleaning stale state doesn't affect the metric
172+ metrics .cleanStaleState ();
173+ assertThat (publishAck (metrics ), is (2 ));
174+ }
175+
176+ @ Test public void publishingNotAcknowledgements () {
177+ long anyDeliveryTag = 123L ;
178+ AbstractMetricsCollector metrics = factory .create ();
179+ Channel channel = mock (Channel .class );
180+ // begins with no messages not-acknowledged
181+ assertThat (publishNack (metrics ), is (0 ));
182+ // first not-acknowledgement gets tracked
183+ metrics .basicPublishNack (channel , anyDeliveryTag , false );
184+ assertThat (publishNack (metrics ), is (1 ));
185+ // second not-acknowledgement gets tracked
186+ metrics .basicPublishNack (channel , anyDeliveryTag , false );
187+ assertThat (publishNack (metrics ), is (2 ));
188+ // multiple deliveries aren't tracked
189+ metrics .basicPublishNack (channel , anyDeliveryTag , true );
190+ assertThat (publishNack (metrics ), is (2 ));
191+ // cleaning stale state doesn't affect the metric
192+ metrics .cleanStaleState ();
193+ assertThat (publishNack (metrics ), is (2 ));
194+ }
195+
196+ @ Test public void publishingUnrouted () {
197+ AbstractMetricsCollector metrics = factory .create ();
198+ Channel channel = mock (Channel .class );
199+ // begins with no messages not-acknowledged
200+ assertThat (publishUnrouted (metrics ), is (0 ));
201+ // first unrouted gets tracked
202+ metrics .basicPublishUnrouted (channel );
203+ assertThat (publishUnrouted (metrics ), is (1 ));
204+ // second unrouted gets tracked
205+ metrics .basicPublishUnrouted (channel );
206+ assertThat (publishUnrouted (metrics ), is (2 ));
207+ // cleaning stale state doesn't affect the metric
208+ metrics .cleanStaleState ();
209+ assertThat (publishUnrouted (metrics ), is (2 ));
150210 }
151211
152212 @ Test public void cleanStaleState () {
@@ -189,6 +249,31 @@ public void basicGetAndAck() {
189249 assertThat (channels (metrics ), is (1L ));
190250 }
191251
252+
253+ long publishAck (MetricsCollector metrics ) {
254+ if (metrics instanceof StandardMetricsCollector ) {
255+ return ((StandardMetricsCollector ) metrics ).getPublishAcknowledgedMessages ().getCount ();
256+ } else {
257+ return (long ) ((MicrometerMetricsCollector ) metrics ).getAckedPublishedMessages ().count ();
258+ }
259+ }
260+
261+ long publishNack (MetricsCollector metrics ) {
262+ if (metrics instanceof StandardMetricsCollector ) {
263+ return ((StandardMetricsCollector ) metrics ).getPublishNotAcknowledgedMessages ().getCount ();
264+ } else {
265+ return (long ) ((MicrometerMetricsCollector ) metrics ).getNackedPublishedMessages ().count ();
266+ }
267+ }
268+
269+ long publishUnrouted (MetricsCollector metrics ) {
270+ if (metrics instanceof StandardMetricsCollector ) {
271+ return ((StandardMetricsCollector ) metrics ).getPublishUnroutedMessages ().getCount ();
272+ } else {
273+ return (long ) ((MicrometerMetricsCollector ) metrics ).getUnroutedPublishedMessages ().count ();
274+ }
275+ }
276+
192277 long publishedMessages (MetricsCollector metrics ) {
193278 if (metrics instanceof StandardMetricsCollector ) {
194279 return ((StandardMetricsCollector ) metrics ).getPublishedMessages ().getCount ();
0 commit comments