-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-2602: Fix x-delay
header to Long
#2603
Changes from 6 commits
5a5e988
ed92329
4ff6dc5
677af59
408384a
d841817
13cd9d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2019 the original author or authors. | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -17,6 +17,7 @@ | |
package org.springframework.amqp.support; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import java.util.Date; | ||
|
@@ -37,6 +38,7 @@ | |
* @author Mark Fisher | ||
* @author Gary Russell | ||
* @author Oleg Zhurakousky | ||
* @author Raylax Grey | ||
*/ | ||
public class SimpleAmqpHeaderMapperTests { | ||
|
||
|
@@ -51,7 +53,7 @@ public void fromHeaders() { | |
headerMap.put(AmqpHeaders.CONTENT_TYPE, "test.contentType"); | ||
String testCorrelationId = "foo"; | ||
headerMap.put(AmqpHeaders.CORRELATION_ID, testCorrelationId); | ||
headerMap.put(AmqpHeaders.DELAY, 1234); | ||
headerMap.put(AmqpHeaders.DELAY, 1234L); | ||
headerMap.put(AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.NON_PERSISTENT); | ||
headerMap.put(AmqpHeaders.DELIVERY_TAG, 1234L); | ||
headerMap.put(AmqpHeaders.EXPIRATION, "test.expiration"); | ||
|
@@ -95,6 +97,32 @@ public void fromHeaders() { | |
assertThat(amqpProperties.getDelay()).isEqualTo(Integer.valueOf(1234)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, consider to not use a deprecated API any more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe in supporting deprecated API. |
||
} | ||
|
||
@Test | ||
public void fromHeadersWithLongDelay() { | ||
SimpleAmqpHeaderMapper headerMapper = new SimpleAmqpHeaderMapper(); | ||
Map<String, Object> headerMap = new HashMap<>(); | ||
headerMap.put(AmqpHeaders.DELAY, 1234L); | ||
MessageHeaders messageHeaders = new MessageHeaders(headerMap); | ||
MessageProperties amqpProperties = new MessageProperties(); | ||
headerMapper.fromHeaders(messageHeaders, amqpProperties); | ||
assertThat(amqpProperties.getDelayLong()).isEqualTo(Long.valueOf(1234)); | ||
|
||
amqpProperties.setDelayLong(5678L); | ||
assertThat(amqpProperties.getDelayLong()).isEqualTo(Long.valueOf(5678)); | ||
|
||
amqpProperties.setDelayLong(null); | ||
assertThat(amqpProperties.getHeaders().containsKey(AmqpHeaders.DELAY)).isFalse(); | ||
|
||
amqpProperties.setDelayLong(MessageProperties.X_DELAY_MAX); | ||
assertThat(amqpProperties.getDelayLong()).isEqualTo(Long.valueOf(MessageProperties.X_DELAY_MAX)); | ||
|
||
assertThatThrownBy(() -> amqpProperties.setDelayLong(MessageProperties.X_DELAY_MAX + 1)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("Delay cannot exceed"); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void fromHeadersWithContentTypeAsMediaType() { | ||
SimpleAmqpHeaderMapper headerMapper = new SimpleAmqpHeaderMapper(); | ||
|
@@ -151,7 +179,7 @@ public void toHeaders() { | |
assertThat(headerMap.get(AmqpHeaders.EXPIRATION)).isEqualTo("test.expiration"); | ||
assertThat(headerMap.get(AmqpHeaders.MESSAGE_COUNT)).isEqualTo(42); | ||
assertThat(headerMap.get(AmqpHeaders.MESSAGE_ID)).isEqualTo("test.messageId"); | ||
assertThat(headerMap.get(AmqpHeaders.RECEIVED_DELAY)).isEqualTo(1234); | ||
assertThat(headerMap.get(AmqpHeaders.RECEIVED_DELAY)).isEqualTo(1234L); | ||
assertThat(headerMap.get(AmqpHeaders.RECEIVED_EXCHANGE)).isEqualTo("test.receivedExchange"); | ||
assertThat(headerMap.get(AmqpHeaders.RECEIVED_ROUTING_KEY)).isEqualTo("test.receivedRoutingKey"); | ||
assertThat(headerMap.get(AmqpHeaders.REPLY_TO)).isEqualTo("test.replyTo"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this has to be public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add Javadoc for this new
public
API then.Including
@since