|
| 1 | +/* |
| 2 | + * Copyright 2017 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.integration.support.management; |
| 18 | + |
| 19 | +import org.junit.Assert; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import org.springframework.integration.channel.QueueChannel; |
| 23 | +import org.springframework.integration.support.MessageBuilder; |
| 24 | +import org.springframework.messaging.Message; |
| 25 | + |
| 26 | +/** |
| 27 | + * @author Ivan Krizsan |
| 28 | + */ |
| 29 | +public class DefaultMessageChannelMetricsTests { |
| 30 | + |
| 31 | + protected final static int MESSAGE_COUNT = 10; |
| 32 | + |
| 33 | + protected final static long SEND_TIMEOUT = 1; |
| 34 | + |
| 35 | + @Test |
| 36 | + public void errorCountWithCountsEnabledOnlySuccessTest() { |
| 37 | + final QueueChannel theMessageChannel = new QueueChannel(); |
| 38 | + theMessageChannel.setCountsEnabled(true); |
| 39 | + |
| 40 | + |
| 41 | + for (int i = 0; i < MESSAGE_COUNT; i++) { |
| 42 | + Message<String> theInputMessage = |
| 43 | + MessageBuilder.withPayload(Integer.toString(i)).build(); |
| 44 | + theMessageChannel.send(theInputMessage, SEND_TIMEOUT); |
| 45 | + } |
| 46 | + |
| 47 | + Assert.assertEquals( |
| 48 | + "Message count should match number of sent messages", |
| 49 | + MESSAGE_COUNT, |
| 50 | + theMessageChannel.getSendCount()); |
| 51 | + Assert.assertEquals( |
| 52 | + "Error count should indicate no errors", |
| 53 | + 0, |
| 54 | + theMessageChannel.getSendErrorCount()); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void errorCountWithCountsEnabledHalfErrorsTest() { |
| 59 | + Message<String> theInputMessage; |
| 60 | + final QueueChannel theMessageChannel = new QueueChannel(MESSAGE_COUNT / 2); |
| 61 | + theMessageChannel.setCountsEnabled(true); |
| 62 | + |
| 63 | + for (int i = 0; i < MESSAGE_COUNT; i++) { |
| 64 | + theInputMessage = MessageBuilder.withPayload(Integer.toString(i)).build(); |
| 65 | + theMessageChannel.send(theInputMessage, SEND_TIMEOUT); |
| 66 | + } |
| 67 | + |
| 68 | + Assert.assertEquals( |
| 69 | + "Message count should match number of sent messages", |
| 70 | + MESSAGE_COUNT, |
| 71 | + theMessageChannel.getSendCount()); |
| 72 | + Assert.assertEquals( |
| 73 | + "Error count should indicate errors half the messages", |
| 74 | + MESSAGE_COUNT / 2, |
| 75 | + theMessageChannel.getSendErrorCount()); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments